-
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.
feat: allow login using either email or username
- Updated the signIn method to check if the identifier is an email or username. - Modified the authentication process to handle both email and username.
- Loading branch information
1 parent
ea5378f
commit 9abf7c4
Showing
9 changed files
with
50 additions
and
41 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
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 |
---|---|---|
|
@@ -89,7 +89,7 @@ void signUp_return_204() throws Exception { | |
.content(usersRecordJacksonTester.write(usersDTO).getJson())) | ||
.andExpect(status().isNoContent()) | ||
.andExpect(jsonPath("$.username").value("testUser")) | ||
.andExpect(jsonPath("$.email").value("[email protected]")); | ||
.andExpect(jsonPath("$.identifier").value("[email protected]")); | ||
|
||
verify(userService).signUp(usersDTO.username(), usersDTO.password(), usersDTO.email()); | ||
} | ||
|
@@ -102,7 +102,7 @@ void signIn_shouldReturn200AndCallUserService() throws Exception { | |
LoginUserDTO loginRecord = new LoginUserDTO("[email protected]", "password"); | ||
TokenJwtDTO tokenJwtDTO = new TokenJwtDTO("TokenJwt", dateExp); | ||
|
||
when(userService.signIn(loginRecord.email(), loginRecord.password())) | ||
when(userService.signIn(loginRecord.identifier(), loginRecord.password())) | ||
.thenReturn(tokenJwtDTO); | ||
|
||
mockMvc.perform(post("/users/sign-in").contentType(MediaType.APPLICATION_JSON) | ||
|
@@ -170,7 +170,7 @@ void updatePassword_return_204() throws Exception { | |
@Test | ||
@DisplayName("Should return 400 when signing up with invalid data") | ||
void signUp_with_invalid_data_return_400() throws Exception { | ||
UsersDTO invalidRecord = new UsersDTO("", "", "invalid-email"); | ||
UsersDTO invalidRecord = new UsersDTO("", "", "invalid-identifier"); | ||
|
||
mockMvc.perform(post("/users/sign-up").contentType(MediaType.APPLICATION_JSON) | ||
.content(usersRecordJacksonTester.write(invalidRecord).getJson())) | ||
|
@@ -189,6 +189,6 @@ void signIn_with_invalid_credentials_return_401() throws Exception { | |
.content(loginRecordJacksonTester.write(loginRecord).getJson())) | ||
.andExpect(status().isUnauthorized()); | ||
|
||
verify(userService, times(1)).signIn(loginRecord.email(), loginRecord.password()); | ||
verify(userService, times(1)).signIn(loginRecord.identifier(), loginRecord.password()); | ||
} | ||
} |
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