Search in sources :

Example 26 with User

use of 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)

Example 27 with User

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

the class ProfileControllerTest method changeEmail.

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

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

the class ProfileControllerTest method getAdminProfile.

@Test
public void getAdminProfile() {
    UserInfoDTO userInfoDTO = new UserInfoDTO(1L, "ADMIN", "admin@mail.ru");
    when(userServiceMock.getUserDTOById(1L)).thenReturn(userInfoDTO);
    User user = new User();
    user.setId(1L);
    user.setRole(Role.ADMIN);
    UserInfoDTO resultUserDTO = profileController.getProfile(user);
    assertEquals(userInfoDTO, resultUserDTO);
}
Also used : User(com.ncedu.fooddelivery.api.v1.entities.User) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 29 with User

use of entities.User 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 30 with User

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

the class ClientUtils method createClient.

private static Client createClient(Long userId, String fullName, String email, String phoneNumber) {
    User user = new User();
    user.setId(userId);
    user.setFullName(fullName);
    user.setEmail(email);
    user.setRole(Role.CLIENT);
    Client client = new Client();
    client.setPhoneNumber(phoneNumber);
    client.setUser(user);
    return client;
}
Also used : User(com.ncedu.fooddelivery.api.v1.entities.User) Client(com.ncedu.fooddelivery.api.v1.entities.Client)

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