|
|
|
@@ -48,13 +48,13 @@ func TestRedeem_Success(t *testing.T) { |
|
|
|
|
|
|
|
// 创建兑换码 |
|
|
|
redemption := Redemption{ |
|
|
|
Id: 1, |
|
|
|
UserId: 1, |
|
|
|
Key: "test-key-123", |
|
|
|
Status: common.RedemptionCodeStatusEnabled, |
|
|
|
Quota: 50000, |
|
|
|
CreatedTime: common.GetTimestamp(), |
|
|
|
ExpiredTime: 0, // 永不过期 |
|
|
|
Id: 1, |
|
|
|
UserId: 1, |
|
|
|
Key: "test-key-123", |
|
|
|
Status: common.RedemptionCodeStatusEnabled, |
|
|
|
Quota: 50000, |
|
|
|
CreatedTime: common.GetTimestamp(), |
|
|
|
ExpiredTime: 0, // 永不过期 |
|
|
|
} |
|
|
|
require.NoError(t, db.Create(&redemption).Error) |
|
|
|
|
|
|
|
@@ -148,13 +148,13 @@ func TestRedeem_Expired(t *testing.T) { |
|
|
|
|
|
|
|
// 创建已过期的兑换码 |
|
|
|
redemption := Redemption{ |
|
|
|
Id: 1, |
|
|
|
UserId: 1, |
|
|
|
Key: "expired-key", |
|
|
|
Status: common.RedemptionCodeStatusEnabled, |
|
|
|
Quota: 50000, |
|
|
|
CreatedTime: common.GetTimestamp() - 86400, |
|
|
|
ExpiredTime: common.GetTimestamp() - 3600, // 已过期 |
|
|
|
Id: 1, |
|
|
|
UserId: 1, |
|
|
|
Key: "expired-key", |
|
|
|
Status: common.RedemptionCodeStatusEnabled, |
|
|
|
Quota: 50000, |
|
|
|
CreatedTime: common.GetTimestamp() - 86400, |
|
|
|
ExpiredTime: common.GetTimestamp() - 3600, // 已过期 |
|
|
|
} |
|
|
|
require.NoError(t, db.Create(&redemption).Error) |
|
|
|
|
|
|
|
@@ -252,3 +252,58 @@ func TestRedeem_SyncedUser(t *testing.T) { |
|
|
|
require.NoError(t, db.First(&updatedUser, 100).Error) |
|
|
|
assert.Equal(t, 150000, updatedUser.Quota) |
|
|
|
} |
|
|
|
|
|
|
|
func TestRedemptionUpdateRemarkPersistsRemark(t *testing.T) { |
|
|
|
db := setupRedemptionDB(t) |
|
|
|
|
|
|
|
redemption := Redemption{ |
|
|
|
Id: 1, |
|
|
|
UserId: 1, |
|
|
|
Key: "remark-update-key", |
|
|
|
Status: common.RedemptionCodeStatusEnabled, |
|
|
|
Name: "starter", |
|
|
|
Remark: "initial-note", |
|
|
|
Quota: 100, |
|
|
|
CreatedTime: common.GetTimestamp(), |
|
|
|
} |
|
|
|
require.NoError(t, db.Create(&redemption).Error) |
|
|
|
|
|
|
|
redemption.Remark = "vip-updated" |
|
|
|
require.NoError(t, redemption.Update()) |
|
|
|
|
|
|
|
var updated Redemption |
|
|
|
require.NoError(t, db.First(&updated, redemption.Id).Error) |
|
|
|
assert.Equal(t, "vip-updated", updated.Remark) |
|
|
|
} |
|
|
|
|
|
|
|
func TestSearchRedemptionsByRemarkRemark(t *testing.T) { |
|
|
|
db := setupRedemptionDB(t) |
|
|
|
|
|
|
|
require.NoError(t, db.Create(&Redemption{ |
|
|
|
Id: 1, |
|
|
|
UserId: 1, |
|
|
|
Key: "remark-search-key", |
|
|
|
Status: common.RedemptionCodeStatusEnabled, |
|
|
|
Name: "starter-pack", |
|
|
|
Remark: "vip benefit", |
|
|
|
Quota: 100, |
|
|
|
CreatedTime: common.GetTimestamp(), |
|
|
|
}).Error) |
|
|
|
require.NoError(t, db.Create(&Redemption{ |
|
|
|
Id: 2, |
|
|
|
UserId: 1, |
|
|
|
Key: "remark-search-other", |
|
|
|
Status: common.RedemptionCodeStatusEnabled, |
|
|
|
Name: "basic-pack", |
|
|
|
Remark: "standard benefit", |
|
|
|
Quota: 100, |
|
|
|
CreatedTime: common.GetTimestamp(), |
|
|
|
}).Error) |
|
|
|
|
|
|
|
results, total, err := SearchRedemptions("vip", 0, 10) |
|
|
|
require.NoError(t, err) |
|
|
|
require.Equal(t, int64(1), total) |
|
|
|
require.Len(t, results, 1) |
|
|
|
assert.Equal(t, 1, results[0].Id) |
|
|
|
assert.Equal(t, "vip benefit", results[0].Remark) |
|
|
|
} |