修改提交
This commit is contained in:
+33
-14
@@ -16,6 +16,11 @@ import com.baiyue.lastleg.relabel.mapper.RelabelItemMapper;
|
||||
import com.baiyue.lastleg.relabel.mapper.RelabelStatusHistoryMapper;
|
||||
import com.baiyue.lastleg.service.LastlegOrderNoGenerator;
|
||||
import com.baiyue.lastleg.wallet.WalletCommandOutboxService;
|
||||
import com.baiyue.lastleg.inventory.command.service.InventoryCommandService;
|
||||
import com.baiyue.lastleg.inventory.entity.InventoryBalance;
|
||||
import com.baiyue.lastleg.inventory.entity.InventoryPosition;
|
||||
import com.baiyue.lastleg.inventory.mapper.InventoryBalanceMapper;
|
||||
import com.baiyue.lastleg.inventory.mapper.InventoryPositionMapper;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -50,6 +55,9 @@ class RelabelApplicationServiceTest {
|
||||
@Mock LastlegOrderMapper orders;
|
||||
@Mock LastlegOrderStatusHistoryMapper orderHistories;
|
||||
@Mock WalletCommandOutboxService walletCommands;
|
||||
@Mock InventoryCommandService inventoryCommands;
|
||||
@Mock InventoryBalanceMapper inventoryBalances;
|
||||
@Mock InventoryPositionMapper inventoryPositions;
|
||||
@Spy LastlegOrderNoGenerator orderNoGenerator = new LastlegOrderNoGenerator();
|
||||
|
||||
private RelabelApplicationService service;
|
||||
@@ -64,8 +72,19 @@ class RelabelApplicationServiceTest {
|
||||
ReflectionTestUtils.setField(service, "orderHistories", orderHistories);
|
||||
ReflectionTestUtils.setField(service, "orderNoGenerator", orderNoGenerator);
|
||||
ReflectionTestUtils.setField(service, "walletCommands", walletCommands);
|
||||
ReflectionTestUtils.setField(service, "inventoryCommands", inventoryCommands);
|
||||
ReflectionTestUtils.setField(service, "inventoryBalances", inventoryBalances);
|
||||
ReflectionTestUtils.setField(service, "inventoryPositions", inventoryPositions);
|
||||
ReflectionTestUtils.setField(service, "objectMapper", mapper());
|
||||
lenient().when(walletCommands.publish(any(), any(Long.class), any(), any(), any(), any(), any(Long.class))).thenReturn("wallet-event-1");
|
||||
lenient().when(inventoryPositions.findTenantPosition(any(), any())).thenAnswer(invocation -> {
|
||||
InventoryPosition value = new InventoryPosition(); value.setId(invocation.getArgument(1));
|
||||
value.setBalanceId(101L); value.setAvailablePackages(100L); return value;
|
||||
});
|
||||
InventoryBalance balance = new InventoryBalance(); balance.setId(101L); balance.setCustomerId("10001");
|
||||
balance.setOverseasWarehouseId("WH-1"); balance.setInboundOrderId(301L); balance.setInboundOrderNo("IN-1");
|
||||
balance.setInboundCode("CODE-1"); balance.setSkuCode("SKU-A"); balance.setProductNameZh("Chinese name");
|
||||
lenient().when(inventoryBalances.selectById(any(Long.class))).thenReturn(balance);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -129,17 +148,17 @@ class RelabelApplicationServiceTest {
|
||||
RelabelRequests.Create request = new RelabelRequests.Create("CUSTOMER-1", "WH-1",
|
||||
LocalDateTime.of(2026, 8, 20, 10, 0), "Li", "13800000000", BigDecimal.ONE, null, "key-marks",
|
||||
List.of(attachedItem));
|
||||
RelabelApplication persisted = application(11L, "FBR-1", "100", "key-files", null,
|
||||
RelabelApplication persisted = application(11L, "FBR-1", "10001", "key-files", null,
|
||||
RelabelApplicationService.PENDING_PROCESSING);
|
||||
persisted.setLastlegOrderId(21L); persisted.setItemCount(1); persisted.setTotalPackageCount(2);
|
||||
persisted.setNotifiedPackageCount(2);
|
||||
when(applications.findNo(eq("100"), any())).thenReturn(persisted);
|
||||
when(applications.findNo(eq("10001"), any())).thenReturn(persisted);
|
||||
when(items.selectList(any())).thenReturn(List.of(item(31L, 11L, "SKU-A", 2, 2)));
|
||||
when(histories.selectList(any())).thenReturn(List.of());
|
||||
when(orders.selectById(21L)).thenReturn(order(21L, "100", "LMO-RELABEL-1",
|
||||
when(orders.selectById(21L)).thenReturn(order(21L, "10001", "LMO-RELABEL-1",
|
||||
RelabelApplicationService.PENDING_PROCESSING));
|
||||
|
||||
service.create("100", "operator-1", request);
|
||||
service.create("10001", "operator-1", request);
|
||||
|
||||
ArgumentCaptor<RelabelItem> saved = ArgumentCaptor.forClass(RelabelItem.class);
|
||||
verify(items).insert(saved.capture());
|
||||
@@ -149,10 +168,10 @@ class RelabelApplicationServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void createGroupsCartonsIntoOneTailOrderPerDestinationWarehouse() {
|
||||
void createKeepsOneOperationWarehouseWhenItemsHaveDifferentFbaDestinations() {
|
||||
RelabelRequests.Item west = carton("SKU-A", "BOX-1", "FBA-1", "ONT8");
|
||||
RelabelRequests.Item east = carton("SKU-B", "BOX-2", "FBA-2", "ABE8");
|
||||
RelabelRequests.Create request = new RelabelRequests.Create("CUSTOMER-1", null,
|
||||
RelabelRequests.Create request = new RelabelRequests.Create("CUSTOMER-1", "WH-1",
|
||||
LocalDateTime.of(2026, 8, 20, 10, 0), "Li", "13800000000", BigDecimal.ONE, null, "key-multi",
|
||||
List.of(west, east));
|
||||
RelabelApplication persisted = application(11L, "FBR-1", "10001", "key-multi", null,
|
||||
@@ -167,10 +186,9 @@ class RelabelApplicationServiceTest {
|
||||
service.create("10001", "operator-1", request);
|
||||
|
||||
ArgumentCaptor<LastlegOrder> created = ArgumentCaptor.forClass(LastlegOrder.class);
|
||||
verify(orders, times(2)).insert(created.capture());
|
||||
assertEquals(List.of("ONT8", "ABE8"), created.getAllValues().stream()
|
||||
.map(LastlegOrder::getOverseasWarehouseId).toList());
|
||||
assertTrue(created.getAllValues().stream().allMatch(value -> value.getPackageCount() == 1));
|
||||
verify(orders).insert(created.capture());
|
||||
assertEquals("WH-1", created.getValue().getOverseasWarehouseId());
|
||||
assertEquals(2, created.getValue().getPackageCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -189,7 +207,7 @@ class RelabelApplicationServiceTest {
|
||||
@Test
|
||||
void createAllowsCartonWithoutSku() {
|
||||
RelabelRequests.Item withoutSku = carton(null, "BOX-NO-SKU", "FBA-NO-SKU", "ONT8");
|
||||
RelabelRequests.Create request = new RelabelRequests.Create("CUSTOMER-NO-SKU", null,
|
||||
RelabelRequests.Create request = new RelabelRequests.Create("CUSTOMER-NO-SKU", "WH-1",
|
||||
LocalDateTime.of(2026, 9, 10, 10, 0), "Li", "13800000000", BigDecimal.ONE,
|
||||
null, "key-no-sku", List.of(withoutSku));
|
||||
RelabelApplication persisted = application(11L, "FBR-1", "10001", "key-no-sku", null,
|
||||
@@ -314,9 +332,10 @@ class RelabelApplicationServiceTest {
|
||||
|
||||
private static RelabelRequests.Item carton(String sku, String cartonMark, String fbaCartonMark,
|
||||
String destinationWarehouseId) {
|
||||
return new RelabelRequests.Item(sku, null, null, null, "Chinese name", 1, 1,
|
||||
"SHP-1", null, sku + "-NEW", null, null, null, null, null,
|
||||
cartonMark, fbaCartonMark, destinationWarehouseId);
|
||||
long positionId = "ABE8".equals(destinationWarehouseId) ? 202L : 201L;
|
||||
return new RelabelRequests.Item(101L, positionId, 301L, sku, null, null, null,
|
||||
"Chinese name", 1, 1, "SHP-1", null, sku + "-NEW", null, null,
|
||||
null, null, null, cartonMark, fbaCartonMark, destinationWarehouseId);
|
||||
}
|
||||
|
||||
private static RelabelApplication application(long id, String no, String customerId, String key, String requestHash,
|
||||
|
||||
Reference in New Issue
Block a user