fix: new test and extract time.Now to mockable Clock #181
All checks were successful
Build Docker Image / Build-Docker-Image (push) Successful in 48s
All checks were successful
Build Docker Image / Build-Docker-Image (push) Successful in 48s
This commit is contained in:
@@ -10,7 +10,6 @@ import (
|
||||
"net/mail"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"me-fit/db"
|
||||
"me-fit/template"
|
||||
@@ -54,14 +53,16 @@ type ServiceAuth interface {
|
||||
type ServiceAuthImpl struct {
|
||||
dbAuth db.DbAuth
|
||||
randomGenerator RandomGenerator
|
||||
clock Clock
|
||||
serverSettings *types.ServerSettings
|
||||
mailService MailService
|
||||
}
|
||||
|
||||
func NewServiceAuthImpl(dbAuth db.DbAuth, randomGenerator RandomGenerator, serverSettings *types.ServerSettings) *ServiceAuthImpl {
|
||||
func NewServiceAuthImpl(dbAuth db.DbAuth, randomGenerator RandomGenerator, clock Clock, serverSettings *types.ServerSettings) *ServiceAuthImpl {
|
||||
return &ServiceAuthImpl{
|
||||
dbAuth: dbAuth,
|
||||
randomGenerator: randomGenerator,
|
||||
clock: clock,
|
||||
serverSettings: serverSettings,
|
||||
mailService: NewMailService(serverSettings),
|
||||
}
|
||||
@@ -96,9 +97,8 @@ func (service ServiceAuthImpl) SignUp(email string, password string) (*User, err
|
||||
return nil, ErrInvalidPassword
|
||||
}
|
||||
|
||||
userId, err := uuid.NewRandom()
|
||||
userId, err := service.randomGenerator.UUID()
|
||||
if err != nil {
|
||||
utils.LogError("Could not generate UUID", err)
|
||||
return nil, types.ErrInternal
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ func (service ServiceAuthImpl) SignUp(email string, password string) (*User, err
|
||||
|
||||
hash := GetHashPassword(password, salt)
|
||||
|
||||
dbUser := db.NewUser(userId, email, false, nil, false, hash, salt, time.Now())
|
||||
dbUser := db.NewUser(userId, email, false, nil, false, hash, salt, service.clock.Now())
|
||||
|
||||
err = service.dbAuth.InsertUser(dbUser)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user