use of com.github.nkonev.aaa.dto.UserAccountDTO in project videochat by nkonev.
the class UserProfileControllerTest method fullyAuthenticatedUserCanChangeHerProfile.
@WithUserDetails(TestConstants.USER_ALICE)
@org.junit.jupiter.api.Test
public void fullyAuthenticatedUserCanChangeHerProfile() throws Exception {
receiver.clear();
UserAccount userAccount = getUserFromBd(TestConstants.USER_ALICE);
final String initialPassword = userAccount.password();
final String newLogin = "new_alice";
EditUserDTO edit = UserAccountConverter.convertToEditUserDto(userAccount);
edit = edit.withLogin(newLogin);
MvcResult mvcResult = mockMvc.perform(post(Constants.Urls.API + Constants.Urls.PROFILE).content(objectMapper.writeValueAsString(edit)).contentType(MediaType.APPLICATION_JSON_UTF8).with(csrf())).andExpect(status().isOk()).andExpect(jsonPath("$.login").value(newLogin)).andExpect(jsonPath("$.password").doesNotExist()).andReturn();
LOGGER.info(mvcResult.getResponse().getContentAsString());
Assertions.assertEquals(initialPassword, getUserFromBd(newLogin).password(), "password shouldn't be affected if there isn't set explicitly");
MvcResult getPostsRequest = mockMvc.perform(get(Constants.Urls.API + Constants.Urls.PROFILE)).andExpect(status().isOk()).andExpect(jsonPath("$.login").value(newLogin)).andExpect(jsonPath("$.password").doesNotExist()).andReturn();
for (int i = 0; i < 10; ++i) {
if (receiver.size() > 0) {
break;
} else {
Uninterruptibles.sleepUninterruptibly(Duration.of(1, ChronoUnit.SECONDS));
}
}
Assertions.assertEquals(1, receiver.size());
final UserAccountDTO userAccountEvent = receiver.getLast();
Assertions.assertEquals(newLogin, userAccountEvent.login());
}
Aggregations