package business import ( "context" "testing" "kra/internal/biz/business" ) func TestGameOptionsRequireVisibleApprovedApplications(t *testing.T) { db, _ := prepareChannels(t) for _, sql := range []string{ "INSERT INTO tab_game VALUES('lx',3,'子渠道游戏'),('lx',4,'未申请包服'),('lx',5,'其他商务游戏'),('lx',6,'待审核游戏')", "INSERT INTO tab_promote_apply VALUES('lx',104,5,1),('lx',100,6,0)", } { if err := db.Exec(sql).Error; err != nil { t.Fatal(err) } } repo := NewLedgerRepo(testData{db}) ctx := context.Background() rows, err := repo.Games(ctx, channelTestScope(), nil, "", 100) if err != nil || len(rows) != 3 { t.Fatalf("只能返回可见渠道已通过申请的游戏,重复申请不能重复: %+v %v", rows, err) } for _, row := range rows { if row.SourceDB != "lx" || row.ID > 3 { t.Fatalf("泄漏未申请或其他商务的游戏: %+v", row) } } rows, err = repo.Games(ctx, channelTestScope(), []string{"hw"}, "", 100) if err != nil || len(rows) != 0 { t.Fatal("不能借用其他平台同号游戏的申请") } rows, err = repo.Games(ctx, business.UserScope{SelfID: 99, OnlySelf: true}, []string{"lx"}, "", 100) if err != nil || len(rows) != 0 { t.Fatal("无可见绑定不能退化为全部游戏") } rows, err = repo.Games(ctx, channelTestScope(), nil, "子渠道", 1) if err != nil || len(rows) != 1 || rows[0].ID != 3 { t.Fatal("应支持已申请游戏的关键词与数量筛选") } if err := db.Exec("DROP TABLE tab_promote_apply").Error; err != nil { t.Fatal(err) } if _, err := repo.Games(ctx, channelTestScope(), nil, "", 100); err != business.ErrGameOptionsUnavailable { t.Fatal("缺申请表不能开放所有游戏") } } func TestGameReportsRejectUnapprovedGamesEvenWithVisibleHistory(t *testing.T) { db, repo, scope, filter := prepareAnalyticsData(t) if err := db.Exec("UPDATE tab_promote_apply SET status=0 WHERE source_db='lx' AND game_id=1").Error; err != nil { t.Fatal(err) } filter.Sources = []string{"lx"} filter.GameNames = []string{"历史游戏甲"} rows, err := repo.Aggregate(context.Background(), business.GameAnalytics, scope, filter) if err != nil || !rows.Available || len(rows.Rows) != 0 { t.Fatalf("直接指定未申请游戏也不能返回统计: %+v %v", rows, err) } }