This commit is contained in:
2026-08-28 10:03:32 +08:00
parent dd117b8fc2
commit a6f266687e
13 changed files with 147 additions and 16 deletions
@@ -72,8 +72,11 @@ class InventoryCommandServiceTest {
verify(balances).updateById(balance.capture());
assertEquals(12L, balance.getValue().getAvailablePackages());
assertEquals("SKU-1", balance.getValue().getSkuCode());
assertEquals("Customer 100", balance.getValue().getCustomerName());
verify(positions).insert(any(InventoryPosition.class));
verify(ledgers).insert(any(InventoryLedger.class));
ArgumentCaptor<InventoryLedger> ledger = ArgumentCaptor.forClass(InventoryLedger.class);
verify(ledgers).insert(ledger.capture());
assertEquals("Customer 100", ledger.getValue().getCustomerName());
verify(operations).updateById(any(InventoryOperation.class));
}
@@ -152,6 +155,33 @@ class InventoryCommandServiceTest {
verify(ledgers).insert(any(InventoryLedger.class));
}
@Test
void stockInRejectsMissingCustomerSnapshotBeforeInventoryMutation() {
InventoryCommandRequests.StockIn request = new InventoryCommandRequests.StockIn(
"100", null, "WH-1", "WH1", "Warehouse 1", "DEST-1", "ONT8", "ONT8",
101L, "IN-1", "IN-CODE-1", "SKU-1", "Product 1", null, 300L, "PLT-1", null,
null, null, 1, "ORD-1", "EVT-1", "missing-customer", null);
assertThrows(ResponseStatusException.class, () -> service.stockIn("100", "7", request));
verify(balances, never()).insert(any(InventoryBalance.class));
verify(positions, never()).insert(any(InventoryPosition.class));
verify(ledgers, never()).insert(any(InventoryLedger.class));
}
@Test
void stockInRejectsCustomerSnapshotDrift() {
InventoryBalance balance = balance(200L, 4);
balance.setCustomerName("Frozen customer");
when(balances.lockDimension("100", "WH-1", "ONT8", 101L, "IN-CODE-1")).thenReturn(balance);
assertThrows(ResponseStatusException.class,
() -> service.stockIn("100", "7", stockIn("IN-1", "customer-drift", 1, 1)));
verify(positions, never()).insert(any(InventoryPosition.class));
verify(ledgers, never()).insert(any(InventoryLedger.class));
}
@Test
void holdRejectsWhenAvailablePackagesAreInsufficient() {
InventoryBalance balance = balance(200L, 5);
@@ -233,7 +263,8 @@ class InventoryCommandServiceTest {
private InventoryBalance balance(Long id, long available) {
InventoryBalance value = new InventoryBalance();
value.setId(id); value.setCustomerId("100"); value.setOverseasWarehouseId("WH-1");
value.setId(id); value.setCustomerId("100"); value.setCustomerName("Customer 100");
value.setOverseasWarehouseId("WH-1");
value.setDestinationWarehouseCode("ONT8"); value.setInboundOrderId(101L);
value.setInboundOrderNo("IN-1"); value.setInboundCode("IN-CODE-1");
value.setAvailablePackages(available);