refac: missing user or article is reported with a domain not-found error instead of a raw GORM error, and the API answers 404 for it

This commit is contained in:
fsylvain committed 2026-09-23 18:55:05 +02:00
1 parent 7c57173497
commit 8460a078e3
13 files changed
+426 -32

No files matched your search

+12 -15
View File
@@ -111,8 +111,8 @@ func TestGetArticleAndGetOnlineArticle(t *testing.T) {
repo := newRepo()
uc := useCases.NewGetArticleUseCase(repo)
_, err := uc.GetArticle(9)
if !errors.Is(err, gorm.ErrRecordNotFound) {
t.Errorf("expected gorm.ErrRecordNotFound, got %v", err)
if !errors.Is(err, article.ErrArticleNotFound) {
t.Errorf("expected article.ErrArticleNotFound, got %v", err)
}
})
@@ -141,11 +141,8 @@ func TestGetArticleAndGetOnlineArticle(t *testing.T) {
repo := newRepo()
uc := useCases.NewGetArticleUseCase(repo)
_, err := uc.GetOnlineArticle(9)
if !errors.Is(err, gorm.ErrRecordNotFound) {
t.Errorf("expected gorm.ErrRecordNotFound, got %v", err)
}
if errors.Is(err, article.ErrArticleNotFound) {
t.Errorf("expected the raw not-found error, not article.ErrArticleNotFound")
if !errors.Is(err, article.ErrArticleNotFound) {
t.Errorf("expected article.ErrArticleNotFound, got %v", err)
}
})
}
@@ -173,8 +170,8 @@ func TestGetArticleByNameDelegatesVerbatim(t *testing.T) {
repo := newRepo()
uc := useCases.NewGetArticleUseCase(repo)
_, err := uc.GetArticleByName("Unknown Title")
if !errors.Is(err, gorm.ErrRecordNotFound) {
t.Errorf("expected gorm.ErrRecordNotFound, got %v", err)
if !errors.Is(err, article.ErrArticleNotFound) {
t.Errorf("expected article.ErrArticleNotFound, got %v", err)
}
})
}
@@ -519,8 +516,8 @@ func TestGetUserReadsByIdUsernameOrEmail(t *testing.T) {
repo := newRepo()
uc := useCases.NewGetUserUseCase(repo)
_, err := uc.GetUser(9)
if !errors.Is(err, gorm.ErrRecordNotFound) {
t.Errorf("expected gorm.ErrRecordNotFound, got %v", err)
if !errors.Is(err, user.ErrUserNotFound) {
t.Errorf("expected user.ErrUserNotFound, got %v", err)
}
})
@@ -540,8 +537,8 @@ func TestGetUserReadsByIdUsernameOrEmail(t *testing.T) {
repo := newRepo()
uc := useCases.NewGetUserUseCase(repo)
_, err := uc.GetUserByUsername("bob")
if !errors.Is(err, gorm.ErrRecordNotFound) {
t.Errorf("expected gorm.ErrRecordNotFound, got %v", err)
if !errors.Is(err, user.ErrUserNotFound) {
t.Errorf("expected user.ErrUserNotFound, got %v", err)
}
})
@@ -561,8 +558,8 @@ func TestGetUserReadsByIdUsernameOrEmail(t *testing.T) {
repo := newRepo()
uc := useCases.NewGetUserUseCase(repo)
_, err := uc.GetUserByEmail("bob@example.com")
if !errors.Is(err, gorm.ErrRecordNotFound) {
t.Errorf("expected gorm.ErrRecordNotFound, got %v", err)
if !errors.Is(err, user.ErrUserNotFound) {
t.Errorf("expected user.ErrUserNotFound, got %v", err)
}
})
}