feat(distribution): 独立分销前台商城多租户体系、货源与订单数据严格隔离
This commit is contained in:
@@ -746,3 +746,49 @@ func containsString(values []string, target string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func TestListPublicWithDistributionSiteCode(t *testing.T) {
|
||||
db := database.NewTestDB()
|
||||
if err := database.MigrateListingLifecycleTestSchema(db); err != nil {
|
||||
t.Fatalf("migrate err: %v", err)
|
||||
}
|
||||
if err := db.AutoMigrate(&model.DistributionSite{}, &model.DistributionSiteAccount{}); err != nil {
|
||||
t.Fatalf("migrate distribution err: %v", err)
|
||||
}
|
||||
|
||||
repo := NewRepository(db, nil)
|
||||
|
||||
account1 := model.GameAccount{Title: "号1", GameName: "delta", Status: "active"}
|
||||
account2 := model.GameAccount{Title: "号2", GameName: "delta", Status: "active"}
|
||||
db.Create(&account1)
|
||||
db.Create(&account2)
|
||||
|
||||
l1 := model.RentalListing{ListingNo: "L101", AccountID: account1.ID, Status: "published", ReviewStatus: "approved", PriceCent: 1000}
|
||||
l2 := model.RentalListing{ListingNo: "L102", AccountID: account2.ID, Status: "published", ReviewStatus: "approved", PriceCent: 2000}
|
||||
db.Create(&l1)
|
||||
db.Create(&l2)
|
||||
|
||||
site := model.DistributionSite{SiteCode: "site_alpha", SiteName: "分销A", Domain: "a.com", Status: "active", DisplayAccountEnabled: true}
|
||||
db.Create(&site)
|
||||
|
||||
dsa := model.DistributionSiteAccount{SiteID: site.ID, AccountID: account1.ID, ListingID: l1.ID, DisplayStatus: "enabled"}
|
||||
db.Create(&dsa)
|
||||
|
||||
res, err := repo.ListPublic(context.Background(), PublicListQuery{
|
||||
DistributionSiteCode: "site_alpha",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("ListPublic err: %v", err)
|
||||
}
|
||||
if len(res.Items) != 1 || res.Items[0].ListingNo != "L101" {
|
||||
t.Fatalf("expected only L101, got %+v", res.Items)
|
||||
}
|
||||
|
||||
allRes, err := repo.ListPublic(context.Background(), PublicListQuery{})
|
||||
if err != nil {
|
||||
t.Fatalf("ListPublic err: %v", err)
|
||||
}
|
||||
if len(allRes.Items) != 2 {
|
||||
t.Fatalf("expected 2 listings for main site, got %d", len(allRes.Items))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user