47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package billing
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"testing"
|
||
|
|
"time"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestSalesQuoteCancelAt(t *testing.T) {
|
||
|
|
now := time.Date(2026, 8, 8, 12, 0, 0, 0, time.UTC)
|
||
|
|
got, err := salesQuoteCancelAt(now, 4, "month")
|
||
|
|
if err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
want := time.Date(2026, 12, 8, 12, 0, 0, 0, time.UTC)
|
||
|
|
if !got.Equal(want) {
|
||
|
|
t.Fatalf("month cancel_at = %v, want %v", got, want)
|
||
|
|
}
|
||
|
|
got, err = salesQuoteCancelAt(now, 2, "quarter")
|
||
|
|
if err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
want = time.Date(2027, 2, 8, 12, 0, 0, 0, time.UTC)
|
||
|
|
if !got.Equal(want) {
|
||
|
|
t.Fatalf("quarter cancel_at = %v, want %v", got, want)
|
||
|
|
}
|
||
|
|
got, err = salesQuoteCancelAt(now, 1, "year")
|
||
|
|
if err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
want = time.Date(2027, 8, 8, 12, 0, 0, 0, time.UTC)
|
||
|
|
if !got.Equal(want) {
|
||
|
|
t.Fatalf("year cancel_at = %v, want %v", got, want)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestStripeRecurringFromInstallment(t *testing.T) {
|
||
|
|
iv, n, err := stripeRecurringFromInstallment("quarter")
|
||
|
|
if err != nil || iv != "month" || n != 3 {
|
||
|
|
t.Fatalf("quarter => %s/%d err=%v", iv, n, err)
|
||
|
|
}
|
||
|
|
iv, n, err = stripeRecurringFromInstallment("month")
|
||
|
|
if err != nil || iv != "month" || n != 1 {
|
||
|
|
t.Fatalf("month => %s/%d err=%v", iv, n, err)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|