feat: 迁移游戏商务绑定审核流程和列表
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
package business
|
||||
|
||||
import (
|
||||
"context"
|
||||
"kra/internal/biz/business"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestBindingRepositoryClearsAuditAndUsesCompositeIdentity(t *testing.T) {
|
||||
db := prepareAccounts(t)
|
||||
r := NewBindingRepo(testData{db})
|
||||
ctx := context.Background()
|
||||
reason, review := "旧驳回", "审核员"
|
||||
now := time.Now()
|
||||
key := business.PlatformKey{SourceDB: "lx", BusierID: 7}
|
||||
if err := r.Save(ctx, &business.Binding{UserID: 3, PlatformKey: key, Status: "2", RejectReason: &reason, ReviewTime: &now, ReviewAccount: &review}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := r.Save(ctx, &business.Binding{UserID: 3, PlatformKey: business.PlatformKey{SourceDB: "hw", BusierID: 7}, Status: "0"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := r.WithPlatformLock(ctx, key, func(txctx context.Context) error {
|
||||
return r.Save(txctx, &business.Binding{UserID: 3, PlatformKey: key, Status: "3", CreatedAt: now})
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rows, err := r.ForPlatform(ctx, key)
|
||||
if err != nil || len(rows) != 1 {
|
||||
t.Fatalf("查询失败: %+v %v", rows, err)
|
||||
}
|
||||
if rows[0].Status != "3" || rows[0].RejectReason != nil || rows[0].ReviewTime != nil || rows[0].ReviewAccount != nil {
|
||||
t.Fatal("重提未清除旧审核信息")
|
||||
}
|
||||
if err := r.Delete(ctx, 4, key); err != business.ErrBindingNotFound {
|
||||
t.Fatal("不能删除其他用户绑定")
|
||||
}
|
||||
if err := r.Delete(ctx, 3, key); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
other, err := r.ForPlatform(ctx, business.PlatformKey{SourceDB: "hw", BusierID: 7})
|
||||
if err != nil || len(other) != 1 {
|
||||
t.Fatal("解绑影响了同 ID 的其他平台")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBindingListLoadsDTOFieldsAndSurvivesMissingChannels(t *testing.T) {
|
||||
db := prepareAccounts(t)
|
||||
if err := db.Create(&accountPO{ID: 3, Username: "child", Level: 3, IDPath: "0,1,2"}).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r := NewBindingRepo(testData{db})
|
||||
ctx := context.Background()
|
||||
for _, source := range []string{"lx", "hw"} {
|
||||
if err := r.Save(ctx, &business.Binding{UserID: 3, PlatformKey: business.PlatformKey{SourceDB: source, BusierID: 7}, Account: "sdk", Status: "0", CreatedAt: time.Now()}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
if err := db.Exec("INSERT INTO tab_promote VALUES(1,'lx',7,1,1),(2,'lx',7,2,1)").Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rows, total, err := r.List(ctx, business.UserScope{OnlySelf: true, SelfID: 3}, business.BindingFilter{SourceDBs: []string{"lx"}})
|
||||
if err != nil || total != 1 || len(rows) != 1 {
|
||||
t.Fatalf("绑定列表错误: %+v %d %v", rows, total, err)
|
||||
}
|
||||
if rows[0].UserID != 3 || rows[0].UserName != "child" || rows[0].Account != "sdk" || rows[0].PromoteCount == nil || *rows[0].PromoteCount != 1 {
|
||||
t.Fatalf("绑定字段或渠道统计错误: %+v", rows[0])
|
||||
}
|
||||
if err := db.Exec("DROP TABLE tab_promote").Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rows, total, err = r.List(ctx, business.UserScope{OnlySelf: true, SelfID: 3}, business.BindingFilter{})
|
||||
if err != nil || total != 2 || len(rows) != 2 || rows[0].PromoteCount != nil {
|
||||
t.Fatalf("缺渠道表不应阻断绑定资料: %+v %d %v", rows, total, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user