Search in sources :

Example 31 with User

use of com.ncedu.fooddelivery.api.v1.entities.User in project 2021-msk-food-delivery by netcracker-edu.

the class ProfileControllerTest method changeAdminName.

@Test
public void changeAdminName() {
    UserChangeInfoDTO userChangeInfoDTO = new UserChangeInfoDTO();
    userChangeInfoDTO.setFullName("Howard Joel Wolowitz");
    Long authedUserId = 1L;
    when(userServiceMock.changeFullName(authedUserId, userChangeInfoDTO.getFullName())).thenReturn(true);
    User user = new User();
    user.setId(authedUserId);
    user.setRole(Role.ADMIN);
    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 32 with User

use of com.ncedu.fooddelivery.api.v1.entities.User in project 2021-msk-food-delivery by netcracker-edu.

the class ProfileControllerTest method changeEmailWithBadValues.

@Test
public void changeEmailWithBadValues() {
    EmailChangeDTO emailChangeDTO = new EmailChangeDTO();
    emailChangeDTO.setEmail("wolowitz.bigbang");
    emailChangeDTO.setPassword("small");
    User user = new User();
    user.setId(1L);
    when(userServiceMock.changeEmail(user, emailChangeDTO)).thenReturn(false);
    ResponseEntity<?> resultResponse = profileController.changeUserEmail(emailChangeDTO, user);
    ResponseEntity<?> perfectResponse = createModifyResponse(false);
    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 33 with User

use of com.ncedu.fooddelivery.api.v1.entities.User in project 2021-msk-food-delivery by netcracker-edu.

the class ProfileControllerTest method getClientProfile.

@Test
public void getClientProfile() {
    ClientInfoDTO clientInfoDTO = new ClientInfoDTO(1L, "CLIENT", "client@mail.ru");
    when(clientServiceMock.getClientDTOById(1L)).thenReturn(clientInfoDTO);
    User user = new User();
    user.setId(1L);
    user.setRole(Role.CLIENT);
    UserInfoDTO resultClientDTO = profileController.getProfile(user);
    assertEquals(clientInfoDTO, resultClientDTO);
}
Also used : User(com.ncedu.fooddelivery.api.v1.entities.User) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 34 with User

use of com.ncedu.fooddelivery.api.v1.entities.User in project 2021-msk-food-delivery by netcracker-edu.

the class ProfileControllerTest method getModeratorProfile.

@Test
public void getModeratorProfile() {
    ModeratorInfoDTO moderatorInfoDTO = new ModeratorInfoDTO(1L, "MODERATOR", "moderator@mail.ru");
    when(moderatorServiceMock.getModeratorDTOById(1L)).thenReturn(moderatorInfoDTO);
    User user = new User();
    user.setId(1L);
    user.setRole(Role.MODERATOR);
    UserInfoDTO resultModeratorDTO = profileController.getProfile(user);
    assertEquals(moderatorInfoDTO, resultModeratorDTO);
}
Also used : User(com.ncedu.fooddelivery.api.v1.entities.User) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 35 with User

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

Aggregations

User (com.ncedu.fooddelivery.api.v1.entities.User)58 Test (org.junit.jupiter.api.Test)55 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)55 File (com.ncedu.fooddelivery.api.v1.entities.File)21 Path (java.nio.file.Path)19 MultipartFile (org.springframework.web.multipart.MultipartFile)19 CustomAccessDeniedException (com.ncedu.fooddelivery.api.v1.errors.security.CustomAccessDeniedException)18 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)18 FileLinkDTO (com.ncedu.fooddelivery.api.v1.dto.file.FileLinkDTO)15 Order (com.ncedu.fooddelivery.api.v1.entities.order.Order)14 BufferedImage (java.awt.image.BufferedImage)10 UserInfoDTO (com.ncedu.fooddelivery.api.v1.dto.user.UserInfoDTO)9 Role (com.ncedu.fooddelivery.api.v1.entities.Role)7 NotFoundEx (com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx)7 IOException (java.io.IOException)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 ProductPosition (com.ncedu.fooddelivery.api.v1.entities.productPosition.ProductPosition)6 AlreadyExistsException (com.ncedu.fooddelivery.api.v1.errors.badrequest.AlreadyExistsException)6 PasswordsMismatchException (com.ncedu.fooddelivery.api.v1.errors.badrequest.PasswordsMismatchException)6 CommitAfter (org.apache.tapestry5.jpa.annotations.CommitAfter)6