refac: stale test entries, failing web tests, Postgre backup bug, Hardcoded MySQL table count, Stale Postgre connection in test, own-scope visibility filter, GetAll ignoring its error, JSON tags in use-case types, 31 copies of DESKTOP_QUERY, ProfileView endpoint paths

This commit is contained in:
Florian Sylvain committed 2026-10-28 17:54:10 +01:00
1 parent efecdee200
commit 5d6f378fce
87 files changed
+696 -373

No files matched your search

+74
View File
@@ -0,0 +1,74 @@
package test
import (
"RenewCMS/internal/infrastructure/useCases"
"errors"
"net/http"
"testing"
"time"
)
func TestGetAllFailuresReachTheCaller(t *testing.T) {
boom := errors.New("storage down")
t.Run("registration status answers 500 instead of reporting open", func(t *testing.T) {
userRepo := newMockUserRepo()
userRepo.fail.failNextWith("GetAll", boom)
router, _ := newRegistrationStatusRouter(userRepo, newMockMailRepo())
rec := registrationStatusRequest(router, nil)
if rec.Code != http.StatusInternalServerError {
t.Errorf("status = %d, want 500", rec.Code)
}
})
t.Run("IsRegistrationOpen returns the error", func(t *testing.T) {
userRepo := newMockUserRepo()
userRepo.fail.failNextWith("GetAll", boom)
uc := useCases.NewCreateUserUseCase(userRepo, newSeededMockRoleRepo(), &stubHasher{}, newMockMailRepo(), "https://cms.example.com", discardRecorder)
if _, err := uc.IsRegistrationOpen(); !errors.Is(err, boom) {
t.Errorf("err = %v, want %v", err, boom)
}
})
t.Run("GetInvite returns the error instead of an invalid invite", func(t *testing.T) {
invites := newInviteFakeRepo()
invites.fail.failNextWith("GetAll", boom)
uc := useCases.NewGetInviteUseCase(invites, &stubHasher{})
if _, err := uc.GetInvite("code"); !errors.Is(err, boom) {
t.Errorf("err = %v, want %v", err, boom)
}
})
t.Run("ListUsers returns the error", func(t *testing.T) {
userRepo := newMockUserRepo()
userRepo.fail.failNextWith("GetAll", boom)
if _, err := useCases.NewListUsersUseCase(userRepo).ListUsers(); !errors.Is(err, boom) {
t.Errorf("err = %v, want %v", err, boom)
}
})
t.Run("retention stops on a user listing failure", func(t *testing.T) {
userRepo := newMockUserRepo()
userRepo.fail.failNextWith("GetAll", boom)
uc := useCases.NewEnforceRetentionUseCase(userRepo, newInviteFakeRepo(), &memorySessionRepo{})
if _, err := uc.Tick(time.Now()); !errors.Is(err, boom) {
t.Errorf("err = %v, want %v", err, boom)
}
})
t.Run("retention stops on an invite listing failure", func(t *testing.T) {
invites := newInviteFakeRepo()
invites.fail.failNextWith("GetAll", boom)
uc := useCases.NewEnforceRetentionUseCase(newMockUserRepo(), invites, &memorySessionRepo{})
if _, err := uc.Tick(time.Now()); !errors.Is(err, boom) {
t.Errorf("err = %v, want %v", err, boom)
}
})
}