feat: activity log backend foundation
This commit is contained in:
1 parent
8907bb49fe
commit
50b1649965
74 files changed
+5949
-239
No files matched your search
+18
-18
@@ -22,9 +22,9 @@ 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{}, newMockAPIKeyRepo(), time.Now)
|
||||
uc := useCases.NewResetPasswordUseCase(repo, &stubHasher{}, newMockAPIKeyRepo(), time.Now, discardRecorder)
|
||||
|
||||
err := uc.ResetPassword("alice@example.com", "reset-code-1", "newpassword1")
|
||||
err := uc.ResetPassword(testCtx, "alice@example.com", "reset-code-1", "newpassword1")
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("expected no error, got %v", err)
|
||||
@@ -49,9 +49,9 @@ func TestResetPasswordUseCase(t *testing.T) {
|
||||
PasswordResetCode: "hashed:reset-code-1",
|
||||
PasswordResetExpiration: time.Now().Add(time.Hour),
|
||||
}
|
||||
uc := useCases.NewResetPasswordUseCase(repo, &stubHasher{}, newMockAPIKeyRepo(), time.Now)
|
||||
uc := useCases.NewResetPasswordUseCase(repo, &stubHasher{}, newMockAPIKeyRepo(), time.Now, discardRecorder)
|
||||
|
||||
err := uc.ResetPassword("alice@example.com", "reset-code-1", "newpassword1")
|
||||
err := uc.ResetPassword(testCtx, "alice@example.com", "reset-code-1", "newpassword1")
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("expected no error, got %v", err)
|
||||
@@ -63,9 +63,9 @@ 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{}, newMockAPIKeyRepo(), time.Now)
|
||||
uc := useCases.NewResetPasswordUseCase(repo, &stubHasher{}, newMockAPIKeyRepo(), time.Now, discardRecorder)
|
||||
|
||||
err := uc.ResetPassword("alice@example.com", "wrong-code", "newpassword1")
|
||||
err := uc.ResetPassword(testCtx, "alice@example.com", "wrong-code", "newpassword1")
|
||||
|
||||
if !errors.Is(err, user.ErrInvalidPasswordResetCode) {
|
||||
t.Errorf("expected user.ErrInvalidPasswordResetCode, got %v", err)
|
||||
@@ -77,9 +77,9 @@ 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{}, newMockAPIKeyRepo(), time.Now)
|
||||
uc := useCases.NewResetPasswordUseCase(repo, &stubHasher{}, newMockAPIKeyRepo(), time.Now, discardRecorder)
|
||||
|
||||
err := uc.ResetPassword("alice@example.com", "reset-code-1", "newpassword1")
|
||||
err := uc.ResetPassword(testCtx, "alice@example.com", "reset-code-1", "newpassword1")
|
||||
|
||||
if !errors.Is(err, user.ErrPasswordResetCodeExpired) {
|
||||
t.Errorf("expected user.ErrPasswordResetCodeExpired, got %v", err)
|
||||
@@ -91,9 +91,9 @@ 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{}, newMockAPIKeyRepo(), time.Now)
|
||||
uc := useCases.NewResetPasswordUseCase(repo, &stubHasher{}, newMockAPIKeyRepo(), time.Now, discardRecorder)
|
||||
|
||||
err := uc.ResetPassword("nobody@example.com", "any-code", "newpassword1")
|
||||
err := uc.ResetPassword(testCtx, "nobody@example.com", "any-code", "newpassword1")
|
||||
|
||||
if !errors.Is(err, user.ErrInvalidPasswordResetCode) {
|
||||
t.Errorf("expected user.ErrInvalidPasswordResetCode, got %v", err)
|
||||
@@ -107,9 +107,9 @@ 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, newMockAPIKeyRepo(), time.Now)
|
||||
uc := useCases.NewResetPasswordUseCase(repo, hasher, newMockAPIKeyRepo(), time.Now, discardRecorder)
|
||||
|
||||
err := uc.ResetPassword("alice@example.com", "anything", "newpassword1")
|
||||
err := uc.ResetPassword(testCtx, "alice@example.com", "anything", "newpassword1")
|
||||
|
||||
if !errors.Is(err, user.ErrInvalidPasswordResetCode) {
|
||||
t.Errorf("expected user.ErrInvalidPasswordResetCode, got %v", err)
|
||||
@@ -125,9 +125,9 @@ 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{}, newMockAPIKeyRepo(), time.Now)
|
||||
uc := useCases.NewResetPasswordUseCase(repo, &stubHasher{}, newMockAPIKeyRepo(), time.Now, discardRecorder)
|
||||
|
||||
err := uc.ResetPassword("alice@example.com", "reset-code-1", "newpassword1")
|
||||
err := uc.ResetPassword(testCtx, "alice@example.com", "reset-code-1", "newpassword1")
|
||||
|
||||
if !errors.Is(err, user.ErrInvalidPasswordResetCode) {
|
||||
t.Errorf("expected user.ErrInvalidPasswordResetCode, got %v", err)
|
||||
@@ -140,9 +140,9 @@ 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}, newMockAPIKeyRepo(), time.Now)
|
||||
uc := useCases.NewResetPasswordUseCase(repo, &stubHasher{hashErr: hashErr}, newMockAPIKeyRepo(), time.Now, discardRecorder)
|
||||
|
||||
err := uc.ResetPassword("alice@example.com", "reset-code-1", "newpassword1")
|
||||
err := uc.ResetPassword(testCtx, "alice@example.com", "reset-code-1", "newpassword1")
|
||||
|
||||
if !errors.Is(err, hashErr) {
|
||||
t.Errorf("expected %v, got %v", hashErr, err)
|
||||
@@ -155,9 +155,9 @@ 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{}, newMockAPIKeyRepo(), time.Now)
|
||||
uc := useCases.NewResetPasswordUseCase(repo, &stubHasher{}, newMockAPIKeyRepo(), time.Now, discardRecorder)
|
||||
|
||||
err := uc.ResetPassword("alice@example.com", "reset-code-1", "newpassword1")
|
||||
err := uc.ResetPassword(testCtx, "alice@example.com", "reset-code-1", "newpassword1")
|
||||
|
||||
if !errors.Is(err, errRepositoryFailure) {
|
||||
t.Errorf("expected %v, got %v", errRepositoryFailure, err)
|
||||
|
||||
Reference in new issue
Block a user