fix(listing-review): 按商品来源站点隔离审核
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"hfb_sys/backend/internal/database"
|
||||
"hfb_sys/backend/internal/model"
|
||||
"hfb_sys/backend/internal/modules/systemconfig"
|
||||
"hfb_sys/backend/internal/tenancy"
|
||||
)
|
||||
|
||||
type stubConfigReader map[string]string
|
||||
@@ -479,6 +480,74 @@ func TestListPendingReviewIncludesSourceChannel(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPendingReviewAndApprovalAreScopedToSourceTenant(t *testing.T) {
|
||||
db := database.NewTestDB()
|
||||
if err := database.MigrateListingLifecycleTestSchema(db); err != nil {
|
||||
t.Fatalf("failed to migrate test db: %v", err)
|
||||
}
|
||||
tenants := []model.Tenant{
|
||||
{Code: "tenant_a", Name: "A站", Status: "active"},
|
||||
{Code: "tenant_b", Name: "B站", Status: "active"},
|
||||
}
|
||||
if err := db.Create(&tenants).Error; err != nil {
|
||||
t.Fatalf("failed to create tenants: %v", err)
|
||||
}
|
||||
users := []model.User{
|
||||
{TenantID: tenants[0].ID, Phone: "18800000101", RealnameStatus: "verified", Status: "active"},
|
||||
{TenantID: tenants[1].ID, Phone: "18800000102", RealnameStatus: "verified", Status: "active"},
|
||||
}
|
||||
if err := db.Create(&users).Error; err != nil {
|
||||
t.Fatalf("failed to create users: %v", err)
|
||||
}
|
||||
listings := make([]model.RentalListing, 0, 2)
|
||||
for index, tenant := range tenants {
|
||||
account := model.GameAccount{
|
||||
SourceTenantID: tenant.ID,
|
||||
OwnerID: users[index].ID,
|
||||
GameName: "delta_force",
|
||||
ServerRegion: "QQ",
|
||||
LoginPlatform: "扫码",
|
||||
Title: tenant.Name + "待审核账号",
|
||||
Status: "draft",
|
||||
}
|
||||
if err := db.Create(&account).Error; err != nil {
|
||||
t.Fatalf("failed to create account: %v", err)
|
||||
}
|
||||
listing := model.RentalListing{
|
||||
SourceTenantID: tenant.ID,
|
||||
ListingNo: "PENDING-" + tenant.Code,
|
||||
AccountID: account.ID,
|
||||
OwnerID: users[index].ID,
|
||||
PriceCent: 10000,
|
||||
Status: "draft",
|
||||
ReviewStatus: "pending",
|
||||
}
|
||||
if err := db.Create(&listing).Error; err != nil {
|
||||
t.Fatalf("failed to create listing: %v", err)
|
||||
}
|
||||
listings = append(listings, listing)
|
||||
}
|
||||
|
||||
repo := NewRepository(db, nil)
|
||||
ctxA := tenancy.WithScope(t.Context(), tenancy.Scope{TenantID: tenants[0].ID})
|
||||
items, err := repo.ListPendingReview(ctxA)
|
||||
if err != nil {
|
||||
t.Fatalf("ListPendingReview() error = %v", err)
|
||||
}
|
||||
if len(items) != 1 || items[0].ID != listings[0].ID {
|
||||
t.Fatalf("pending items = %+v, want only listing %d", items, listings[0].ID)
|
||||
}
|
||||
if _, err := repo.FindAdmin(ctxA, listings[1].ID); !IsNotFound(err) {
|
||||
t.Fatalf("cross-tenant FindAdmin error = %v, want not found", err)
|
||||
}
|
||||
if _, err := repo.Approve(ctxA, listings[1].ID); !IsNotFound(err) {
|
||||
t.Fatalf("cross-tenant Approve error = %v, want not found", err)
|
||||
}
|
||||
if _, err := repo.Approve(ctxA, listings[0].ID); err != nil {
|
||||
t.Fatalf("Approve current tenant listing: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExternalAccountToCreateRequestMapsUploadFields(t *testing.T) {
|
||||
req := externalAccountToCreateRequest("客服1", 1772526103000, ExternalAccountData{
|
||||
LoginMethod: "QQ账号密码",
|
||||
|
||||
Reference in New Issue
Block a user