|
|
@@ -1,8 +1,10 @@
|
|
|
package com.etotem.cfc.service;
|
|
|
|
|
|
+import com.etotem.cfc.entity.OrderItem;
|
|
|
import com.etotem.cfc.entity.ProductOrder;
|
|
|
import com.etotem.cfc.entity.ProductSku;
|
|
|
import com.etotem.cfc.entity.ProductSkuComboItem;
|
|
|
+import com.etotem.cfc.mapper.OrderItemMapper;
|
|
|
import com.etotem.cfc.service.InventoryService;
|
|
|
import com.etotem.cfc.service.ProductOrderService;
|
|
|
import com.etotem.cfc.service.ProductService;
|
|
|
@@ -23,6 +25,7 @@ class ProductOrderComboStockTest {
|
|
|
private ProductSkuService skuService;
|
|
|
private ProductService productService;
|
|
|
private InventoryService inventoryService;
|
|
|
+ private OrderItemMapper orderItemMapper;
|
|
|
|
|
|
@BeforeEach
|
|
|
void setUp() {
|
|
|
@@ -30,9 +33,11 @@ class ProductOrderComboStockTest {
|
|
|
skuService = mock(ProductSkuService.class);
|
|
|
productService = mock(ProductService.class);
|
|
|
inventoryService = mock(InventoryService.class);
|
|
|
+ orderItemMapper = mock(OrderItemMapper.class);
|
|
|
ReflectionTestUtils.setField(orderService, "productSkuService", skuService);
|
|
|
ReflectionTestUtils.setField(orderService, "productService", productService);
|
|
|
ReflectionTestUtils.setField(orderService, "inventoryService", inventoryService);
|
|
|
+ ReflectionTestUtils.setField(orderService, "orderItemMapper", orderItemMapper);
|
|
|
}
|
|
|
|
|
|
private ProductSku combo() {
|
|
|
@@ -102,4 +107,23 @@ class ProductOrderComboStockTest {
|
|
|
// 父商品(order.productId)不得回补:本用例未设置 productId,仍断言未调用
|
|
|
verify(productService, never()).increaseStock(null, 3);
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void deductComboStock_mixedOrder_usesComboLineQuantity() {
|
|
|
+ ProductOrder o = order();
|
|
|
+ o.setQuantity(6); // 订单总数量含其他行,组合行自身仅 1
|
|
|
+ OrderItem comboLine = new OrderItem();
|
|
|
+ comboLine.setSkuId(9L);
|
|
|
+ comboLine.setQuantity(1);
|
|
|
+ when(orderItemMapper.selectList(any())).thenReturn(java.util.Collections.singletonList(comboLine));
|
|
|
+ when(skuService.decreaseStock(100L, 2)).thenReturn(true); // 2(组合unit) × 1(行数量)
|
|
|
+ when(productService.decreaseStock(11L, 1)).thenReturn(true);
|
|
|
+
|
|
|
+ orderService.deductComboStock(combo(), o, "PO1");
|
|
|
+
|
|
|
+ verify(skuService).decreaseStock(100L, 2);
|
|
|
+ verify(inventoryService).recordOutbound(10L, 100L, 2, "order", 77L, null, "组合出库:PO1");
|
|
|
+ verify(productService).decreaseStock(11L, 1);
|
|
|
+ verify(inventoryService).recordOutbound(11L, null, 1, "order", 77L, null, "组合出库:PO1");
|
|
|
+ }
|
|
|
}
|