Fix gift list type filtering
This commit is contained in:
parent
3fe8c907fd
commit
1cffc335ce
@ -2506,6 +2506,126 @@ func TestGiftConfigRegionFilter(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestListGiftConfigsWithoutTypeFilterIncludesLuckyTypes 验证礼物面板预加载全部礼物时不会被空类型过滤误收窄到普通礼物。
|
||||
func TestListGiftConfigsWithoutTypeFilterIncludesLuckyTypes(t *testing.T) {
|
||||
repository := mysqltest.NewRepository(t)
|
||||
svc := walletservice.New(repository)
|
||||
ctx := context.Background()
|
||||
|
||||
normalResource, err := svc.CreateResource(ctx, resourcedomain.ResourceCommand{
|
||||
ResourceCode: "gift_all_normal",
|
||||
ResourceType: resourcedomain.TypeGift,
|
||||
Name: "All Normal",
|
||||
Status: resourcedomain.StatusActive,
|
||||
Grantable: true,
|
||||
GrantStrategy: resourcedomain.GrantStrategyIncreaseQuantity,
|
||||
UsageScopes: []string{"gift"},
|
||||
OperatorUserID: 90001,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("create normal gift resource failed: %v", err)
|
||||
}
|
||||
luckyResource, err := svc.CreateResource(ctx, resourcedomain.ResourceCommand{
|
||||
ResourceCode: "gift_all_lucky",
|
||||
ResourceType: resourcedomain.TypeGift,
|
||||
Name: "All Lucky",
|
||||
Status: resourcedomain.StatusActive,
|
||||
Grantable: true,
|
||||
GrantStrategy: resourcedomain.GrantStrategyIncreaseQuantity,
|
||||
UsageScopes: []string{"gift"},
|
||||
OperatorUserID: 90001,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("create lucky gift resource failed: %v", err)
|
||||
}
|
||||
superLuckyResource, err := svc.CreateResource(ctx, resourcedomain.ResourceCommand{
|
||||
ResourceCode: "gift_all_super_lucky",
|
||||
ResourceType: resourcedomain.TypeGift,
|
||||
Name: "All Super Lucky",
|
||||
Status: resourcedomain.StatusActive,
|
||||
Grantable: true,
|
||||
GrantStrategy: resourcedomain.GrantStrategyIncreaseQuantity,
|
||||
UsageScopes: []string{"gift"},
|
||||
OperatorUserID: 90001,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("create super lucky gift resource failed: %v", err)
|
||||
}
|
||||
commands := []resourcedomain.GiftConfigCommand{
|
||||
{
|
||||
GiftID: "all-normal",
|
||||
ResourceID: normalResource.ResourceID,
|
||||
Status: resourcedomain.StatusActive,
|
||||
Name: "All Normal",
|
||||
PriceVersion: "v1",
|
||||
CoinPrice: 100,
|
||||
HeatValue: 100,
|
||||
OperatorUserID: 90001,
|
||||
RegionIDs: []int64{0},
|
||||
},
|
||||
{
|
||||
GiftID: "all-lucky",
|
||||
ResourceID: luckyResource.ResourceID,
|
||||
Status: resourcedomain.StatusActive,
|
||||
Name: "All Lucky",
|
||||
GiftTypeCode: resourcedomain.GiftTypeLucky,
|
||||
PriceVersion: "v1",
|
||||
CoinPrice: 200,
|
||||
HeatValue: 200,
|
||||
OperatorUserID: 90001,
|
||||
RegionIDs: []int64{0},
|
||||
},
|
||||
{
|
||||
GiftID: "all-super-lucky",
|
||||
ResourceID: superLuckyResource.ResourceID,
|
||||
Status: resourcedomain.StatusActive,
|
||||
Name: "All Super Lucky",
|
||||
GiftTypeCode: resourcedomain.GiftTypeSuperLucky,
|
||||
PriceVersion: "v1",
|
||||
CoinPrice: 300,
|
||||
HeatValue: 300,
|
||||
OperatorUserID: 90001,
|
||||
RegionIDs: []int64{0},
|
||||
},
|
||||
}
|
||||
for _, command := range commands {
|
||||
if _, err := svc.CreateGiftConfig(ctx, command); err != nil {
|
||||
t.Fatalf("create gift config %s failed: %v", command.GiftID, err)
|
||||
}
|
||||
}
|
||||
|
||||
// 空 gift_type_code 表示“不按类型过滤”,gateway 的 gift-tabs 会依赖这次查询一次性拿到所有礼物类型。
|
||||
items, total, err := svc.ListGiftConfigs(ctx, resourcedomain.ListGiftConfigsQuery{
|
||||
ActiveOnly: true,
|
||||
FilterRegion: true,
|
||||
RegionID: 0,
|
||||
Page: 1,
|
||||
PageSize: 10,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("list all gift configs failed: %v", err)
|
||||
}
|
||||
if total != 3 || !giftIDsContain(items, "all-normal") || !giftIDsContain(items, "all-lucky") || !giftIDsContain(items, "all-super-lucky") {
|
||||
t.Fatalf("all gift type list mismatch total=%d items=%+v", total, items)
|
||||
}
|
||||
|
||||
// 显式传入 lucky 时仍保留类型过滤能力,避免修复全部礼物预加载时破坏后台按类型筛选。
|
||||
luckyItems, luckyTotal, err := svc.ListGiftConfigs(ctx, resourcedomain.ListGiftConfigsQuery{
|
||||
GiftTypeCode: resourcedomain.GiftTypeLucky,
|
||||
ActiveOnly: true,
|
||||
FilterRegion: true,
|
||||
RegionID: 0,
|
||||
Page: 1,
|
||||
PageSize: 10,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("list lucky gift configs failed: %v", err)
|
||||
}
|
||||
if luckyTotal != 1 || !giftIDsContain(luckyItems, "all-lucky") || giftIDsContain(luckyItems, "all-normal") || giftIDsContain(luckyItems, "all-super-lucky") {
|
||||
t.Fatalf("lucky gift type filter mismatch total=%d items=%+v", luckyTotal, luckyItems)
|
||||
}
|
||||
}
|
||||
|
||||
// TestGrantResourceGroupExpandsWalletAssetAndEntitlement 验证资源组赠送会原子展开钱包资产入账和非钱包权益。
|
||||
func TestGrantResourceGroupExpandsWalletAssetAndEntitlement(t *testing.T) {
|
||||
repository := mysqltest.NewRepository(t)
|
||||
|
||||
@ -2913,7 +2913,10 @@ func normalizeResourceGroupListQuery(query resourcedomain.ListResourceGroupsQuer
|
||||
func normalizeGiftConfigListQuery(query resourcedomain.ListGiftConfigsQuery) resourcedomain.ListGiftConfigsQuery {
|
||||
query.Status = strings.ToLower(strings.TrimSpace(query.Status))
|
||||
query.Keyword = strings.TrimSpace(query.Keyword)
|
||||
query.GiftTypeCode = resourcedomain.NormalizeGiftTypeCode(query.GiftTypeCode)
|
||||
// 列表查询的 gift_type_code 是可选过滤条件;空值必须保持为空,避免礼物面板加载全部礼物时被默认收窄到 normal。
|
||||
if strings.TrimSpace(query.GiftTypeCode) != "" {
|
||||
query.GiftTypeCode = resourcedomain.NormalizeGiftTypeCode(query.GiftTypeCode)
|
||||
}
|
||||
query.Page, query.PageSize = normalizePage(query.Page, query.PageSize)
|
||||
return query
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user