Search in sources :

Example 1 with ChangeRatingDTO

use of com.ncedu.fooddelivery.api.v1.dto.order.ChangeRatingDTO in project 2021-msk-food-delivery by netcracker-edu.

the class OrderServiceTest method changeCourierRatingCourierNotSetTest.

@Test
public void changeCourierRatingCourierNotSetTest() {
    User fakeUser = getFakeUserClient();
    ChangeRatingDTO fakeDto = new ChangeRatingDTO();
    Order fakeOrder = getFakeOrder();
    fakeOrder.setCourier(null);
    Assertions.assertThrows(CourierNotSetException.class, new Executable() {

        @Override
        public void execute() throws Throwable {
            orderService.changeDeliveryRating(fakeOrder, fakeDto, fakeUser);
        }
    });
}
Also used : Order(com.ncedu.fooddelivery.api.v1.entities.order.Order) ChangeRatingDTO(com.ncedu.fooddelivery.api.v1.dto.order.ChangeRatingDTO) Executable(org.junit.jupiter.api.function.Executable) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with ChangeRatingDTO

use of com.ncedu.fooddelivery.api.v1.dto.order.ChangeRatingDTO in project 2021-msk-food-delivery by netcracker-edu.

the class OrderServiceTest method changeCourierRatingSuccessTest.

@Test
public void changeCourierRatingSuccessTest() {
    User fakeUser = getFakeUserClient();
    ChangeRatingDTO fakeDto = new ChangeRatingDTO();
    fakeDto.setRating(new BigDecimal(4.5));
    Order fakeOrder = getFakeOrder();
    Mockito.when(orderRepo.save(Mockito.any(Order.class))).thenReturn(fakeOrder);
    orderService.changeDeliveryRating(fakeOrder, fakeDto, fakeUser);
    Assertions.assertTrue(fakeOrder.getDeliveryRating().equals(new BigDecimal(4.5)));
    Mockito.verify(orderRepo, Mockito.times(1)).save(fakeOrder);
}
Also used : Order(com.ncedu.fooddelivery.api.v1.entities.order.Order) ChangeRatingDTO(com.ncedu.fooddelivery.api.v1.dto.order.ChangeRatingDTO) BigDecimal(java.math.BigDecimal) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with ChangeRatingDTO

use of com.ncedu.fooddelivery.api.v1.dto.order.ChangeRatingDTO in project 2021-msk-food-delivery by netcracker-edu.

the class OrderServiceImpl1 method changeDeliveryRating.

@Override
public void changeDeliveryRating(Order order, ChangeRatingDTO dto, User user) {
    if (order.getCourier() == null)
        throw new CourierNotSetException();
    if (!user.getId().equals(order.getClient().getId()))
        throw new CustomAccessDeniedException();
    order.setDeliveryRating(dto.getRating());
    orderRepo.save(order);
}
Also used : CustomAccessDeniedException(com.ncedu.fooddelivery.api.v1.errors.security.CustomAccessDeniedException)

Example 4 with ChangeRatingDTO

use of com.ncedu.fooddelivery.api.v1.dto.order.ChangeRatingDTO in project 2021-msk-food-delivery by netcracker-edu.

the class OrderServiceImpl1 method changeClientRating.

@Override
public void changeClientRating(Order order, ChangeRatingDTO dto, User user) {
    if (order.getCourier() == null || !user.getId().equals(order.getCourier().getId()))
        throw new CustomAccessDeniedException();
    order.setClientRating(dto.getRating());
    orderRepo.save(order);
}
Also used : CustomAccessDeniedException(com.ncedu.fooddelivery.api.v1.errors.security.CustomAccessDeniedException)

Aggregations

ChangeRatingDTO (com.ncedu.fooddelivery.api.v1.dto.order.ChangeRatingDTO)2 Order (com.ncedu.fooddelivery.api.v1.entities.order.Order)2 CustomAccessDeniedException (com.ncedu.fooddelivery.api.v1.errors.security.CustomAccessDeniedException)2 Test (org.junit.jupiter.api.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 BigDecimal (java.math.BigDecimal)1 Executable (org.junit.jupiter.api.function.Executable)1