feat: integration v2 and API key PART 1/3

This commit is contained in:
fsylvain committed 2026-10-04 21:56:14 +02:00
1 parent 7e9bd9ba30
commit 844842fdae
40 files changed
+3782 -64

No files matched your search

+9 -9
View File
@@ -22,7 +22,7 @@ func TestResetPasswordUseCase(t *testing.T) {
t.Run("The use case itself sets the password and clears the code in one write, independently of any handler", func(t *testing.T) {
repo := newRepo(time.Now().Add(time.Hour))
uc := useCases.NewResetPasswordUseCase(repo, &stubHasher{})
uc := useCases.NewResetPasswordUseCase(repo, &stubHasher{}, newMockAPIKeyRepo(), time.Now)
err := uc.ResetPassword("alice@example.com", "reset-code-1", "newpassword1")
@@ -49,7 +49,7 @@ func TestResetPasswordUseCase(t *testing.T) {
PasswordResetCode: "hashed:reset-code-1",
PasswordResetExpiration: time.Now().Add(time.Hour),
}
uc := useCases.NewResetPasswordUseCase(repo, &stubHasher{})
uc := useCases.NewResetPasswordUseCase(repo, &stubHasher{}, newMockAPIKeyRepo(), time.Now)
err := uc.ResetPassword("alice@example.com", "reset-code-1", "newpassword1")
@@ -63,7 +63,7 @@ func TestResetPasswordUseCase(t *testing.T) {
t.Run("The use case rejects a wrong code without touching the repository's ResetPassword method", func(t *testing.T) {
repo := newRepo(time.Now().Add(time.Hour))
uc := useCases.NewResetPasswordUseCase(repo, &stubHasher{})
uc := useCases.NewResetPasswordUseCase(repo, &stubHasher{}, newMockAPIKeyRepo(), time.Now)
err := uc.ResetPassword("alice@example.com", "wrong-code", "newpassword1")
@@ -77,7 +77,7 @@ func TestResetPasswordUseCase(t *testing.T) {
t.Run("The use case rejects an expired code without touching the repository's ResetPassword method", func(t *testing.T) {
repo := newRepo(time.Now().Add(-time.Hour))
uc := useCases.NewResetPasswordUseCase(repo, &stubHasher{})
uc := useCases.NewResetPasswordUseCase(repo, &stubHasher{}, newMockAPIKeyRepo(), time.Now)
err := uc.ResetPassword("alice@example.com", "reset-code-1", "newpassword1")
@@ -91,7 +91,7 @@ func TestResetPasswordUseCase(t *testing.T) {
t.Run("The use case treats an unknown email the same as a wrong code", func(t *testing.T) {
repo := newMockUserRepo()
uc := useCases.NewResetPasswordUseCase(repo, &stubHasher{})
uc := useCases.NewResetPasswordUseCase(repo, &stubHasher{}, newMockAPIKeyRepo(), time.Now)
err := uc.ResetPassword("nobody@example.com", "any-code", "newpassword1")
@@ -107,7 +107,7 @@ func TestResetPasswordUseCase(t *testing.T) {
repo := newMockUserRepo()
repo.users[3] = user.User{ID: 3, Email: "alice@example.com", PasswordResetCode: ""}
hasher := &stubHasher{}
uc := useCases.NewResetPasswordUseCase(repo, hasher)
uc := useCases.NewResetPasswordUseCase(repo, hasher, newMockAPIKeyRepo(), time.Now)
err := uc.ResetPassword("alice@example.com", "anything", "newpassword1")
@@ -125,7 +125,7 @@ func TestResetPasswordUseCase(t *testing.T) {
t.Run("The use case treats any GetByEmail failure, not just not-found, as an invalid code", func(t *testing.T) {
repo := newRepo(time.Now().Add(time.Hour))
repo.fail.failNextWith("GetByEmail", errors.New("db is down"))
uc := useCases.NewResetPasswordUseCase(repo, &stubHasher{})
uc := useCases.NewResetPasswordUseCase(repo, &stubHasher{}, newMockAPIKeyRepo(), time.Now)
err := uc.ResetPassword("alice@example.com", "reset-code-1", "newpassword1")
@@ -140,7 +140,7 @@ func TestResetPasswordUseCase(t *testing.T) {
t.Run("A hashing failure propagates and the repository's ResetPassword method is never called", func(t *testing.T) {
repo := newRepo(time.Now().Add(time.Hour))
hashErr := errors.New("hash blew up")
uc := useCases.NewResetPasswordUseCase(repo, &stubHasher{hashErr: hashErr})
uc := useCases.NewResetPasswordUseCase(repo, &stubHasher{hashErr: hashErr}, newMockAPIKeyRepo(), time.Now)
err := uc.ResetPassword("alice@example.com", "reset-code-1", "newpassword1")
@@ -155,7 +155,7 @@ func TestResetPasswordUseCase(t *testing.T) {
t.Run("A failure in the repository's ResetPassword method propagates", func(t *testing.T) {
repo := newRepo(time.Now().Add(time.Hour))
repo.fail.failNext("ResetPassword")
uc := useCases.NewResetPasswordUseCase(repo, &stubHasher{})
uc := useCases.NewResetPasswordUseCase(repo, &stubHasher{}, newMockAPIKeyRepo(), time.Now)
err := uc.ResetPassword("alice@example.com", "reset-code-1", "newpassword1")