use of org.example.app6.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class ProfileControllerTest method changeAdminNameWithNullName.
@Test
public void changeAdminNameWithNullName() {
// in DTO fullName not presented
UserChangeInfoDTO userChangeInfoDTO = new UserChangeInfoDTO();
userChangeInfoDTO.setPhoneNumber("+7 (800) 555 35-35");
Long authedUserId = 1L;
when(userServiceMock.changeFullName(authedUserId, userChangeInfoDTO.getFullName())).thenReturn(false);
User user = new User();
user.setId(authedUserId);
user.setRole(Role.ADMIN);
ResponseEntity<?> resultResponse = profileController.changeUserInfo(userChangeInfoDTO, user);
ResponseEntity<?> perfectResponse = createModifyResponse(false);
assertEquals(perfectResponse, resultResponse);
}
use of org.example.app6.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class ProfileControllerTest method changeEmail.
@Test
public void changeEmail() {
EmailChangeDTO emailChangeDTO = new EmailChangeDTO();
emailChangeDTO.setEmail("wolowitz@bigbang.theory");
emailChangeDTO.setPassword("bigBangTheory");
User user = new User();
user.setId(1L);
when(userServiceMock.changeEmail(user, emailChangeDTO)).thenReturn(true);
ResponseEntity<?> resultResponse = profileController.changeUserEmail(emailChangeDTO, user);
ResponseEntity<?> perfectResponse = createModifyResponse(true);
assertEquals(perfectResponse, resultResponse);
}
use of org.example.app6.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class ProfileControllerTest method getAdminProfile.
@Test
public void getAdminProfile() {
UserInfoDTO userInfoDTO = new UserInfoDTO(1L, "ADMIN", "admin@mail.ru");
when(userServiceMock.getUserDTOById(1L)).thenReturn(userInfoDTO);
User user = new User();
user.setId(1L);
user.setRole(Role.ADMIN);
UserInfoDTO resultUserDTO = profileController.getProfile(user);
assertEquals(userInfoDTO, resultUserDTO);
}
use of org.example.app6.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class ProfileControllerTest method changePasswordMismatchError.
@Test
public void changePasswordMismatchError() {
PasswordChangeDTO pwdChangeDTO = new PasswordChangeDTO();
pwdChangeDTO.setOldPassword("password");
pwdChangeDTO.setNewPassword("qwerty123");
pwdChangeDTO.setNewPasswordConfirm("INCORRECT");
User user = new User();
user.setId(1L);
when(userServiceMock.changePassword(user, pwdChangeDTO)).thenThrow(new PasswordsMismatchException());
Exception exception = assertThrows(PasswordsMismatchException.class, () -> {
profileController.changeUserPassword(pwdChangeDTO, user);
});
String resultMessage = exception.getMessage();
String perfectMessage = new PasswordsMismatchException().getMessage();
verify(userServiceMock, times(1)).changePassword(user, pwdChangeDTO);
assertEquals(perfectMessage, resultMessage);
}
use of org.example.app6.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class ClientUtils method createClient.
private static Client createClient(Long userId, String fullName, String email, String phoneNumber) {
User user = new User();
user.setId(userId);
user.setFullName(fullName);
user.setEmail(email);
user.setRole(Role.CLIENT);
Client client = new Client();
client.setPhoneNumber(phoneNumber);
client.setUser(user);
return client;
}
Aggregations