refactor(publish): 审核侧切到正式表,通过即改状态不再晋升

This commit is contained in:
toom1996
2026-09-23 11:09:12 +08:00
parent e0ce81318d
commit 76626b8372
19 changed files with 423 additions and 775 deletions

View File

@ -14,27 +14,27 @@ import (
// fakeGroupRepo 只实现分组相关的仓储方法,其余由嵌入的接口兜底(测试中不会调到未实现的方法)。
type fakeGroupRepo struct {
repository.ReviewRepository
images []model.StreetSnapDraftImage
detail *model.StreetSnapDraft
attachFn func(draftID, mainID uint32, imgIDs []uint32) error
images []model.StreetSnapImage
detail *model.StreetSnap
attachFn func(snapID, mainID uint32, imgIDs []uint32) error
}
func (f *fakeGroupRepo) StreetDraftDetail(_ context.Context, _ uint32) (*model.StreetSnapDraft, error) {
func (f *fakeGroupRepo) StreetRecordDetail(_ context.Context, _ uint32) (*model.StreetSnap, error) {
return f.detail, nil
}
func (f *fakeGroupRepo) StreetDraftImages(_ context.Context, _ uint32) ([]model.StreetSnapDraftImage, error) {
func (f *fakeGroupRepo) StreetRecordImages(_ context.Context, _ uint32) ([]model.StreetSnapImage, error) {
return f.images, nil
}
func (f *fakeGroupRepo) AttachStreetDraftImages(_ context.Context, draftID, mainID uint32, imgIDs []uint32) error {
func (f *fakeGroupRepo) AttachStreetSnapImages(_ context.Context, snapID, mainID uint32, imgIDs []uint32) error {
if f.attachFn != nil {
return f.attachFn(draftID, mainID, imgIDs)
return f.attachFn(snapID, mainID, imgIDs)
}
return nil
}
func (f *fakeGroupRepo) DetachStreetDraftImage(_ context.Context, _ uint32, _ uint32) error {
func (f *fakeGroupRepo) DetachStreetSnapImage(_ context.Context, _ uint32, _ uint32) error {
if f.attachFn != nil {
return f.attachFn(0, 0, nil)
}
@ -50,17 +50,17 @@ func newGroupService(f *fakeGroupRepo) ReviewService {
// TestStreetGroupDetailExposesGrouping 详情必须输出可折叠分组:主图各成一组,副图归入主图。
func TestStreetGroupDetailExposesGrouping(t *testing.T) {
repo := &fakeGroupRepo{
detail: &model.StreetSnapDraft{ID: 7, Title: "T", Year: 2026, City: "Beijing", Status: model.DraftStatusPending},
images: []model.StreetSnapDraftImage{
detail: &model.StreetSnap{ID: 7, Title: "T", Year: 2026, City: "Beijing", Status: model.StatusPending},
images: []model.StreetSnapImage{
{ID: 1, Image: "main.jpg", Name: "main", SortOrder: 1, IsDetail: 0, ParentImageID: 0},
{ID: 2, Image: "det.jpg", Name: "det", SortOrder: 2, IsDetail: 1, ParentImageID: 1},
{ID: 3, Image: "solo.jpg", Name: "solo", SortOrder: 3, IsDetail: 0, ParentImageID: 0},
},
}
svc := newGroupService(repo)
v, err := svc.DraftDetail(context.Background(), dto.IngestKindStreet, 7)
v, err := svc.RecordDetail(context.Background(), dto.IngestKindStreet, 7)
if err != nil {
t.Fatalf("DraftDetail 失败: %v", err)
t.Fatalf("RecordDetail 失败: %v", err)
}
if len(v.Images) != 3 {
t.Fatalf("Images 应保留扁平 3 张,实际 %d", len(v.Images))
@ -85,20 +85,20 @@ func TestStreetGroupDetailExposesGrouping(t *testing.T) {
// TestStreetGroupAttachDelegates 并入必须透传参数到仓储。
func TestStreetGroupAttachDelegates(t *testing.T) {
var got struct {
draftID uint32
mainID uint32
imgIDs []uint32
snapID uint32
mainID uint32
imgIDs []uint32
}
repo := &fakeGroupRepo{attachFn: func(draftID, mainID uint32, imgIDs []uint32) error {
got.draftID, got.mainID, got.imgIDs = draftID, mainID, imgIDs
repo := &fakeGroupRepo{attachFn: func(snapID, mainID uint32, imgIDs []uint32) error {
got.snapID, got.mainID, got.imgIDs = snapID, mainID, imgIDs
return nil
}}
svc := newGroupService(repo)
if err := svc.AttachDraftImages(context.Background(), dto.IngestKindStreet, 7, 1, []uint32{2, 3}); err != nil {
t.Fatalf("AttachDraftImages 失败: %v", err)
if err := svc.AttachImages(context.Background(), dto.IngestKindStreet, 7, 1, []uint32{2, 3}); err != nil {
t.Fatalf("AttachImages 失败: %v", err)
}
if got.draftID != 7 || got.mainID != 1 || len(got.imgIDs) != 2 {
t.Fatalf("参数透传错误: draftID=%d mainID=%d imgIDs=%v", got.draftID, got.mainID, got.imgIDs)
if got.snapID != 7 || got.mainID != 1 || len(got.imgIDs) != 2 {
t.Fatalf("参数透传错误: snapID=%d mainID=%d imgIDs=%v", got.snapID, got.mainID, got.imgIDs)
}
}
@ -106,20 +106,20 @@ func TestStreetGroupAttachDelegates(t *testing.T) {
func TestStreetGroupNonStreetRejected(t *testing.T) {
repo := &fakeGroupRepo{}
svc := newGroupService(repo)
if err := svc.AttachDraftImages(context.Background(), dto.IngestKindRunway, 7, 1, []uint32{2}); !errors.Is(err, ErrInvalidImageGroup) {
if err := svc.AttachImages(context.Background(), dto.IngestKindRunway, 7, 1, []uint32{2}); !errors.Is(err, ErrInvalidImageGroup) {
t.Fatalf("走秀并入应返回 ErrInvalidImageGroup,实际 %v", err)
}
}
// TestStreetGroupPreventCrossDraft 仓储拦截跨草稿主图后,service 翻成中文用户错误。
func TestStreetGroupPreventCrossDraft(t *testing.T) {
// TestStreetGroupPreventCrossRecord 仓储拦截跨记录主图后,service 翻成中文用户错误。
func TestStreetGroupPreventCrossRecord(t *testing.T) {
repo := &fakeGroupRepo{attachFn: func(_, _ uint32, _ []uint32) error {
return repository.ErrInvalidImageGroup
}}
svc := newGroupService(repo)
err := svc.AttachDraftImages(context.Background(), dto.IngestKindStreet, 7, 1, []uint32{2, 3})
err := svc.AttachImages(context.Background(), dto.IngestKindStreet, 7, 1, []uint32{2, 3})
if err == nil {
t.Fatal("跨草稿应报错")
t.Fatal("跨记录应报错")
}
if err.Error() != "主图无效:它必须属于本草稿、未被删除,且自身是主图" {
t.Fatalf("错误文案不符: %q", err.Error())