-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AYS-501 | Fixed the time and user were not being updated in the User …
…update (#388)
- Loading branch information
1 parent
5b2bc1a
commit a8f09a2
Showing
3 changed files
with
170 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,8 @@ | |
import org.ays.auth.port.AysRoleReadPort; | ||
import org.ays.auth.port.AysUserReadPort; | ||
import org.ays.auth.port.AysUserSavePort; | ||
import org.ays.common.model.AysPhoneNumberBuilder; | ||
import org.ays.common.model.request.AysPhoneNumberRequestBuilder; | ||
import org.ays.common.model.response.AysPageResponse; | ||
import org.ays.common.model.response.AysResponse; | ||
import org.ays.common.model.response.AysResponseBuilder; | ||
|
@@ -373,6 +375,78 @@ void givenValidIdAndUserUpdateRequest_whenUserUpdated_thenReturnSuccess() throws | |
Assertions.assertNotNull(userFromDatabase.get().getUpdatedAt()); | ||
} | ||
|
||
@Test | ||
void givenValidIdAndUserUpdateRequest_whenRolesUpdatedOnly_thenReturnSuccess() throws Exception { | ||
|
||
// Initialize | ||
Institution institution = new InstitutionBuilder() | ||
.withId(AysValidTestData.Admin.INSTITUTION_ID) | ||
.build(); | ||
|
||
List<AysRole> roles = roleReadPort.findAllActivesByInstitutionId(institution.getId()); | ||
|
||
AysUser user = userSavePort.save( | ||
new AysUserBuilder() | ||
.withValidValues() | ||
.withFirstName("Test") | ||
.withLastName("Dene") | ||
.withEmailAddress("[email protected]") | ||
.withCity("İzmir") | ||
.withPhoneNumber(new AysPhoneNumberBuilder().withValidValues().build()) | ||
.withoutId() | ||
.withRoles(roles) | ||
.withInstitution(institution) | ||
.build() | ||
); | ||
|
||
// Given | ||
String id = user.getId(); | ||
AysRole newRole = roles.get(0); | ||
List<AysRole> newRoles = List.of(newRole); | ||
|
||
Set<String> newRoleIds = newRoles.stream() | ||
.map(AysRole::getId) | ||
.limit(1) | ||
.collect(Collectors.toSet()); | ||
|
||
AysUserUpdateRequest updateRequest = new AysUserUpdateRequestBuilder() | ||
.withValidValues() | ||
.withFirstName("Test") | ||
.withLastName("Dene") | ||
.withEmailAddress("[email protected]") | ||
.withCity("İzmir") | ||
.withPhoneNumber(new AysPhoneNumberRequestBuilder().withValidValues().build()) | ||
.withRoleIds(newRoleIds) | ||
.build(); | ||
|
||
// Then | ||
String endpoint = BASE_PATH.concat("/user/").concat(id); | ||
MockHttpServletRequestBuilder mockHttpServletRequestBuilder = AysMockMvcRequestBuilders | ||
.put(endpoint, adminToken.getAccessToken(), updateRequest); | ||
|
||
AysResponse<Void> mockResponse = AysResponseBuilder.SUCCESS; | ||
|
||
aysMockMvc.perform(mockHttpServletRequestBuilder, mockResponse) | ||
.andExpect(AysMockResultMatchersBuilders.status() | ||
.isOk()) | ||
.andExpect(AysMockResultMatchersBuilders.response() | ||
.doesNotExist()); | ||
|
||
// Verify | ||
Optional<AysUser> userFromDatabase = userReadPort.findById(id); | ||
|
||
Assertions.assertTrue(userFromDatabase.isPresent()); | ||
Assertions.assertNotNull(userFromDatabase.get().getId()); | ||
Assertions.assertNotNull(userFromDatabase.get().getInstitution()); | ||
newRoleIds.forEach(roleId -> Assertions.assertTrue( | ||
userFromDatabase.get().getRoles().stream() | ||
.anyMatch(role -> role.getId().equals(roleId)) | ||
) | ||
); | ||
Assertions.assertNotNull(userFromDatabase.get().getUpdatedUser()); | ||
Assertions.assertNotNull(userFromDatabase.get().getUpdatedAt()); | ||
} | ||
|
||
|
||
@Test | ||
void givenValidId_whenActivateUser_thenReturnSuccess() throws Exception { | ||
|
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