Search in sources :

Example 1 with PasswordChangeDTO

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));
}
Also used : User(com.ncedu.fooddelivery.api.v1.entities.User) PasswordChangeDTO(com.ncedu.fooddelivery.api.v1.dto.user.PasswordChangeDTO) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with PasswordChangeDTO

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);
}
Also used : User(com.ncedu.fooddelivery.api.v1.entities.User) PasswordsMismatchException(com.ncedu.fooddelivery.api.v1.errors.badrequest.PasswordsMismatchException) PasswordsMismatchException(com.ncedu.fooddelivery.api.v1.errors.badrequest.PasswordsMismatchException) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with PasswordChangeDTO

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));
}
Also used : User(com.ncedu.fooddelivery.api.v1.entities.User) PasswordChangeDTO(com.ncedu.fooddelivery.api.v1.dto.user.PasswordChangeDTO) AlreadyExistsException(com.ncedu.fooddelivery.api.v1.errors.badrequest.AlreadyExistsException) PasswordsMismatchException(com.ncedu.fooddelivery.api.v1.errors.badrequest.PasswordsMismatchException) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with PasswordChangeDTO

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);
}
Also used : User(com.ncedu.fooddelivery.api.v1.entities.User) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with PasswordChangeDTO

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));
}
Also used : User(com.ncedu.fooddelivery.api.v1.entities.User) PasswordChangeDTO(com.ncedu.fooddelivery.api.v1.dto.user.PasswordChangeDTO) AlreadyExistsException(com.ncedu.fooddelivery.api.v1.errors.badrequest.AlreadyExistsException) PasswordsMismatchException(com.ncedu.fooddelivery.api.v1.errors.badrequest.PasswordsMismatchException) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

User (com.ncedu.fooddelivery.api.v1.entities.User)5 Test (org.junit.jupiter.api.Test)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 PasswordChangeDTO (com.ncedu.fooddelivery.api.v1.dto.user.PasswordChangeDTO)3 PasswordsMismatchException (com.ncedu.fooddelivery.api.v1.errors.badrequest.PasswordsMismatchException)3 AlreadyExistsException (com.ncedu.fooddelivery.api.v1.errors.badrequest.AlreadyExistsException)2