-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2ee3456
commit efcf3b7
Showing
5 changed files
with
17 additions
and
16 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
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 |
---|---|---|
|
@@ -88,7 +88,7 @@ void signUp_return_204() throws Exception { | |
mockMvc.perform(post("/users/sign-up").contentType(MediaType.APPLICATION_JSON) | ||
.content(usersRecordJacksonTester.write(usersDTO).getJson())) | ||
.andExpect(status().isNoContent()) | ||
.andExpect(jsonPath("$.username").value("testUser")) | ||
.andExpect(jsonPath("$.identifier").value("testUser")) | ||
.andExpect(jsonPath("$.identifier").value("[email protected]")); | ||
|
||
verify(userService).signUp(usersDTO.username(), usersDTO.password(), usersDTO.email()); | ||
|
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 |
---|---|---|
|
@@ -40,7 +40,7 @@ void testRecoverPassword_UserExists() { | |
when(userRepository.existsByUsernameAndEmail(anyString(), anyString())).thenReturn(true); | ||
when(passwordRecoveryTokenManager.generateTemporaryPassword()).thenReturn("tempPassword"); | ||
|
||
userService.recoverPassword("username", "[email protected]"); | ||
userService.recoverPassword("identifier", "[email protected]"); | ||
|
||
verify(passwordRecoveryTokenManager).generateAndStoreToken("[email protected]", | ||
"tempPassword"); | ||
|
@@ -52,12 +52,12 @@ void testRecoverPassword_UserDoesNotExist() { | |
when(userRepository.existsByUsernameAndEmail(anyString(), anyString())).thenReturn(false); | ||
|
||
assertThrows(CustomGlobalErrorHandling.ResourceNotFoundException.class, | ||
() -> userService.recoverPassword("username", "[email protected]")); | ||
() -> userService.recoverPassword("identifier", "[email protected]")); | ||
} | ||
|
||
@Test | ||
void testChangePassword_ValidToken() { | ||
User user = new User("username", BCryptEncoderComponent.encrypt("newPassword"), | ||
User user = new User("identifier", BCryptEncoderComponent.encrypt("newPassword"), | ||
"[email protected]", UserRoles.USER); | ||
when(passwordRecoveryTokenManager.isRecoveryTokenValid(anyString(), anyString())) | ||
.thenReturn(true); | ||
|
@@ -80,44 +80,44 @@ void testSignUp_UserAlreadyExists() { | |
when(userRepository.existsByEmail(anyString())).thenReturn(true); | ||
|
||
assertThrows(CustomGlobalErrorHandling.UserAlreadyExistException.class, | ||
() -> userService.signUp("username", "password", "[email protected]")); | ||
() -> userService.signUp("identifier", "password", "[email protected]")); | ||
} | ||
|
||
@Test | ||
void testSignUp_NewUser() { | ||
when(userRepository.existsByEmail(anyString())).thenReturn(false); | ||
when(userRepository.save(any(User.class))).thenReturn( | ||
new User("username", "encryptedPassword", "[email protected]", UserRoles.USER)); | ||
new User("identifier", "encryptedPassword", "[email protected]", UserRoles.USER)); | ||
|
||
User user = userService.signUp("username", "password", "[email protected]"); | ||
User user = userService.signUp("identifier", "password", "[email protected]"); | ||
|
||
assertNotNull(user); | ||
assertEquals("username", user.getUsername()); | ||
assertEquals("identifier", user.getUsername()); | ||
assertEquals("[email protected]", user.getEmail()); | ||
} | ||
|
||
@Test | ||
void should_return_error_with_testUpdateUserPassword_PasswordMatches() { | ||
User user = new User("username", BCryptEncoderComponent.encrypt("newPassword"), | ||
User user = new User("identifier", BCryptEncoderComponent.encrypt("newPassword"), | ||
"[email protected]", UserRoles.USER); | ||
|
||
when(userRepository.getReferenceByUsernameAndEmail(anyString(), anyString())) | ||
.thenReturn(user); | ||
|
||
assertThrows(CustomGlobalErrorHandling.PasswordNotMatchesException.class, () -> userService | ||
.updateUserPassword("username", "[email protected]", "oldPassword", "newPassword")); | ||
.updateUserPassword("identifier", "[email protected]", "oldPassword", "newPassword")); | ||
verify(userRepository, never()).setPasswordWhereByUsername(anyString(), anyString()); | ||
} | ||
|
||
@Test | ||
void testUpdateUserPassword_PasswordDoesNotMatch() { | ||
User user = new User("username", BCryptEncoderComponent.encrypt("oldPassword"), | ||
User user = new User("identifier", BCryptEncoderComponent.encrypt("oldPassword"), | ||
"[email protected]", UserRoles.USER); | ||
when(userRepository.getReferenceByUsernameAndEmail(anyString(), anyString())) | ||
.thenReturn(user); | ||
|
||
assertThrows(CustomGlobalErrorHandling.PasswordNotMatchesException.class, | ||
() -> userService.updateUserPassword("username", "[email protected]", | ||
() -> userService.updateUserPassword("identifier", "[email protected]", | ||
"wrongPassword", "newPassword")); | ||
} | ||
} |