use of com.ncedu.fooddelivery.api.v1.dto.user.PasswordChangeDTO in project 2021-msk-food-delivery by netcracker-edu.
the class UserServiceTest method changePasswordSuccess.
@Test
public void changePasswordSuccess() {
Long userId = 1L;
User rajesh = UserUtils.clientRajeshKoothrappali(userId);
String oldPass = "password";
String newPass = "koothrappali";
PasswordChangeDTO passwordDTO = new PasswordChangeDTO();
passwordDTO.setNewPassword(newPass);
passwordDTO.setNewPasswordConfirm(newPass);
passwordDTO.setOldPassword(oldPass);
when(userRepoMock.save(any(User.class))).thenAnswer(invocation -> invocation.getArguments()[0]);
boolean result = userService.changePassword(rajesh, passwordDTO);
assertTrue(result);
verify(userRepoMock, times(1)).save(any(User.class));
}
use of com.ncedu.fooddelivery.api.v1.dto.user.PasswordChangeDTO 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 com.ncedu.fooddelivery.api.v1.dto.user.PasswordChangeDTO in project 2021-msk-food-delivery by netcracker-edu.
the class UserServiceTest method changePasswordNewPassNotSame.
@Test
public void changePasswordNewPassNotSame() {
Long userId = 1L;
User rajesh = UserUtils.clientRajeshKoothrappali(userId);
String oldPass = "password";
String newPass = "koothrappali";
String newPass2 = "wrongNewPass";
PasswordChangeDTO passwordDTO = new PasswordChangeDTO();
passwordDTO.setNewPassword(newPass);
passwordDTO.setNewPasswordConfirm(newPass2);
passwordDTO.setOldPassword(oldPass);
Exception exception = assertThrows(PasswordsMismatchException.class, () -> {
userService.changePassword(rajesh, passwordDTO);
});
verify(userRepoMock, never()).save(any(User.class));
}
use of com.ncedu.fooddelivery.api.v1.dto.user.PasswordChangeDTO in project 2021-msk-food-delivery by netcracker-edu.
the class ProfileControllerTest method changePasswordSuccess.
@Test
public void changePasswordSuccess() {
PasswordChangeDTO pwdChangeDTO = new PasswordChangeDTO();
pwdChangeDTO.setOldPassword("password");
pwdChangeDTO.setNewPassword("qwerty123");
pwdChangeDTO.setNewPasswordConfirm("qwerty123");
User user = new User();
user.setId(1L);
when(userServiceMock.changePassword(user, pwdChangeDTO)).thenReturn(true);
ResponseEntity<?> resultResponse = profileController.changeUserPassword(pwdChangeDTO, user);
ResponseEntity<?> perfectResponse = createModifyResponse(true);
verify(userServiceMock, times(1)).changePassword(user, pwdChangeDTO);
assertEquals(perfectResponse, resultResponse);
}
use of com.ncedu.fooddelivery.api.v1.dto.user.PasswordChangeDTO in project 2021-msk-food-delivery by netcracker-edu.
the class UserServiceTest method changePasswordOldPassIncorrect.
@Test
public void changePasswordOldPassIncorrect() {
Long userId = 1L;
User rajesh = UserUtils.clientRajeshKoothrappali(userId);
String oldPass = "wrongOldPass";
String newPass = "koothrappali";
PasswordChangeDTO passwordDTO = new PasswordChangeDTO();
passwordDTO.setNewPassword(newPass);
passwordDTO.setNewPasswordConfirm(newPass);
passwordDTO.setOldPassword(oldPass);
Exception exception = assertThrows(PasswordsMismatchException.class, () -> {
userService.changePassword(rajesh, passwordDTO);
});
verify(userRepoMock, never()).save(any(User.class));
}
Aggregations