refac: repository updates, image attachment and deletes report the domain not-found error for an unknown id, the same for articles, users and images, and the test fakes stop returning GORM errors

This commit is contained in:
fsylvain committed 2026-09-23 22:09:06 +02:00
1 parent 4278d96882
commit 6a2ca07b66
14 files changed
+553 -66

No files matched your search

+7 -6
View File
@@ -7,8 +7,6 @@ import (
"errors"
"sort"
"testing"
"gorm.io/gorm"
)
type mockArticleRepo struct {
@@ -99,7 +97,7 @@ func (m *mockArticleRepo) UpdateBody(id uint32, body string) (article.Article, e
}
a, ok := m.articles[id]
if !ok {
return article.Article{}, gorm.ErrRecordNotFound
return article.Article{}, article.ErrArticleNotFound
}
a.Body = body
m.articles[id] = a
@@ -112,7 +110,7 @@ func (m *mockArticleRepo) UpdateIsOnline(id uint32, isOnline bool) (article.Arti
}
a, ok := m.articles[id]
if !ok {
return article.Article{}, gorm.ErrRecordNotFound
return article.Article{}, article.ErrArticleNotFound
}
a.IsOnline = isOnline
m.articles[id] = a
@@ -123,6 +121,9 @@ func (m *mockArticleRepo) Delete(id uint32) error {
if err := m.fail.trigger("Delete"); err != nil {
return err
}
if _, ok := m.articles[id]; !ok {
return article.ErrArticleNotFound
}
delete(m.articles, id)
return nil
}
@@ -133,11 +134,11 @@ func (m *mockArticleRepo) AddImage(articleId uint32, imageId uint32) error {
}
a, ok := m.articles[articleId]
if !ok {
return gorm.ErrRecordNotFound
return article.ErrArticleNotFound
}
img, ok := m.images[imageId]
if !ok {
return gorm.ErrRecordNotFound
return imageDomain.ErrImageNotFound
}
a.Images = append(a.Images, img)
m.articles[articleId] = a