cart and checkout
This commit is contained in:
@@ -442,6 +442,45 @@ func TestDateRangeCondition(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCouponCodeCondition(t *testing.T) {
|
||||
rule := PromotionRule{
|
||||
ID: "coupon-promo",
|
||||
Name: "Coupon Promo",
|
||||
Status: StatusActive,
|
||||
Conditions: Conditions{
|
||||
BaseCondition{
|
||||
ID: "c",
|
||||
Type: CondCouponCode,
|
||||
Operator: OpEquals,
|
||||
Value: cvString("SAVE50"),
|
||||
},
|
||||
},
|
||||
Actions: []Action{{ID: "a", Type: ActionFixedDiscount, Value: 500}},
|
||||
}
|
||||
|
||||
svc := NewPromotionService(nil)
|
||||
|
||||
// Context with matching coupon code
|
||||
ctxMatched := &PromotionEvalContext{
|
||||
CouponCodes: []string{"SAVE50"},
|
||||
Now: time.Now(),
|
||||
}
|
||||
resMatched := svc.EvaluateRule(rule, ctxMatched)
|
||||
if !resMatched.Applicable {
|
||||
t.Errorf("expected coupon code rule to apply with SAVE50")
|
||||
}
|
||||
|
||||
// Context without matching coupon code
|
||||
ctxUnmatched := &PromotionEvalContext{
|
||||
CouponCodes: []string{"SAVE20"},
|
||||
Now: time.Now(),
|
||||
}
|
||||
resUnmatched := svc.EvaluateRule(rule, ctxUnmatched)
|
||||
if resUnmatched.Applicable {
|
||||
t.Errorf("expected coupon code rule NOT to apply with SAVE20")
|
||||
}
|
||||
}
|
||||
|
||||
// --- Utilities -------------------------------------------------------------
|
||||
|
||||
func ptr(s string) *string { return &s }
|
||||
|
||||
Reference in New Issue
Block a user