use of com.laurentiuspilca.springsecurityc2.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class UserServiceTest method unlockUserAlsoUnlocked.
@Test
public void unlockUserAlsoUnlocked() {
User penny = UserUtils.clientPennyTeller(1L);
penny.setLockDate(null);
UserInfoDTO resultDTO = userService.unlockUser(penny);
assertEquals(null, resultDTO.getLockDate());
verify(userRepoMock, never()).save(any(User.class));
}
use of com.laurentiuspilca.springsecurityc2.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class ProfileControllerTest method changeClientName.
@Test
public void changeClientName() {
UserChangeInfoDTO userChangeInfoDTO = new UserChangeInfoDTO();
userChangeInfoDTO.setFullName("Sheldon Lee Cooper");
Long authedUserId = 1L;
when(clientServiceMock.changeClientInfo(authedUserId, userChangeInfoDTO)).thenReturn(true);
User user = new User();
user.setId(authedUserId);
user.setRole(Role.CLIENT);
ResponseEntity<?> resultResponse = profileController.changeUserInfo(userChangeInfoDTO, user);
ResponseEntity<?> perfectResponse = createModifyResponse(true);
assertEquals(perfectResponse, resultResponse);
}
use of com.laurentiuspilca.springsecurityc2.entities.User 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.laurentiuspilca.springsecurityc2.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class UserServiceImpl method getAllAdmins.
public List<UserInfoDTO> getAllAdmins() {
Role adminRole = Role.ADMIN;
List<User> admins = userRepo.findByRole(adminRole);
List<UserInfoDTO> adminsDTO = new ArrayList<>();
for (User admin : admins) {
adminsDTO.add(createUserDTO(admin));
}
return adminsDTO;
}
use of com.laurentiuspilca.springsecurityc2.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class UserServiceImpl method changeEmail.
@Override
public boolean changeEmail(User user, EmailChangeDTO newEmailInfo) {
String newUserEmail = newEmailInfo.getEmail();
User userWithNewEmail = userRepo.findByEmail(newUserEmail);
// user with new email also exist throw exception!
if (userWithNewEmail != null) {
throw new AlreadyExistsException(newUserEmail);
}
String inputPassword = newEmailInfo.getPassword();
String userEncodedPassword = user.getPassword();
boolean isPasswordsSame = encoder.matches(inputPassword, userEncodedPassword);
if (!isPasswordsSame) {
throw new PasswordsMismatchException();
}
user.setEmail(newUserEmail);
userRepo.save(user);
return true;
}
Aggregations