package order import ( "testing" "bindbox-game/internal/repository/mysql/model" ) func TestApplyCouponDiscount(t *testing.T) { c1 := &model.SystemCoupons{DiscountType: 1, DiscountValue: 500} if d := ApplyCouponDiscount(1000, c1, true); d != 500 { t.Fatalf("expected 500 got %d", d) } c2 := &model.SystemCoupons{DiscountType: 2, DiscountValue: 1200} if d := ApplyCouponDiscount(1000, c2, true); d != 1000 { t.Fatalf("expected clamp to 1000 got %d", d) } c3 := &model.SystemCoupons{DiscountType: 3, DiscountValue: 800} // 80% if d := ApplyCouponDiscount(1000, c3, true); d != 200 { t.Fatalf("expected 200 got %d", d) } c4 := &model.SystemCoupons{DiscountType: 3, DiscountValue: 1200} // 超界值按100%折扣(不打折) if d := ApplyCouponDiscount(1000, c4, true); d != 0 { t.Fatalf("expected 0 got %d", d) } if d := ApplyCouponDiscount(1000, c1, false); d != 0 { t.Fatalf("expected 0 when minSpend not ok got %d", d) } }