38 lines
1.2 KiB
Go
38 lines
1.2 KiB
Go
package test
|
|
|
|
import (
|
|
domainArticle "RenewCMS/internal/domain/article"
|
|
"RenewCMS/internal/infrastructure/useCases"
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
type mediaOrderRecordingArticleRepo struct {
|
|
*mockArticleRepo
|
|
updated []uint32
|
|
}
|
|
|
|
func (r *mediaOrderRecordingArticleRepo) UpdateBody(id uint32, body string) (domainArticle.Article, error) {
|
|
r.updated = append(r.updated, id)
|
|
return r.mockArticleRepo.UpdateBody(id, body)
|
|
}
|
|
|
|
func TestMediaMergeRewritesArticlesInIdOrder(t *testing.T) {
|
|
env := newMediaEnv(t)
|
|
env.seedImage(2, "floorboards.jpg", 20, "image/jpeg", 3, 2, hashB, 1)
|
|
env.seedImage(3, "floorboards-copy.jpg", 20, "image/jpeg", 3, 2, hashB, 2)
|
|
for id := uint32(1); id <= 8; id++ {
|
|
env.seedArticle(id, "Article", true, env.urlOf(3))
|
|
}
|
|
recorder := &mediaOrderRecordingArticleRepo{mockArticleRepo: env.articles}
|
|
uc := useCases.NewMergeMediaUseCase(env.images, recorder, env.storage, newMockVariantFileRepo(), discardRecorder, plainSites(), plainAuthors())
|
|
|
|
if _, err := uc.Merge(testCtx, 2, []uint32{3}); err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
|
|
if want := []uint32{1, 2, 3, 4, 5, 6, 7, 8}; !reflect.DeepEqual(recorder.updated, want) {
|
|
t.Errorf("expected updates in id order %v, got %v", want, recorder.updated)
|
|
}
|
|
}
|