-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue 147 - Padronizar testes usando Mockery (#149)
* Padronizar testes usando Mockery (#147) *refactor tests: breed and pet. * Issue 54 - Fazer rota de listagem de pets ter autenticacao e listagem diferenciada (#142) * feat: add validations to dto feat: implement function find User by email feat: add missing fields to NewPet and database fields on entity feat: fix Save function and add List functions feat: fix call of Save from repository and add List methods feat: add ListAllPets function feat: add List functions to interface feat: routes to list pets feat: change error message feat: add offset, fix query and remove adoptionDate feat: remove unused adoptionDate feat: remove page from parameter feat: add validation rule to check if user is authenticated and return list of pets based on result feat: update autogenerated mocks feat: add autogenerated repo mocks feat: add test for ListAllUnauthenticated feat: add more test cases for ListAllUnauthenticated feat: remove print statements feat: fix Save Pet Usecase test and add two authenticated list pets feat: add test for List pets authenticated with repo error feat: implement FindByEmail from usecase instead of repo feat: rename encoder variable feat: remove parenthesis feat: remove method for unauthenticated listing feat: remove ID from list of pets after receiving from repo feat: call private methods based on user auth and move validation to usecase feat: validate Authorization token and pass to usecase * feat: fix usage of boolean to verify authenticated user * feat: add pet listing to public routes * feat: update mockery to fix errors * fix tests * feat: remove redundant validation * feat: Reset User Password (#151) * feat: Reset User Password * feat: Changing Password functions * chore: mockery * fix: Controller logger warnings * fix: Fixing Password verification * fix: Message Warning * fix: Password format validation * feat: Utils tests * chore: user test WIP * feat: Change Password Tests * fix: CMD Errors * fix: Renaming hasher and repo to have different names of the pkg * fix: Initializing empty var with var instead of := --------- Co-authored-by: Luan Alves <[email protected]> Co-authored-by: Patrick Nery Nogueira <[email protected]>
- Loading branch information
1 parent
7ba70d0
commit ac98426
Showing
26 changed files
with
1,023 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
with-expecter: true | ||
packages: | ||
pet-dex-backend/v2/interfaces: | ||
all: true | ||
interfaces: | ||
Hasher: | ||
PetRepository: | ||
UserRepository: | ||
OngRepository: | ||
AdressRepo: | ||
pet-dex-backend/v2/interfaces: | ||
all: true | ||
interfaces: | ||
Hasher: | ||
PetRepository: | ||
UserRepository: | ||
OngRepository: | ||
BreedRepository: | ||
AdressRepo: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package dto | ||
|
||
import ( | ||
"errors" | ||
"pet-dex-backend/v2/pkg/utils" | ||
) | ||
|
||
type UserChangePasswordDto struct { | ||
OldPassword string `json:"oldPassword"` | ||
NewPassword string `json:"newPassword"` | ||
NewPasswordAgain string `json:"newPasswordAgain"` | ||
} | ||
|
||
func (u *UserChangePasswordDto) Validate() error { | ||
if u.NewPassword == "" { | ||
return errors.New("password cannot be empty") | ||
} | ||
if u.OldPassword == u.NewPassword { | ||
return errors.New("old password cannot be the same as new password") | ||
} | ||
if u.NewPassword != u.NewPasswordAgain { | ||
return errors.New("new passwords do not match") | ||
} | ||
|
||
if !utils.IsValidPassword(u.NewPassword) { | ||
return errors.New("new password must be at least 6 characters long and contain at least one uppercase letter and one special character") | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package dto | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestChangePasswordValidate(t *testing.T) { | ||
cases := map[string]struct { | ||
userChangePassword UserChangePasswordDto | ||
expected error | ||
}{ | ||
"Valid Password": { | ||
userChangePassword: UserChangePasswordDto{ | ||
OldPassword: "oldPassword123!", | ||
NewPassword: "NewPassword123!", | ||
NewPasswordAgain: "NewPassword123!", | ||
}, | ||
expected: nil, | ||
}, | ||
"Empty New Password": { | ||
userChangePassword: UserChangePasswordDto{ | ||
OldPassword: "oldPassword123!", | ||
NewPassword: "", | ||
NewPasswordAgain: "NewPassword123!", | ||
}, | ||
expected: errors.New("password cannot be empty"), | ||
}, | ||
"New Password is equal to Old Password": { | ||
userChangePassword: UserChangePasswordDto{ | ||
OldPassword: "oldPassword123!", | ||
NewPassword: "oldPassword123!", | ||
NewPasswordAgain: "NewPassword123!", | ||
}, | ||
expected: errors.New("old password cannot be the same as new password"), | ||
}, | ||
"New Passwords does not match": { | ||
userChangePassword: UserChangePasswordDto{ | ||
OldPassword: "oldPassword123!", | ||
NewPassword: "NewPassword123!", | ||
NewPasswordAgain: "DifferentNewPassword123!", | ||
}, | ||
expected: errors.New("new passwords do not match"), | ||
}, | ||
"New Password does not match the security requirements": { | ||
userChangePassword: UserChangePasswordDto{ | ||
OldPassword: "oldPassword123!", | ||
NewPassword: "password123!", | ||
NewPasswordAgain: "password123!", | ||
}, | ||
expected: errors.New("new password must be at least 6 characters long and contain at least one uppercase letter and one special character"), | ||
}, | ||
} | ||
|
||
for name, test := range cases { | ||
t.Run(name, func(t *testing.T) { | ||
result := test.userChangePassword.Validate() | ||
assert.Equal(t, test.expected, result, test.expected) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.