fix: missing service tests #181
This commit was merged in pull request #202.
This commit is contained in:
@@ -47,24 +47,24 @@ func NewUser(user *db.User) *User {
|
||||
type ServiceAuth interface {
|
||||
SignIn(email string, password string) (*User, error)
|
||||
SignUp(email string, password string) (*User, error)
|
||||
SendVerificationMail(user *User)
|
||||
SendVerificationMail(userId uuid.UUID, email string)
|
||||
}
|
||||
|
||||
type ServiceAuthImpl struct {
|
||||
dbAuth db.DbAuth
|
||||
randomGenerator RandomGenerator
|
||||
clock Clock
|
||||
serverSettings *types.ServerSettings
|
||||
mailService MailService
|
||||
serverSettings *types.ServerSettings
|
||||
}
|
||||
|
||||
func NewServiceAuthImpl(dbAuth db.DbAuth, randomGenerator RandomGenerator, clock Clock, serverSettings *types.ServerSettings) *ServiceAuthImpl {
|
||||
func NewServiceAuthImpl(dbAuth db.DbAuth, randomGenerator RandomGenerator, clock Clock, mailService MailService, serverSettings *types.ServerSettings) *ServiceAuthImpl {
|
||||
return &ServiceAuthImpl{
|
||||
dbAuth: dbAuth,
|
||||
randomGenerator: randomGenerator,
|
||||
clock: clock,
|
||||
mailService: mailService,
|
||||
serverSettings: serverSettings,
|
||||
mailService: NewMailService(serverSettings),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,10 +123,10 @@ func (service ServiceAuthImpl) SignUp(email string, password string) (*User, err
|
||||
return NewUser(dbUser), nil
|
||||
}
|
||||
|
||||
func (service ServiceAuthImpl) SendVerificationMail(user *User) {
|
||||
func (service ServiceAuthImpl) SendVerificationMail(userId uuid.UUID, email string) {
|
||||
var token string
|
||||
|
||||
token, err := service.dbAuth.GetEmailVerificationToken(user.Id)
|
||||
token, err := service.dbAuth.GetEmailVerificationToken(userId)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -137,7 +137,7 @@ func (service ServiceAuthImpl) SendVerificationMail(user *User) {
|
||||
return
|
||||
}
|
||||
|
||||
err = service.dbAuth.InsertEmailVerificationToken(user.Id, token)
|
||||
err = service.dbAuth.InsertEmailVerificationToken(userId, token)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -150,7 +150,7 @@ func (service ServiceAuthImpl) SendVerificationMail(user *User) {
|
||||
return
|
||||
}
|
||||
|
||||
service.mailService.SendMail(user.Email, "Welcome to ME-FIT", w.String())
|
||||
service.mailService.SendMail(email, "Welcome to ME-FIT", w.String())
|
||||
}
|
||||
|
||||
// TODO
|
||||
@@ -311,7 +311,7 @@ func HandleSignOutComp(db *sql.DB) http.HandlerFunc {
|
||||
}
|
||||
|
||||
func HandleDeleteAccountComp(db *sql.DB, serverSettings *types.ServerSettings) http.HandlerFunc {
|
||||
mailService := NewMailService(serverSettings)
|
||||
mailService := NewMailServiceImpl(serverSettings)
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
user := utils.GetUserFromSession(db, r)
|
||||
if user == nil {
|
||||
@@ -508,7 +508,7 @@ func HandleActualResetPasswordComp(db *sql.DB) http.HandlerFunc {
|
||||
}
|
||||
|
||||
func HandleResetPasswordComp(db *sql.DB, serverSettings *types.ServerSettings) http.HandlerFunc {
|
||||
mailService := NewMailService(serverSettings)
|
||||
mailService := NewMailServiceImpl(serverSettings)
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
email := r.FormValue("email")
|
||||
|
||||
Reference in New Issue
Block a user