feat: integrate OA activation workflows and business migration
This commit is contained in:
@@ -37,7 +37,7 @@ func prepareActivations(t *testing.T) (*gorm.DB, *gorm.DB, business.ActivationRe
|
||||
end := time.Unix(2000, 0).UTC()
|
||||
channel := uint64(100)
|
||||
amount := "30.30"
|
||||
pos := []activationPO{{ID: 1, PromoteID: &channel, PlatformName: "lx", PromoteAccount: "渠道一", BusierAccount: "Own", BindAt: &start, ReachAt: &end, Status: "reached", AccumAmount: &amount}, {ID: 2, PlatformName: "hw", BusierAccount: "own", Status: "pending"}, {ID: 3, PlatformName: "lx", BusierAccount: "Other", Status: "in_progress"}, {ID: 4, PlatformName: "lx", BusierAccount: "Own", Status: "rejected", DeletedAt: &end}}
|
||||
pos := []activationPO{{ID: 1, PromoteID: &channel, PlatformName: "lx", PromoteAccount: "渠道一", BusierAccount: "Own", BindAt: &start, ReachAt: &end, UnbindAt: &end, Status: "reached", AccumAmount: &amount}, {ID: 2, PlatformName: "hw", BusierAccount: "own", Status: "pending"}, {ID: 3, PlatformName: "lx", BusierAccount: "Other", Status: "in_progress"}, {ID: 4, PlatformName: "lx", BusierAccount: "Own", Status: "rejected", DeletedAt: &end}}
|
||||
if err := oa.Create(&pos).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -53,7 +53,7 @@ func prepareActivations(t *testing.T) (*gorm.DB, *gorm.DB, business.ActivationRe
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
return db, oa, NewActivationRepo(testData{db}, activationDatabases{oa})
|
||||
return db, oa, NewActivationRepo(testData{db}, activationSDKFixtures(t, db, oa))
|
||||
}
|
||||
func TestActivationListsReadOAAndRestrictAccounts(t *testing.T) {
|
||||
db, _, repo := prepareActivations(t)
|
||||
@@ -67,7 +67,7 @@ func TestActivationListsReadOAAndRestrictAccounts(t *testing.T) {
|
||||
t.Fatalf("OA 列表或排序错误: %+v %v", page, err)
|
||||
}
|
||||
page, err = repo.List(ctx, business.ActivationScope{All: true}, business.ActivationFilter{PlatformNames: []string{"lx"}, Statuses: []string{"reached"}})
|
||||
if err != nil || page.Total != 1 || page.Rows[0].AccumAmount != "30.30" {
|
||||
if err != nil || page.Total != 1 || page.Rows[0].AccumAmount != "33.60" {
|
||||
t.Fatalf("平台或状态筛选错误: %+v %v", page, err)
|
||||
}
|
||||
if _, err := repo.Find(ctx, 4); err != business.ErrActivationNotFound {
|
||||
@@ -87,7 +87,11 @@ func TestActivationListsReadOAAndRestrictAccounts(t *testing.T) {
|
||||
}
|
||||
}
|
||||
func TestActivationSpendTreePlatformAndInclusiveBounds(t *testing.T) {
|
||||
db, _, repo := prepareActivations(t)
|
||||
_, _, repo := prepareActivations(t)
|
||||
db, err := repo.(*activationRepo).databases.Database("lx")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
end := int64(2000)
|
||||
query := business.ActivationSpendQuery{PlatformName: "lx", PromoteID: 100, Start: 1000, End: &end}
|
||||
items, err := repo.Spend(context.Background(), query)
|
||||
@@ -113,3 +117,38 @@ func TestActivationSpendTreePlatformAndInclusiveBounds(t *testing.T) {
|
||||
t.Fatal("确定没有渠道时应返回真实空流水")
|
||||
}
|
||||
}
|
||||
|
||||
func activationSDKFixtures(t *testing.T, db, oa *gorm.DB) activationTestSources {
|
||||
t.Helper()
|
||||
sources := activationTestSources{"oa": oa}
|
||||
var files []struct{ Name, File string }
|
||||
if err := db.Raw("PRAGMA database_list").Scan(&files).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var file string
|
||||
for _, f := range files {
|
||||
if f.Name == "main" {
|
||||
file = f.File
|
||||
}
|
||||
}
|
||||
for _, source := range []string{"lx", "hw", "yq"} {
|
||||
sdk := openTestDB(t)
|
||||
pool, _ := sdk.DB()
|
||||
pool.SetMaxOpenConns(1)
|
||||
if err := sdk.Exec("ATTACH DATABASE ? AS sample", file).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, table := range []string{"tab_promote", "tab_spend", "tab_user"} {
|
||||
if db.Migrator().HasTable(table) {
|
||||
if err := sdk.Exec("CREATE TABLE "+table+" AS SELECT * FROM sample."+table+" WHERE source_db=?", source).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := sdk.Exec("DETACH DATABASE sample").Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sources[source] = sdk
|
||||
}
|
||||
return sources
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user