Search in sources :

Example 66 with User

use of com.laurentiuspilca.ssc6.entities.User in project 2021-msk-food-delivery by netcracker-edu.

the class UserServiceTest method setLastSigninSuccess.

@Test
public void setLastSigninSuccess() {
    User howard = UserUtils.courierHowardWolowitz(1L);
    Timestamp current = new Timestamp(System.currentTimeMillis());
    howard.setLastSigninDate(current);
    when(userRepoMock.save(any(User.class))).thenAnswer(invocation -> invocation.getArguments()[0]);
    userService.setLastSigninFromNow(howard);
    assertTrue(current.before(howard.getLastSigninDate()));
    verify(userRepoMock, times(1)).save(any());
}
Also used : User(com.ncedu.fooddelivery.api.v1.entities.User) Timestamp(java.sql.Timestamp) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 67 with User

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

Example 68 with User

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

Example 69 with User

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

Example 70 with User

use of com.laurentiuspilca.ssc6.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;
}
Also used : Role(com.ncedu.fooddelivery.api.v1.entities.Role) User(com.ncedu.fooddelivery.api.v1.entities.User) UserInfoDTO(com.ncedu.fooddelivery.api.v1.dto.user.UserInfoDTO)

Aggregations

User (com.ncedu.fooddelivery.api.v1.entities.User)58 Test (org.junit.jupiter.api.Test)49 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)49 File (com.ncedu.fooddelivery.api.v1.entities.File)18 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)18 MultipartFile (org.springframework.web.multipart.MultipartFile)18 Path (java.nio.file.Path)16 FileLinkDTO (com.ncedu.fooddelivery.api.v1.dto.file.FileLinkDTO)12 UserInfoDTO (com.ncedu.fooddelivery.api.v1.dto.user.UserInfoDTO)9 BufferedImage (java.awt.image.BufferedImage)8 CommitAfter (org.apache.tapestry5.jpa.annotations.CommitAfter)7 AlreadyExistsException (com.ncedu.fooddelivery.api.v1.errors.badrequest.AlreadyExistsException)6 PasswordsMismatchException (com.ncedu.fooddelivery.api.v1.errors.badrequest.PasswordsMismatchException)6 PersistenceContext (javax.persistence.PersistenceContext)6 User (org.example.app0.entities.User)6 User (org.example.app1.entities.User)6 User (org.example.app6.entities.User)5 EmailChangeDTO (com.ncedu.fooddelivery.api.v1.dto.user.EmailChangeDTO)4 PasswordChangeDTO (com.ncedu.fooddelivery.api.v1.dto.user.PasswordChangeDTO)4 IOException (java.io.IOException)4