fix(publish): 后台详情与品牌列表改读基表,修复未发布内容在后台不可达
This commit is contained in:
@ -51,6 +51,16 @@ func TestPublicReadHidesUnpublishedRunway(t *testing.T) {
|
||||
t.Fatalf("后台应读到 pending 行与其图片,实际 rw=%v imgs=%d", rw != nil, len(baseImgs))
|
||||
}
|
||||
|
||||
// 后台详情通路:FindByIDBase 也必须读得到 pending(后台详情页据此渲染;
|
||||
// 若它读视图,后台列表里的待审行点进去就 404)。
|
||||
baseRow, err := repo.FindByIDBase(ctx, idStr)
|
||||
if err != nil {
|
||||
t.Fatalf("后台 FindByIDBase 应读到 pending 行: %v", err)
|
||||
}
|
||||
if baseRow == nil || baseRow.ID != id {
|
||||
t.Fatalf("后台 FindByIDBase 返回不符: %+v", baseRow)
|
||||
}
|
||||
|
||||
// 置为已发布后,公开侧才可见。
|
||||
if err := db.Model(&model.BrandRunway{}).Where("id = ?", id).Update("status", model.StatusPublished).Error; err != nil {
|
||||
t.Fatalf("置为已发布失败: %v", err)
|
||||
@ -113,6 +123,15 @@ func TestPublicReadHidesUnpublishedStreet(t *testing.T) {
|
||||
t.Fatalf("后台列表应看到 pending 街拍,实际 total=%d", adminTotal)
|
||||
}
|
||||
|
||||
// 后台详情通路:FindByIDBase 也必须读得到 pending(否则后台详情页 404)。
|
||||
baseSnap, err := repo.FindByIDBase(ctx, idStr)
|
||||
if err != nil {
|
||||
t.Fatalf("后台 FindByIDBase 应读到 pending 行: %v", err)
|
||||
}
|
||||
if baseSnap == nil || baseSnap.ID != id {
|
||||
t.Fatalf("后台 FindByIDBase 返回不符: %+v", baseSnap)
|
||||
}
|
||||
|
||||
if err := db.Model(&model.StreetSnap{}).Where("id = ?", id).Update("status", model.StatusPublished).Error; err != nil {
|
||||
t.Fatalf("置为已发布失败: %v", err)
|
||||
}
|
||||
@ -124,3 +143,59 @@ func TestPublicReadHidesUnpublishedStreet(t *testing.T) {
|
||||
t.Fatalf("已发布街拍应出现在公开列表,实际 total=%d", total)
|
||||
}
|
||||
}
|
||||
|
||||
// hasBrandID 判断品牌列表里是否含指定 id(按 id 判定,避免受库里既有同名/同首字母品牌干扰)。
|
||||
func hasBrandID(items []model.Brand, id uint32) bool {
|
||||
for _, it := range items {
|
||||
if it.ID == id {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// TestBrandIndexSplitsPublicAndAdmin 品牌 A-Z 索引的公开/后台分野:
|
||||
// 只有待审走秀的品牌不得出现在公开索引(否则未发布内容从索引泄露),
|
||||
// 但必须出现在后台列表(否则该品牌从后台「消失」,审核员无从下手)。
|
||||
func TestBrandIndexSplitsPublicAndAdmin(t *testing.T) {
|
||||
db := testDB(t)
|
||||
applyMigration(t, db, "2026-09-22-01-single-table-publish.sql")
|
||||
ctx := context.Background()
|
||||
repo := NewBrandRepository(db)
|
||||
|
||||
now := uint32(1_800_000_000)
|
||||
brand := model.Brand{NameEn: "ViewTestBrand", NameCn: "视图测试品牌", CreatedAt: now, UpdatedAt: now}
|
||||
if err := db.Create(&brand).Error; err != nil {
|
||||
t.Fatalf("插入品牌失败: %v", err)
|
||||
}
|
||||
rw := model.BrandRunway{
|
||||
BrandID: brand.ID, TitleEn: "view-test-brand", Year: 1995,
|
||||
Status: model.StatusPending, CreatedAt: now, UpdatedAt: now,
|
||||
}
|
||||
if err := db.Create(&rw).Error; err != nil {
|
||||
t.Fatalf("插入走秀失败: %v", err)
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
db.Exec("DELETE FROM brand_runways WHERE id = ?", rw.ID)
|
||||
db.Exec("DELETE FROM brands WHERE id = ?", brand.ID)
|
||||
})
|
||||
|
||||
// 字母桶 V + 大页,确保命中「必须有走秀档案」的子查询分支、且不会被分页截断。
|
||||
q := dto.BrandQuery{Letter: "V", Page: 1, Size: 400}
|
||||
|
||||
pubItems, _, err := repo.List(ctx, q, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("公开 List 出错: %v", err)
|
||||
}
|
||||
if hasBrandID(pubItems, brand.ID) {
|
||||
t.Fatalf("只有待审走秀的品牌不应出现在公开索引,实际出现在结果里(id=%d)", brand.ID)
|
||||
}
|
||||
|
||||
admItems, _, err := repo.ListAdmin(ctx, q, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("后台 ListAdmin 出错: %v", err)
|
||||
}
|
||||
if !hasBrandID(admItems, brand.ID) {
|
||||
t.Fatalf("后台列表应看到只有待审走秀的品牌(id=%d)", brand.ID)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user