Merge branch 'dev-lyhfive' of http://git.buggoglobal.com/java-project/baiyue-firstleg into dev
This commit is contained in:
+46
@@ -24,6 +24,8 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
@@ -57,6 +59,7 @@ class InventoryCommandServiceTest {
|
||||
ReflectionTestUtils.setField(service, "warehouseGateway", warehouseGateway);
|
||||
ReflectionTestUtils.setField(service, "objectMapper", new ObjectMapper());
|
||||
lenient().when(operations.findIdempotency(any(), any())).thenReturn(null);
|
||||
lenient().when(commands.lockInboundTransitBalances(any(), any(), any())).thenReturn(List.of());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -117,6 +120,7 @@ class InventoryCommandServiceTest {
|
||||
balance.setSkuCode("SKU-1");
|
||||
balance.setInTransitPackages(12L);
|
||||
when(balances.lockDimension("100", "WH-1", "ONT8", 101L, "IN-CODE-1")).thenReturn(balance);
|
||||
when(commands.lockInboundTransitBalances("100", 101L, "IN-CODE-1")).thenReturn(List.of(balance));
|
||||
|
||||
InventoryCommandResponse result = service.stockIn("100", "7", stockIn("IN-1", "stock-in-transit", 12, 24));
|
||||
|
||||
@@ -125,6 +129,48 @@ class InventoryCommandServiceTest {
|
||||
assertEquals(12L, balance.getAvailablePackages());
|
||||
}
|
||||
|
||||
@Test
|
||||
void stockInTransfersInTransitFromTheOriginalOverseasWarehouse() {
|
||||
InventoryBalance target = balance(200L, 0);
|
||||
target.setSkuCode("SKU-1");
|
||||
target.setInTransitPackages(0L);
|
||||
InventoryBalance source = balance(201L, 0);
|
||||
source.setOverseasWarehouseId("WH-OLD");
|
||||
source.setSkuCode("SKU-1");
|
||||
source.setInTransitPackages(12L);
|
||||
when(balances.lockDimension("100", "WH-1", "ONT8", 101L, "IN-CODE-1")).thenReturn(target);
|
||||
when(commands.lockInboundTransitBalances("100", 101L, "IN-CODE-1")).thenReturn(List.of(source));
|
||||
|
||||
InventoryCommandResponse result = service.stockIn("100", "7",
|
||||
stockIn("IN-1", "stock-in-cross-warehouse", 12, 24));
|
||||
|
||||
assertEquals(12, result.availablePackages());
|
||||
assertEquals(0L, source.getInTransitPackages());
|
||||
ArgumentCaptor<InventoryLedger> written = ArgumentCaptor.forClass(InventoryLedger.class);
|
||||
verify(ledgers, times(2)).insert(written.capture());
|
||||
assertEquals("STOCK_IN_TRANSIT_RELEASE", written.getAllValues().get(0).getBusinessType());
|
||||
assertEquals(-12L, written.getAllValues().get(0).getDeltaPackages());
|
||||
assertEquals("STOCK_IN", written.getAllValues().get(1).getBusinessType());
|
||||
assertEquals("IN_TRANSIT", written.getAllValues().get(1).getStatusFrom());
|
||||
}
|
||||
|
||||
@Test
|
||||
void stockInKeepsOutsideSourceWhenInTransitIsInsufficient() {
|
||||
InventoryBalance target = balance(200L, 0);
|
||||
target.setSkuCode("SKU-1");
|
||||
target.setInTransitPackages(2L);
|
||||
when(balances.lockDimension("100", "WH-1", "ONT8", 101L, "IN-CODE-1")).thenReturn(target);
|
||||
when(commands.lockInboundTransitBalances("100", 101L, "IN-CODE-1")).thenReturn(List.of(target));
|
||||
|
||||
service.stockIn("100", "7", stockIn("IN-1", "stock-in-partial-transit", 5, 10));
|
||||
|
||||
ArgumentCaptor<InventoryLedger> ledger = ArgumentCaptor.forClass(InventoryLedger.class);
|
||||
verify(ledgers).insert(ledger.capture());
|
||||
assertEquals("OUTSIDE", ledger.getValue().getStatusFrom());
|
||||
assertEquals(0L, target.getInTransitPackages());
|
||||
assertEquals(5L, target.getAvailablePackages());
|
||||
}
|
||||
|
||||
@Test
|
||||
void differentSkusShareInboundBalanceAndKeepSkuInLedger() {
|
||||
InventoryBalance balance = balance(200L, 4);
|
||||
|
||||
Reference in New Issue
Block a user