chore: extract mail to it's own service #181
Some checks failed
Build Docker Image / Explore-Gitea-Actions (push) Failing after 45s

This commit is contained in:
2024-09-27 23:21:37 +02:00
parent a70138f2f7
commit fe7178ea03
4 changed files with 18 additions and 5 deletions

View File

@@ -76,7 +76,7 @@ func (handler HandlerAuthImpl) handleSignIn() http.HandlerFunc {
http.Error(w, "Invalid email or password", http.StatusUnauthorized)
} else {
utils.LogError("Error signing in", err)
http.Error(w, "An error occurred", http.StatusInternalServerError)
http.Error(w, "InternalServerErr", http.StatusInternalServerError)
}
return
}

11
handler/auth_test.go Normal file
View File

@@ -0,0 +1,11 @@
package handler
import (
"testing"
)
func TestHandleSignIn(t *testing.T) {
t.Parallel()
t.Run("should signIn and return session cookie", func(t *testing.T) {
})
}

View File

@@ -400,6 +400,7 @@ func HandleDeleteAccountComp(db *sql.DB, serverSettings *types.ServerSettings) h
return
}
mailService := NewMailService(serverSettings)
go mailService.SendMail(user.Email, "Account deleted", "Your account has been deleted")
utils.DoRedirect(w, r, "/")
@@ -579,6 +580,7 @@ func HandleResetPasswordComp(db *sql.DB, serverSettings *types.ServerSettings) h
utils.TriggerToast(w, r, "error", "Internal Server Error")
return
}
mailService := NewMailService(serverSettings)
mailService.SendMail(email, "Reset Password", mail.String())
}

View File

@@ -38,7 +38,7 @@ func TestSignIn(t *testing.T) {
),
err: nil,
}
underTest := NewServiceAuthImpl(stub)
underTest := NewServiceAuthImpl(stub, NewServiceMailStub())
actualUser, err := underTest.SignIn("test@test.de", "password")
if err != nil {
@@ -71,7 +71,7 @@ func TestSignIn(t *testing.T) {
),
err: nil,
}
underTest := NewServiceAuthImpl(stub)
underTest := NewServiceAuthImpl(stub, NewServiceMailStub())
_, err := underTest.SignIn("test@test.de", "wrong password")
if err != ErrInvaidCredentials {
@@ -84,7 +84,7 @@ func TestSignIn(t *testing.T) {
user: nil,
err: db.ErrUserNotFound,
}
underTest := NewServiceAuthImpl(stub)
underTest := NewServiceAuthImpl(stub, NewServiceMailStub())
_, err := underTest.SignIn("test", "test")
if err != ErrInvaidCredentials {
@@ -97,7 +97,7 @@ func TestSignIn(t *testing.T) {
user: nil,
err: errors.New("Some error"),
}
underTest := NewServiceAuthImpl(stub)
underTest := NewServiceAuthImpl(stub, NewServiceMailStub())
_, err := underTest.SignIn("test", "test")
if err != types.ErrInternal {