Skip to content

Commit

Permalink
Update CreateUseCase input from value to pointer
Browse files Browse the repository at this point in the history
Also, update multiple files from the previous mentioned update, including mocks, tests and validation implementation
  • Loading branch information
jessicatarra committed Dec 16, 2023
1 parent 2139b28 commit 6b4223c
Show file tree
Hide file tree
Showing 11 changed files with 185 additions and 24 deletions.
2 changes: 1 addition & 1 deletion ms/auth/internal/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewAppl(userRepo domain.UserRepository, tokenRepo domain.TokenRepository, p
}
}

func (a *appl) CreateUseCase(input domain.CreateUserRequest, hashedPassword string) (*domain.User, error) {
func (a *appl) CreateUseCase(input *domain.CreateUserRequest, hashedPassword string) (*domain.User, error) {
user := &domain.User{Name: input.Name, Email: input.Email, Activated: false}

err := a.userRepo.InsertNewUser(user, hashedPassword)
Expand Down
4 changes: 2 additions & 2 deletions ms/auth/internal/application/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestAppl_CreateUseCase(t *testing.T) {
tokenRepo.On("New", mock.Anything, mock.AnythingOfType("time.Duration"), mock.IsType("string")).Return(nil, nil)

// Call the CreateUseCase function
user, err := app.CreateUseCase(input, hashedPassword)
user, err := app.CreateUseCase(&input, hashedPassword)

// Assert the results
assert.NotNil(t, user)
Expand All @@ -98,7 +98,7 @@ func TestAppl_CreateUseCase(t *testing.T) {
tokenRepo.On("New", mock.Anything, mock.AnythingOfType("time.Duration"), mock.IsType("string")).Return(nil, nil)

// Call the CreateUseCase function again
user, err := app.CreateUseCase(input, hashedPassword)
user, err := app.CreateUseCase(&input, hashedPassword)

// Assert the error step
assert.Nil(t, user)
Expand Down
34 changes: 29 additions & 5 deletions ms/auth/internal/domain/mocks/Appl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion ms/auth/internal/domain/mocks/PermissionRepository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion ms/auth/internal/domain/mocks/TokenInterface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 13 additions & 1 deletion ms/auth/internal/domain/mocks/TokenRepository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 21 additions & 1 deletion ms/auth/internal/domain/mocks/UserRepository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ms/auth/internal/domain/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (u *User) IsAnonymous() bool {
}

type Appl interface {
CreateUseCase(input CreateUserRequest, hashedPassword string) (*User, error)
CreateUseCase(input *CreateUserRequest, hashedPassword string) (*User, error)
ActivateUseCase(tokenPlainText string) (*User, error)
GetByEmailUseCase(email string) (*User, error)
CreateAuthTokenUseCase(userID int64) ([]byte, error)
Expand Down
8 changes: 4 additions & 4 deletions ms/auth/internal/infrastructure/http/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (h *handlers) createUser(res http.ResponseWriter, req *http.Request) {
return
}

ValidateUser(input, existingUser)
ValidateUser(&input, existingUser)

if input.Validator.HasErrors() {
_errors.FailedValidation(res, req, input.Validator)
Expand All @@ -76,7 +76,7 @@ func (h *handlers) createUser(res http.ResponseWriter, req *http.Request) {
return
}

user, err := h.appl.CreateUseCase(input, hashedPassword)
user, err := h.appl.CreateUseCase(&input, hashedPassword)
if err != nil {
switch {
case errors.Is(err, domain.ErrDuplicateEmail):
Expand Down Expand Up @@ -109,7 +109,7 @@ func (h *handlers) activateUser(res http.ResponseWriter, req *http.Request) {

input.TokenPlaintext = h.helpers.ReadString(qs, "token", "")

ValidateToken(input)
ValidateToken(&input)

if input.Validator.HasErrors() {
_errors.FailedValidation(res, req, input.Validator)
Expand Down Expand Up @@ -156,7 +156,7 @@ func (h *handlers) createAuthenticationToken(res http.ResponseWriter, req *http.
return
}

ValidateEmailForAuth(input, existingUser)
ValidateEmailForAuth(&input, existingUser)

if existingUser != nil {
passwordMatches, err := password.Matches(input.Password, existingUser.HashedPassword)
Expand Down
Loading

0 comments on commit 6b4223c

Please sign in to comment.