52 lines
1.4 KiB
Go
52 lines
1.4 KiB
Go
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)
|
|
}
|
|
})
|
|
}
|