use of com.ncedu.fooddelivery.api.v1.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class OrderServiceTest method createOrderTest.
@Test
public void createOrderTest() {
CreateOrderDTO fakeDTO = new CreateOrderDTO();
User fakeUser = getFakeUserClient();
HashMap<Long, Integer> fakeHashMap = new HashMap<>();
fakeHashMap.put(1L, 2);
fakeHashMap.put(2L, 3);
fakeHashMap.put(3L, 5);
fakeDTO.setProductAmountPairs(fakeHashMap);
fakeDTO.setOverallCost(380.0);
fakeDTO.setHighDemandCoeff(1.0);
fakeDTO.setDiscount(20.0);
fakeDTO.setAddress("address");
fakeDTO.setGeo(getFakeCoordsDTO());
fakeDTO.setWarehouseId(1L);
WarehouseInfoDTO fakeWarehouseInfoDTO = getFakeWarehouseInfoDTO();
List<Product> fakeProducts = getFakeProducts();
List<ProductPosition> fakePositions = getFakeProductPositions();
Mockito.when(courierRepo.countWorkingCouriersByWarehouse(Mockito.any(Long.class))).thenReturn((short) 100);
Mockito.when(courierRepo.countDeliveringCouriersByWarehouse(Mockito.any(Long.class))).thenReturn((short) 50);
Mockito.when(warehouseService.getNearestWarehouse(Mockito.any(BigDecimal.class), Mockito.any(BigDecimal.class))).thenReturn(fakeWarehouseInfoDTO);
Mockito.when(warehouseService.findById(1L)).thenReturn(getFakeWarehouse1());
Mockito.when(productPositionRepo.findByProductIdAndWarehouseIdWithLock(1L, 1L)).thenReturn(Arrays.asList(fakePositions.get(0), fakePositions.get(1)));
Mockito.when(productPositionRepo.findByProductIdAndWarehouseIdWithLock(2L, 1L)).thenReturn(Arrays.asList(fakePositions.get(2), fakePositions.get(3)));
Mockito.when(productPositionRepo.findByProductIdAndWarehouseIdWithLock(3L, 1L)).thenReturn(Arrays.asList(fakePositions.get(4), fakePositions.get(5)));
Mockito.when(productPositionRepo.findById(1L)).thenReturn(Optional.of(fakePositions.get(0)));
Mockito.when(productPositionRepo.findById(2L)).thenReturn(Optional.of(fakePositions.get(1)));
Mockito.when(productPositionRepo.findById(3L)).thenReturn(Optional.of(fakePositions.get(2)));
Mockito.when(productPositionRepo.findById(4L)).thenReturn(Optional.of(fakePositions.get(3)));
Mockito.when(productPositionRepo.findById(5L)).thenReturn(Optional.of(fakePositions.get(4)));
Mockito.when(productPositionRepo.findById(6L)).thenReturn(Optional.of(fakePositions.get(5)));
Mockito.when(productRepo.findById(1l)).thenReturn(Optional.of(fakeProducts.get(0)));
Mockito.when(productRepo.findById(2l)).thenReturn(Optional.of(fakeProducts.get(1)));
Mockito.when(productRepo.findById(3l)).thenReturn(Optional.of(fakeProducts.get(2)));
Mockito.when(orderRepo.save(Mockito.any(Order.class))).thenReturn(getFakeOrder());
Mockito.when(courierRepo.getWaitingCourierByWarehouse(1L)).thenReturn(Mockito.mock(Courier.class));
Mockito.when(orderProductPositionRepo.save(Mockito.any(OrderProductPosition.class))).thenReturn(Mockito.mock(OrderProductPosition.class));
orderService.createOrder(fakeDTO, fakeUser);
Mockito.verify(courierRepo, Mockito.times(1)).countWorkingCouriersByWarehouse(1L);
Mockito.verify(courierRepo, Mockito.times(1)).countDeliveringCouriersByWarehouse(1L);
Mockito.verify(productPositionRepo, Mockito.times(6)).findByProductIdAndWarehouseIdWithLock(Mockito.any(Long.class), Mockito.eq(1L));
Mockito.verify(warehouseService, Mockito.times(1)).getNearestWarehouse(Mockito.any(BigDecimal.class), Mockito.any(BigDecimal.class));
Mockito.verify(orderProductPositionRepo, Mockito.times(3)).save(Mockito.any(OrderProductPosition.class));
}
use of com.ncedu.fooddelivery.api.v1.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class OrderServiceTest method replaceCourierAccessExTest.
@Test
public void replaceCourierAccessExTest() {
User fakeUser = getFakeUserModerator();
Courier mockCourier = Mockito.mock(Courier.class);
Order fakeOrder = getFakeOrder();
fakeOrder.setWarehouse(getFakeWarehouse2());
Assertions.assertThrows(CustomAccessDeniedException.class, new Executable() {
@Override
public void execute() throws Throwable {
orderService.replaceCourier(fakeOrder, fakeUser);
}
});
}
use of com.ncedu.fooddelivery.api.v1.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class UserServiceTest method changeEmailSuccess.
@Test
public void changeEmailSuccess() {
Long userId = 1L;
User howard = UserUtils.courierHowardWolowitz(userId);
String newEmail = "happy-howard@bigbang.theory";
User howardWithNewEmail = UserUtils.courierHowardWolowitz(userId);
howardWithNewEmail.setEmail(newEmail);
when(userRepoMock.findByEmail(newEmail)).thenReturn(null);
when(userRepoMock.save(howardWithNewEmail)).thenReturn(howardWithNewEmail);
String password = "password";
EmailChangeDTO changeDTO = new EmailChangeDTO();
changeDTO.setEmail(newEmail);
changeDTO.setPassword(password);
boolean result = userService.changeEmail(howard, changeDTO);
assertTrue(result);
verify(userRepoMock, times(1)).findByEmail(newEmail);
verify(userRepoMock, times(1)).save(howardWithNewEmail);
}
use of com.ncedu.fooddelivery.api.v1.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class UserServiceTest method changeFullNameSuccess.
@Test
public void changeFullNameSuccess() {
Long userId = 1L;
User penny = UserUtils.clientPennyTeller(userId);
String newFullName = "Penny Hofstadter";
User pennyWithNewFullName = UserUtils.clientPennyTeller(userId);
pennyWithNewFullName.setFullName(newFullName);
when(userRepoMock.findById(userId)).thenReturn(Optional.of(penny));
when(userRepoMock.save(pennyWithNewFullName)).thenReturn(pennyWithNewFullName);
boolean result = userService.changeFullName(userId, newFullName);
assertTrue(result);
verify(userRepoMock, times(1)).findById(userId);
verify(userRepoMock, times(1)).save(pennyWithNewFullName);
}
use of com.ncedu.fooddelivery.api.v1.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());
}
Aggregations