fix: scope coupons by tenant

This commit is contained in:
2026-01-09 16:23:42 +08:00
parent 4d90f547e6
commit ad9dc4615f
6 changed files with 81 additions and 18 deletions

View File

@@ -56,6 +56,7 @@ func (s *CouponTestSuite) Test_CouponFlow() {
// 1. Create Coupon (Fixed 5.00 CNY, Min 10.00 CNY)
cp := &models.Coupon{
TenantID: tenantID,
Title: "Save 5",
Type: "fix_amount",
Value: 500,
@@ -72,13 +73,13 @@ func (s *CouponTestSuite) Test_CouponFlow() {
models.UserCouponQuery.WithContext(ctx).Create(uc)
Convey("should validate coupon successfully", func() {
discount, err := Coupon.Validate(ctx, user.ID, uc.ID, 1500)
discount, err := Coupon.Validate(ctx, tenantID, user.ID, uc.ID, 1500)
So(err, ShouldBeNil)
So(discount, ShouldEqual, 500)
})
Convey("should fail if below min amount", func() {
_, err := Coupon.Validate(ctx, user.ID, uc.ID, 800)
_, err := Coupon.Validate(ctx, tenantID, user.ID, uc.ID, 800)
So(err, ShouldNotBeNil)
})