Search in sources :

Example 1 with UserAccountDTO

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());
}
Also used : UserAccountDTO(com.github.nkonev.aaa.dto.UserAccountDTO) EditUserDTO(com.github.nkonev.aaa.dto.EditUserDTO) MvcResult(org.springframework.test.web.servlet.MvcResult) UserAccount(com.github.nkonev.aaa.entity.jdbc.UserAccount) Test(org.junit.jupiter.api.Test) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails)

Aggregations

EditUserDTO (com.github.nkonev.aaa.dto.EditUserDTO)1 UserAccountDTO (com.github.nkonev.aaa.dto.UserAccountDTO)1 UserAccount (com.github.nkonev.aaa.entity.jdbc.UserAccount)1 Test (org.junit.jupiter.api.Test)1 WithUserDetails (org.springframework.security.test.context.support.WithUserDetails)1 MvcResult (org.springframework.test.web.servlet.MvcResult)1