This commit is contained in:
2026-08-20 18:06:07 +08:00
parent c9a05b108b
commit a38396ce3f
26 changed files with 532 additions and 21 deletions
@@ -18,7 +18,7 @@ class InventoryQueryControllerTest {
private final InventoryQueryService service = mock(InventoryQueryService.class);
private final InventoryQueryController controller = controller();
private final InventoryQueryRequests.BalanceQuery query = new InventoryQueryRequests.BalanceQuery(
1, 20, null, null, null, null, null, null, null, null);
1, 20, null, null, null, null, null, null, null, null, null, null, null, null);
@Test
void merchantCannotOverrideCustomerScope() {
@@ -6,6 +6,8 @@ import com.baiyue.lastleg.inventory.query.dto.InventoryDashboardResponse;
import com.baiyue.lastleg.inventory.query.dto.InventoryQueryRequests;
import com.baiyue.lastleg.inventory.query.mapper.InventoryQueryMapper;
import com.baiyue.lastleg.inventory.query.model.InventoryAggregateProjection;
import com.baiyue.lastleg.inventory.query.model.InventoryLocationFact;
import com.baiyue.lastleg.inventory.query.model.InventorySkuFact;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.test.util.ReflectionTestUtils;
@@ -58,9 +60,21 @@ class InventoryQueryServiceTest {
balance.setCustomerId("100");
when(mapper.countBalances("100", query)).thenReturn(1L);
when(mapper.balances("100", query, 0, 20)).thenReturn(List.of(balance));
InventorySkuFact sku = new InventorySkuFact();
sku.setBalanceId(1L);
sku.setSkuCode("SKU-1");
sku.setProductName("测试产品");
InventoryLocationFact location = new InventoryLocationFact();
location.setBalanceId(1L);
location.setWarehouseLocationCode(null);
when(mapper.skuFacts("100", List.of(1L))).thenReturn(List.of(sku));
when(mapper.locationFacts("100", List.of(1L))).thenReturn(List.of(location));
service.balances("100", query);
var result = service.balances("100", query);
assertEquals(List.of("SKU-1"), result.records().get(0).skuCodes());
assertEquals(List.of("测试产品"), result.records().get(0).productNames());
assertEquals(List.of(), result.records().get(0).warehouseLocationCodes());
verify(mapper).countBalances("100", query);
verify(mapper).balances("100", query, 0, 20);
}
@@ -106,6 +120,7 @@ class InventoryQueryServiceTest {
void reversedLedgerDateRangeIsRejected() {
InventoryQueryRequests.LedgerQuery query = new InventoryQueryRequests.LedgerQuery(
1, 20, null, null, null, null, null, null, null, null, null,
null, null,
java.time.LocalDateTime.of(2026, 8, 18, 0, 0),
java.time.LocalDateTime.of(2026, 8, 17, 0, 0));
@@ -120,12 +135,12 @@ class InventoryQueryServiceTest {
String csv = new String(service.exportBalances("100", query), StandardCharsets.UTF_8);
assertTrue(csv.contains("inboundOrderNo,inboundCode,totalPackages"));
assertFalse(csv.contains("skuCode"));
assertTrue(csv.contains("inboundOrderNo,inboundCode,skuCodes"));
assertFalse(csv.contains("Quantity"));
}
private static InventoryQueryRequests.BalanceQuery balanceQuery(String status) {
return new InventoryQueryRequests.BalanceQuery(1, 20, null, null, null, null, null, null, null, status);
return new InventoryQueryRequests.BalanceQuery(1, 20, null, null, null, null, null, null, null,
null, null, null, null, status);
}
}