| index d79416146..648f789c5 100644 |
| --- a/internal/billingstripe/annual_test.go |
| +++ b/internal/billingstripe/annual_test.go |
| @@ -17,8 +17,8 @@ func TestAnnualOf(t *testing.T) { |
| periodEnd := time.Date(2027, 10, 25, 0, 0, 0, 0, time.UTC) |
| i64 := func(v int64) *int64 { return &v } |
| f64 := func(v float64) *float64 { return &v } |
| - personal := SubscriptionItem{ID: "si_1", PriceID: "price_p", Quantity: 1, PriceCurrency: "usd", UnitAmount: i64(2800)} |
| - pack := SubscriptionItem{ID: "si_2", PriceID: "price_a", Quantity: 2, PriceCurrency: "usd", UnitAmount: i64(1200)} |
| + personal := SubscriptionItem{ID: "si_1", PriceID: "price_p", Quantity: 1, PriceCurrency: "usd", UnitAmount: i64(2800), Interval: "year"} |
| + pack := SubscriptionItem{ID: "si_2", PriceID: "price_a", Quantity: 2, PriceCurrency: "usd", UnitAmount: i64(1200), Interval: "year"} |
| sub := func(items []SubscriptionItem, discounts ...Discount) *Subscription { |
| return &Subscription{ID: "sub_1", Currency: "usd", CurrentPeriodEnd: periodEnd, Items: items, Discounts: discounts} |
| } |
| @@ -49,8 +49,10 @@ func TestAnnualOf(t *testing.T) { |
| {"amount off in another currency", sub([]SubscriptionItem{personal}, off(500, "eur")), 0, false}, |
| {"product-limited coupon", sub([]SubscriptionItem{personal}, |
| Discount{Coupon: Coupon{ID: "c", PercentOff: f64(50), Duration: "forever", AppliesToProducts: []string{"prod_x"}}}), 0, false}, |
| - {"no unit amount", sub([]SubscriptionItem{{ID: "si_1", PriceID: "price_p", Quantity: 1}}), 0, false}, |
| - {"item discount", sub([]SubscriptionItem{{ID: "si_1", PriceID: "price_p", Quantity: 1, UnitAmount: i64(2800), HasDiscounts: true}}), 0, false}, |
| + {"no unit amount", sub([]SubscriptionItem{{ID: "si_1", PriceID: "price_p", Quantity: 1, Interval: "year"}}), 0, false}, |
| + {"item discount", sub([]SubscriptionItem{{ID: "si_1", PriceID: "price_p", Quantity: 1, UnitAmount: i64(2800), HasDiscounts: true, Interval: "year"}}), 0, false}, |
| + {"monthly price", sub([]SubscriptionItem{personal, {ID: "si_3", PriceID: "price_m", Quantity: 1, PriceCurrency: "usd", UnitAmount: i64(300), Interval: "month"}}), 0, false}, |
| + {"price with no interval", sub([]SubscriptionItem{{ID: "si_1", PriceID: "price_p", Quantity: 1, PriceCurrency: "usd", UnitAmount: i64(2800)}}), 0, false}, |
| } |
| for _, tc := range cases { |
| got, known := annualOf(tc.sub) |
| @@ -74,7 +76,7 @@ func TestSubscriptionDecodesDiscounts(t *testing.T) { |
| "current_period_end":1824422400, |
| "discounts":[{"id":"di_1","coupon":{"id":"half","valid":true,"livemode":false,"percent_off":50,"duration":"repeating"},"end":1830000000}, |
| {"id":"di_2","coupon":{"id":"five","valid":true,"livemode":false,"amount_off":500,"currency":"usd","duration":"forever"},"end":null}], |
| - "items":{"has_more":false,"data":[{"id":"si_1","quantity":1,"price":{"id":"price_p","currency":"usd","unit_amount":2800}}, |
| + "items":{"has_more":false,"data":[{"id":"si_1","quantity":1,"price":{"id":"price_p","currency":"usd","unit_amount":2800,"recurring":{"interval":"year"}}}, |
| {"id":"si_2","quantity":2,"discounts":["di_3"],"price":{"id":"price_a","currency":"usd","unit_amount":null}}]}}`) |
| })) |
| defer srv.Close() |
| @@ -100,10 +102,10 @@ func TestSubscriptionDecodesDiscounts(t *testing.T) { |
| if len(s.Items) != 2 { |
| t.Fatalf("items = %+v", s.Items) |
| } |
| - if it := s.Items[0]; it.UnitAmount == nil || *it.UnitAmount != 2800 || it.HasDiscounts { |
| + if it := s.Items[0]; it.UnitAmount == nil || *it.UnitAmount != 2800 || it.HasDiscounts || it.Interval != "year" { |
| t.Errorf("item 0 = %+v", it) |
| } |
| - if it := s.Items[1]; it.UnitAmount != nil || !it.HasDiscounts { |
| + if it := s.Items[1]; it.UnitAmount != nil || !it.HasDiscounts || it.Interval != "" { |
| t.Errorf("item 1 = %+v", it) |
| } |
| } |
| @@ -112,7 +114,7 @@ func TestSubscriptionAnnualReadsCoupons(t *testing.T) { |
| const subBody = `{"id":"sub_1","customer":"cus_1","status":"active","livemode":false,"currency":"usd", |
| "current_period_end":1824422400,"metadata":{"account_sqid":"bab"}, |
| "discounts":[{"id":"di_1","coupon":{"id":"half","valid":true,"livemode":false,"percent_off":50,"duration":"forever"},"end":null}], |
| - "items":{"has_more":false,"data":[{"id":"si_1","quantity":1,"price":{"id":"price_p","currency":"usd","unit_amount":2800}}]}}` |
| + "items":{"has_more":false,"data":[{"id":"si_1","quantity":1,"price":{"id":"price_p","currency":"usd","unit_amount":2800,"recurring":{"interval":"year"}}}]}}` |
| run := func(name string, coupon func(w http.ResponseWriter)) (*Provider, func()) { |
| srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| switch { |