Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
@@ -297,3 +297,78 @@ func TestCalculatePurchasePriceNewUserGatedByFirstPurchase(t *testing.T) {
|
||||
t.Fatalf("PayableBase = %d, want 900 (regular 90%% discount)", result.PayableBase)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCalculateRenewalPriceCampaignAppliesToReturningUsers(t *testing.T) {
|
||||
model := &fakePromoModel{rules: []*promo.RuleWithPrice{
|
||||
{
|
||||
Rule: promo.Rule{
|
||||
Id: 21,
|
||||
Name: "renewal campaign",
|
||||
Type: promo.RuleTypeCampaign,
|
||||
Enabled: true,
|
||||
},
|
||||
PromoPrice: 700,
|
||||
},
|
||||
}}
|
||||
svcCtx := &svc.ServiceContext{DB: &gorm.DB{}, PromoModel: model}
|
||||
|
||||
result, err := calculateRenewalPrice(
|
||||
context.Background(),
|
||||
svcCtx,
|
||||
42,
|
||||
2,
|
||||
500,
|
||||
3,
|
||||
[]types.SubscribeDiscount{{Quantity: 3, Discount: 80}},
|
||||
true,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("calculateRenewalPrice returned error: %v", err)
|
||||
}
|
||||
if result.OriginalPrice != 1500 {
|
||||
t.Fatalf("OriginalPrice = %d, want 1500", result.OriginalPrice)
|
||||
}
|
||||
if result.PayableBase != 700 {
|
||||
t.Fatalf("PayableBase = %d, want 700", result.PayableBase)
|
||||
}
|
||||
if result.DiscountAmount != 0 {
|
||||
t.Fatalf("DiscountAmount = %d, want 0 when promo applies", result.DiscountAmount)
|
||||
}
|
||||
if result.PromoRuleId != 21 {
|
||||
t.Fatalf("PromoRuleId = %d, want 21", result.PromoRuleId)
|
||||
}
|
||||
if result.PromoDiscount != 800 {
|
||||
t.Fatalf("PromoDiscount = %d, want 800", result.PromoDiscount)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCalculateRenewalPriceFallsBackToRegularDiscountWhenPromoMisses(t *testing.T) {
|
||||
model := &fakePromoModel{rules: nil}
|
||||
svcCtx := &svc.ServiceContext{DB: &gorm.DB{}, PromoModel: model}
|
||||
|
||||
result, err := calculateRenewalPrice(
|
||||
context.Background(),
|
||||
svcCtx,
|
||||
42,
|
||||
2,
|
||||
500,
|
||||
3,
|
||||
[]types.SubscribeDiscount{{Quantity: 3, Discount: 80}},
|
||||
true,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("calculateRenewalPrice returned error: %v", err)
|
||||
}
|
||||
if result.OriginalPrice != 1500 {
|
||||
t.Fatalf("OriginalPrice = %d, want 1500", result.OriginalPrice)
|
||||
}
|
||||
if result.PayableBase != 1200 {
|
||||
t.Fatalf("PayableBase = %d, want 1200", result.PayableBase)
|
||||
}
|
||||
if result.DiscountAmount != 300 {
|
||||
t.Fatalf("DiscountAmount = %d, want 300", result.DiscountAmount)
|
||||
}
|
||||
if result.PromoRuleId != 0 || result.PromoDiscount != 0 {
|
||||
t.Fatalf("promo fields = (%d, %d), want (0, 0)", result.PromoRuleId, result.PromoDiscount)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user