|
|
@@ -0,0 +1,92 @@
|
|
|
+package com.ruoyi.app.order;
|
|
|
+
|
|
|
+import com.ruoyi.app.order.dto.MultiStoreBatchCreateRequest;
|
|
|
+import com.ruoyi.app.order.dto.MultiStoreQuoteRequest;
|
|
|
+import com.ruoyi.app.order.dto.MultiStoreQuoteView;
|
|
|
+import com.ruoyi.common.core.redis.RedisCache;
|
|
|
+import com.ruoyi.system.domain.InfoAddress;
|
|
|
+import com.ruoyi.system.domain.OrderCheckoutBatch;
|
|
|
+import com.ruoyi.system.domain.OrderParent;
|
|
|
+import com.ruoyi.system.domain.PosFood;
|
|
|
+import com.ruoyi.system.domain.PosOrder;
|
|
|
+import com.ruoyi.system.domain.PosStore;
|
|
|
+import com.ruoyi.system.mapper.FoodSpecsValueMapper;
|
|
|
+import com.ruoyi.system.mapper.InfoAddressMapper;
|
|
|
+import com.ruoyi.system.mapper.OrderCheckoutMapper;
|
|
|
+import com.ruoyi.system.mapper.PosFoodMapper;
|
|
|
+import com.ruoyi.system.mapper.PosStoreMapper;
|
|
|
+import com.ruoyi.system.service.IOrderParentService;
|
|
|
+import com.ruoyi.system.service.IPosOrderService;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
+import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
|
+import static org.mockito.ArgumentMatchers.any;
|
|
|
+import static org.mockito.Mockito.mock;
|
|
|
+import static org.mockito.Mockito.never;
|
|
|
+import static org.mockito.Mockito.verify;
|
|
|
+import static org.mockito.Mockito.when;
|
|
|
+
|
|
|
+class MultiStoreCheckoutBatchServiceTest {
|
|
|
+ private final MultiStoreCheckoutQuoteService quotes = mock(MultiStoreCheckoutQuoteService.class);
|
|
|
+ private final OrderCheckoutMapper checkout = mock(OrderCheckoutMapper.class);
|
|
|
+ private final IOrderParentService parents = mock(IOrderParentService.class);
|
|
|
+ private final IPosOrderService orders = mock(IPosOrderService.class);
|
|
|
+ private final InfoAddressMapper addresses = mock(InfoAddressMapper.class);
|
|
|
+ private final PosStoreMapper stores = mock(PosStoreMapper.class);
|
|
|
+ private final PosFoodMapper foods = mock(PosFoodMapper.class);
|
|
|
+ private final FoodSpecsValueMapper values = mock(FoodSpecsValueMapper.class);
|
|
|
+ private final OrderPromotionHelper promotions = mock(OrderPromotionHelper.class);
|
|
|
+
|
|
|
+ private MultiStoreCheckoutBatchService subject() {
|
|
|
+ return new MultiStoreCheckoutBatchService(quotes, checkout, parents, orders,
|
|
|
+ addresses, stores, foods, values, promotions);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void createsHiddenUnpaidChildrenWithoutOpeningFulfilment() {
|
|
|
+ MultiStoreQuoteRequest requested = new MultiStoreQuoteRequest(10L, true, List.of(
|
|
|
+ new MultiStoreQuoteRequest.Store(1L, null, List.of(new MultiStoreQuoteRequest.Item(11L, 1, List.of())), null, null),
|
|
|
+ new MultiStoreQuoteRequest.Store(2L, null, List.of(new MultiStoreQuoteRequest.Item(22L, 1, List.of())), null, null)));
|
|
|
+ when(quotes.loadSnapshot("quote", 42L)).thenReturn(
|
|
|
+ new MultiStoreCheckoutQuoteService.QuoteSnapshot(42L, requested, "fingerprint", Long.MAX_VALUE));
|
|
|
+ when(quotes.quote(requested, 42L)).thenReturn(new MultiStoreQuoteView("other", Long.MAX_VALUE,
|
|
|
+ 7L, 1L, 1000, List.of(1L, 2L), List.of(
|
|
|
+ new MultiStoreQuoteView.StorePrice(1L, new BigDecimal("50"), new BigDecimal("50"),
|
|
|
+ new BigDecimal("40"), new BigDecimal("36"), new BigDecimal("86"), List.of("1")),
|
|
|
+ new MultiStoreQuoteView.StorePrice(2L, new BigDecimal("60"), new BigDecimal("60"),
|
|
|
+ new BigDecimal("40"), new BigDecimal("36"), new BigDecimal("96"), List.of("1"))),
|
|
|
+ List.of(), new BigDecimal("0.9"), "fingerprint"));
|
|
|
+ InfoAddress address = new InfoAddress(); address.setId(10L); address.setUserId(42L);
|
|
|
+ when(addresses.selectById(10L)).thenReturn(address);
|
|
|
+ for (int id : List.of(1, 2)) {
|
|
|
+ PosStore store = new PosStore(); store.setId(id); store.setUserId((long) id);
|
|
|
+ when(stores.selectById((long) id)).thenReturn(store);
|
|
|
+ PosFood food = new PosFood(); food.setId(id == 1 ? 11L : 22L);
|
|
|
+ food.setPrice(new BigDecimal(id == 1 ? "50" : "60")); food.setName("meal");
|
|
|
+ when(foods.selectById(food.getId())).thenReturn(food);
|
|
|
+ }
|
|
|
+ when(checkout.insertOrGetBatch(any(OrderCheckoutBatch.class))).thenAnswer(call -> {
|
|
|
+ OrderCheckoutBatch row = call.getArgument(0); row.setId(100L); return 1;
|
|
|
+ });
|
|
|
+ when(checkout.selectBatchById(100L)).thenAnswer(call -> created);
|
|
|
+ when(orders.save(any(PosOrder.class))).thenAnswer(call -> {
|
|
|
+ PosOrder order = call.getArgument(0); order.setId(order.getMdId()); return true;
|
|
|
+ });
|
|
|
+
|
|
|
+ MultiStoreCheckoutBatchService.BatchCreated result = subject().create(
|
|
|
+ new MultiStoreBatchCreateRequest("request-1", "quote", List.of(1L, 2L)), 42L);
|
|
|
+
|
|
|
+ assertEquals(100L, result.batchId());
|
|
|
+ assertEquals("PENDING", result.status());
|
|
|
+ assertEquals(2, result.members().size());
|
|
|
+ assertFalse(result.members().get(0).payType() != null);
|
|
|
+ verify(parents).save(any(OrderParent.class));
|
|
|
+ verify(checkout).insertGroup(any());
|
|
|
+ }
|
|
|
+
|
|
|
+ private OrderCheckoutBatch created;
|
|
|
+}
|