Search in sources :

Example 1 with Order

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

the class OrderServiceTest method replaceCourierReplaceExTest.

@Test
public void replaceCourierReplaceExTest() {
    User fakeUser = getFakeUserModerator();
    Courier mockCourier = Mockito.mock(Courier.class);
    Order fakeOrder = getFakeOrder();
    fakeOrder.setStatus(OrderStatus.DELIVERED);
    Assertions.assertThrows(CourierReplaceException.class, new Executable() {

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

Example 2 with Order

use of com.ncedu.fooddelivery.api.v1.entities.order.Order 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 3 with Order

use of com.ncedu.fooddelivery.api.v1.entities.order.Order 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 4 with Order

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

the class OrderServiceImpl1 method buildOrder.

private Order buildOrder(User user, Geometry coords, CreateOrderDTO dto, Map<Long, Double> productPosPriceMap, Map<Long, Integer> productPosAmountMap) {
    Order order = new Order();
    order.setDiscount(dto.getDiscount());
    order.setHighDemandCoeff(dto.getHighDemandCoeff());
    order.setOverallCost(dto.getOverallCost());
    order.setClient(user.getClient());
    order.setWarehouse(warehouseService.findById(dto.getWarehouseId()));
    order.setAddress(dto.getAddress());
    order.setCoordinates(coords);
    order.setStatus(OrderStatus.CREATED);
    order.setDateStart(LocalDateTime.now());
    order = orderRepo.save(order);
    // adding records in DB table 'orders_product_positions'
    for (Long productPositionId : productPosAmountMap.keySet()) {
        orderProductPositionRepo.save(new OrderProductPosition(order, productPositionRepo.findById(productPositionId).get(), productPosAmountMap.get(productPositionId), productPosPriceMap.get(productPositionId)));
    }
    return orderRepo.save(order);
}
Also used : Order(com.ncedu.fooddelivery.api.v1.entities.order.Order) OrderProductPosition(com.ncedu.fooddelivery.api.v1.entities.orderProductPosition.OrderProductPosition)

Example 5 with Order

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

the class OrderServiceImpl1 method convertToOrderInfoDTO.

public OrderInfoDTO convertToOrderInfoDTO(Order order) {
    List<OrderProductPosition> orderProductPositions = orderProductPositionRepo.findAllByOrder(order);
    List<OrderInfoDTO.ProductAmountPair> products = new ArrayList<>();
    for (OrderProductPosition orderProductPosition : orderProductPositions) {
        ProductDTO p = productMapper.mapToDTO(orderProductPosition.getProductPosition().getProduct());
        Integer amount = orderProductPosition.getAmount();
        products.add(new OrderInfoDTO.ProductAmountPair(p, amount));
    }
    return new OrderInfoDTO(order.getId(), order.getClient(), order.getAddress(), order.getCoordinates(), order.getWarehouse(), order.getCourier(), order.getStatus(), order.getDateStart(), order.getDateEnd(), order.getOverallCost(), order.getHighDemandCoeff(), order.getDiscount(), order.getPromoCodeId(), order.getClientRating(), order.getDeliveryRating(), products);
}
Also used : OrderProductPosition(com.ncedu.fooddelivery.api.v1.entities.orderProductPosition.OrderProductPosition) ProductDTO(com.ncedu.fooddelivery.api.v1.dto.product.ProductDTO)

Aggregations

Order (com.ncedu.fooddelivery.api.v1.entities.order.Order)19 Test (org.junit.jupiter.api.Test)10 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)10 CustomAccessDeniedException (com.ncedu.fooddelivery.api.v1.errors.security.CustomAccessDeniedException)7 Executable (org.junit.jupiter.api.function.Executable)7 OrderProductPosition (com.ncedu.fooddelivery.api.v1.entities.orderProductPosition.OrderProductPosition)6 ProductPosition (com.ncedu.fooddelivery.api.v1.entities.productPosition.ProductPosition)4 ProductPositionsShipmentDTO (com.ncedu.fooddelivery.api.v1.dto.ProductPositionDTOs.ProductPositionsShipmentDTO)2 com.ncedu.fooddelivery.api.v1.dto.areCreatedDTO (com.ncedu.fooddelivery.api.v1.dto.areCreatedDTO)2 ChangeOrderStatusDTO (com.ncedu.fooddelivery.api.v1.dto.order.ChangeOrderStatusDTO)2 ChangeRatingDTO (com.ncedu.fooddelivery.api.v1.dto.order.ChangeRatingDTO)2 ProductDTO (com.ncedu.fooddelivery.api.v1.dto.product.ProductDTO)2 Warehouse (com.ncedu.fooddelivery.api.v1.entities.Warehouse)2 NotFoundEx (com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx)2 CourierAvailabilityEx (com.ncedu.fooddelivery.api.v1.errors.orderRegistration.CourierAvailabilityEx)2 Coordinate (com.vividsolutions.jts.geom.Coordinate)2 Geometry (com.vividsolutions.jts.geom.Geometry)2 CoordsDTO (com.ncedu.fooddelivery.api.v1.dto.CoordsDTO)1 ProductPositionsFromOrderDTO (com.ncedu.fooddelivery.api.v1.dto.ProductPositionDTOs.ProductPositionsFromOrderDTO)1 com.ncedu.fooddelivery.api.v1.dto.order (com.ncedu.fooddelivery.api.v1.dto.order)1