feat(API): media library

This commit is contained in:
fsylvain committed 2026-09-30 18:35:28 +02:00
1 parent 95ae043d3e
commit 0d99544579
65 files changed
+3992 -1530

No files matched your search

+8 -30
View File
@@ -3,7 +3,6 @@ package test
import (
"RenewCMS/api/handlers/article"
domainArticle "RenewCMS/internal/domain/article"
domainImage "RenewCMS/internal/domain/image"
"RenewCMS/internal/infrastructure/useCases"
"encoding/json"
"net/http"
@@ -24,7 +23,7 @@ func newArticlesListRouter(articleRepo *mockArticleRepo, token *jwtauth.JWTAuth)
useCases.NewCreateArticleUseCase(articleRepo),
useCases.NewGetArticleUseCase(articleRepo),
useCases.NewListArticlesUseCase(articleRepo),
useCases.NewDeleteArticleUseCase(articleRepo, newMockImageRepo()),
useCases.NewDeleteArticleUseCase(articleRepo),
useCases.NewUpdateArticleUseCase(articleRepo),
getUserUseCase,
)
@@ -43,16 +42,9 @@ func TestArticlesListHttp(t *testing.T) {
validator.InitValidator()
token := jwtauth.New("HS256", []byte("test-secret"), nil)
t.Run("GET /v1/article/ returns each article's images array populated", func(t *testing.T) {
t.Run("GET /v1/article/ items carry no images field now that images belong to the library", func(t *testing.T) {
repo := newMockArticleRepo()
repo.articles[4] = domainArticle.Article{
ID: 4,
Title: "Winter checklist for timber windows",
Images: []*domainImage.Image{
{ID: 10, ArticleID: 4},
{ID: 11, ArticleID: 4},
},
}
repo.articles[4] = domainArticle.Article{ID: 4, Title: "Winter checklist for timber windows"}
router := newArticlesListRouter(repo, token)
req := httptest.NewRequest(http.MethodGet, "/v1/article/", nil)
@@ -64,29 +56,15 @@ func TestArticlesListHttp(t *testing.T) {
t.Fatalf("expected status 200, got %d", rec.Code)
}
var got []domainArticle.Article
var got []map[string]any
if err := json.Unmarshal(rec.Body.Bytes(), &got); err != nil {
t.Fatalf("failed to decode response: %v", err)
}
var found *domainArticle.Article
for i := range got {
if got[i].ID == 4 {
found = &got[i]
}
if len(got) != 1 {
t.Fatalf("expected 1 article, got %d", len(got))
}
if found == nil {
t.Fatalf("expected article id 4 in response, got %v", got)
}
if len(found.Images) != 2 {
t.Fatalf("expected 2 images, got %d", len(found.Images))
}
ids := map[uint32]bool{}
for _, img := range found.Images {
ids[img.ID] = true
}
if !ids[10] || !ids[11] {
t.Errorf("expected images 10 and 11, got %v", found.Images)
if _, present := got[0]["images"]; present {
t.Errorf("expected no images field, got %v", got[0]["images"])
}
})
}