refactor(utils): 修复密码哈希比较逻辑错误 feat(user): 新增按状态筛选优惠券接口 docs: 添加虚拟发货与任务中心相关文档 fix(wechat): 修正Code2Session上下文传递问题 test: 补充订单折扣与积分转换测试用例 build: 更新配置文件与构建脚本 style: 清理多余的空行与注释
23 lines
975 B
Go
23 lines
975 B
Go
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) }
|
|
}
|