refac: debt on role backend

This commit is contained in:
Florian Sylvain committed 2026-10-26 23:34:35 +01:00
1 parent de142f6c5f
commit a043f7f41a
130 files changed
+3591 -512

No files matched your search

+9 -4
View File
@@ -24,6 +24,7 @@ type mockArticleRepo struct {
credits map[uint32][]uint32
authors *mockAuthorRepo
reportSlugRace bool
raceCreates int
createAlwaysRaces bool
afterFindByBody func()
updateBodyIDs []uint32
@@ -298,6 +299,10 @@ func (m *mockArticleRepo) Create(a article.Article) (article.Article, error) {
return article.Article{}, err
}
if m.createAlwaysRaces {
m.raceCreates++
if m.raceCreates > 100 {
return article.Article{}, errors.New("create budget exceeded")
}
return article.Article{}, article.ErrSlugTaken
}
if m.slugUsedOn(a.SiteID, a.Slug, 0) {
@@ -443,7 +448,7 @@ func TestCreateArticle(t *testing.T) {
uc := useCases.NewCreateArticleUseCase(repo, &fakeBodyRenderer{}, discardRecorder, plainSites(), plainAuthors())
t.Run("Valid Title", func(t *testing.T) {
cmd := useCases.CreateArticleCommand{Title: "Valid Title", Body: "Content"}
cmd := useCases.CreateArticleCommand{Caller: ownerCaller(1), Title: "Valid Title", Body: "Content"}
res, err := uc.CreateArticle(testCtx, cmd)
if err != nil {
t.Fatalf("Expected no error, got %v", err)
@@ -454,7 +459,7 @@ func TestCreateArticle(t *testing.T) {
})
t.Run("Short Title", func(t *testing.T) {
cmd := useCases.CreateArticleCommand{Title: "Ab", Body: "Content"}
cmd := useCases.CreateArticleCommand{Caller: ownerCaller(1), Title: "Ab", Body: "Content"}
_, err := uc.CreateArticle(testCtx, cmd)
if !errors.Is(err, article.ErrInvalidTitle) {
t.Errorf("Expected ErrInvalidTitle")
@@ -469,14 +474,14 @@ func TestGetOnlineArticle(t *testing.T) {
uc := useCases.NewGetArticleUseCase(repo, &fakeBodyRenderer{})
t.Run("Article Online", func(t *testing.T) {
_, err := uc.GetOnlineArticle(1, article.BodyFormatHTML)
_, err := uc.GetArticle(1, article.BodyFormatHTML, useCases.ContentCaller{})
if err != nil {
t.Errorf("Expected article to be found")
}
})
t.Run("Article Offline", func(t *testing.T) {
_, err := uc.GetOnlineArticle(2, article.BodyFormatHTML)
_, err := uc.GetArticle(2, article.BodyFormatHTML, useCases.ContentCaller{})
if !errors.Is(err, article.ErrArticleNotFound) {
t.Errorf("Offline article should return not found")
}