feat(tenant): 隔离邀请返利与推广追踪数据
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package invitation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"hfb_sys/backend/internal/database"
|
||||
"hfb_sys/backend/internal/model"
|
||||
"hfb_sys/backend/internal/tenancy"
|
||||
)
|
||||
|
||||
func TestRebateConfigIsScopedByTenant(t *testing.T) {
|
||||
db := database.NewTestDB()
|
||||
if err := database.AutoMigrateIfMissing(db, &model.InvitationRebateConfig{}); err != nil {
|
||||
t.Fatalf("migrate rebate config: %v", err)
|
||||
}
|
||||
repo := NewRepository(db)
|
||||
ctxA := tenancy.WithScope(context.Background(), tenancy.Scope{TenantID: 101, TenantCode: "tenant_a"})
|
||||
ctxB := tenancy.WithScope(context.Background(), tenancy.Scope{TenantID: 202, TenantCode: "tenant_b"})
|
||||
enabled := true
|
||||
|
||||
if _, err := repo.UpdateRebateConfig(ctxA, 0, UpdateConfigRequest{
|
||||
FirstMonthRate: 0.50,
|
||||
SecondMonthRate: 0.25,
|
||||
SubsequentRate: 0.10,
|
||||
Enabled: &enabled,
|
||||
}); err != nil {
|
||||
t.Fatalf("update tenant A config: %v", err)
|
||||
}
|
||||
if _, err := repo.UpdateRebateConfig(ctxB, 0, UpdateConfigRequest{
|
||||
FirstMonthRate: 0.70,
|
||||
SecondMonthRate: 0.35,
|
||||
SubsequentRate: 0.20,
|
||||
Enabled: &enabled,
|
||||
}); err != nil {
|
||||
t.Fatalf("update tenant B config: %v", err)
|
||||
}
|
||||
|
||||
cfgA, err := repo.GetRebateConfig(ctxA, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("get tenant A config: %v", err)
|
||||
}
|
||||
cfgB, err := repo.GetRebateConfig(ctxB, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("get tenant B config: %v", err)
|
||||
}
|
||||
if cfgA.TenantID != 101 || cfgA.FirstMonthRate != 0.50 {
|
||||
t.Fatalf("tenant A config = %+v", cfgA)
|
||||
}
|
||||
if cfgB.TenantID != 202 || cfgB.FirstMonthRate != 0.70 {
|
||||
t.Fatalf("tenant B config = %+v", cfgB)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user