refac: reamaining auth surface rewrite, T0

This commit is contained in:
fsylvain committed 2026-09-24 05:11:49 +02:00
1 parent 6d510d2805
commit aa865af2e9
50 files changed
+3723 -149

No files matched your search

+51
View File
@@ -0,0 +1,51 @@
package test
import (
"RenewCMS/internal/domain/user"
"RenewCMS/internal/infrastructure/useCases"
"errors"
"testing"
)
func TestCancelRegistrationUseCase(t *testing.T) {
t.Run("The use case deletes an unverified user, independently of any handler", func(t *testing.T) {
repo := newMockUserRepo()
repo.users[3] = user.User{ID: 3, IsVerified: false}
uc := useCases.NewCancelRegistrationUseCase(repo)
err := uc.CancelRegistration(3)
if err != nil {
t.Fatalf("expected no error, got %v", err)
}
if _, ok := repo.users[3]; ok {
t.Errorf("expected user 3 to be removed from the repository")
}
})
t.Run("The use case refuses to delete an already-verified user, independently of any handler", func(t *testing.T) {
repo := newMockUserRepo()
repo.users[3] = user.User{ID: 3, IsVerified: true}
uc := useCases.NewCancelRegistrationUseCase(repo)
err := uc.CancelRegistration(3)
if !errors.Is(err, user.ErrAlreadyVerified) {
t.Fatalf("expected user.ErrAlreadyVerified, got %v", err)
}
if _, ok := repo.users[3]; !ok {
t.Errorf("expected user 3 to still be present in the repository")
}
})
t.Run("The use case reports an unknown user, independently of any handler", func(t *testing.T) {
repo := newMockUserRepo()
uc := useCases.NewCancelRegistrationUseCase(repo)
err := uc.CancelRegistration(42)
if !errors.Is(err, user.ErrUserNotFound) {
t.Fatalf("expected user.ErrUserNotFound, got %v", err)
}
})
}