优化
This commit is contained in:
+9
-5
@@ -1,6 +1,7 @@
|
||||
package com.baiyue.warehouse.controller;
|
||||
|
||||
import com.baiyue.common.core.exception.BizException;
|
||||
import com.baiyue.common.core.api.PageResult;
|
||||
import com.baiyue.warehouse.dto.PalletRequests;
|
||||
import com.baiyue.warehouse.service.PalletApplicationService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -39,17 +40,20 @@ class InternalPalletControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void listsAllWarehouseSnapshotsFromPlatformScope() {
|
||||
void pagesWarehouseCandidatesFromPlatformScope() {
|
||||
List<PalletRequests.Snapshot> expected = List.of(snapshot(30L, "TP-001"), snapshot(31L, "TP-002"));
|
||||
when(service.snapshots(0L, 20L)).thenReturn(expected);
|
||||
PalletRequests.SnapshotPageQuery query = new PalletRequests.SnapshotPageQuery(2, 20, "TP");
|
||||
PageResult<PalletRequests.Snapshot> page = new PageResult<>(expected, 2, 20, 1000, 50);
|
||||
when(service.snapshotCandidates(0L, 20L, query)).thenReturn(page);
|
||||
|
||||
assertThat(controller.snapshots(TOKEN, 20L).data()).isEqualTo(expected);
|
||||
verify(service).snapshots(0L, 20L);
|
||||
assertThat(controller.snapshots(TOKEN, 20L, 2, 20, "TP").data()).isEqualTo(page);
|
||||
verify(service).snapshotCandidates(0L, 20L, query);
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsInvalidInternalToken() {
|
||||
assertThatThrownBy(() -> controller.snapshots("invalid", 20L)).isInstanceOf(BizException.class);
|
||||
assertThatThrownBy(() -> controller.snapshots("invalid", 20L, 1, 20, null))
|
||||
.isInstanceOf(BizException.class);
|
||||
verifyNoInteractions(service);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,10 @@ class PalletOpenApiContractTest {
|
||||
assertThat(yaml)
|
||||
.contains("/internal/warehouse/v1/pallets/{palletId}/snapshot:")
|
||||
.contains("/internal/warehouse/v1/pallets/snapshots:")
|
||||
.contains("name: keyword")
|
||||
.contains("maximum: 100")
|
||||
.contains("maxItems: 100")
|
||||
.contains("PalletSnapshotPageResponse:")
|
||||
.contains("required: [palletId, palletCode, palletType, capacityCbm, tareWeightKg]")
|
||||
.contains("additionalProperties: false")
|
||||
.doesNotContain("tenantId:")
|
||||
|
||||
@@ -64,6 +64,26 @@ class PalletRepositoryTest {
|
||||
.containsExactlyInAnyOrder(10001L, 20L, 30L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void candidatePageIsWarehouseScopedKeywordFilteredAndBounded() {
|
||||
when(mapper.selectPage(any(Page.class), any())).thenAnswer(invocation -> invocation.getArgument(0));
|
||||
|
||||
repository.candidatePage(0L, 20L,
|
||||
new PalletRequests.SnapshotPageQuery(3, 100, " TP-9 "));
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
ArgumentCaptor<Page<PalletEntity>> page = ArgumentCaptor.forClass(Page.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
ArgumentCaptor<LambdaQueryWrapper<PalletEntity>> wrapper =
|
||||
ArgumentCaptor.forClass(LambdaQueryWrapper.class);
|
||||
verify(mapper).selectPage(page.capture(), wrapper.capture());
|
||||
wrapper.getValue().getSqlSegment();
|
||||
assertThat(page.getValue().getCurrent()).isEqualTo(3);
|
||||
assertThat(page.getValue().getSize()).isEqualTo(100);
|
||||
assertThat(wrapper.getValue().getParamNameValuePairs().values())
|
||||
.contains(0L, 20L, "%TP-9%");
|
||||
}
|
||||
|
||||
private Collection<Object> queryValues(Long tenantId, Long warehouseId) {
|
||||
when(mapper.selectPage(any(Page.class), any())).thenAnswer(invocation -> invocation.getArgument(0));
|
||||
repository.page(tenantId,
|
||||
|
||||
+25
-3
@@ -18,6 +18,7 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
@SpringJUnitConfig(PalletApplicationService.class)
|
||||
class PalletApplicationServiceTest {
|
||||
@@ -64,21 +65,42 @@ class PalletApplicationServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void returnsReusablePalletSnapshotsWithoutResourceStatus() {
|
||||
void returnsControlledReusablePalletCandidatePage() {
|
||||
WarehouseEntity warehouse = new WarehouseEntity();
|
||||
warehouse.setWarehouseType("DOMESTIC");
|
||||
warehouse.setStatus("ACTIVE");
|
||||
when(warehouseRepository.findOwned(0L, 20L)).thenReturn(warehouse);
|
||||
PalletEntity entity = pallet();
|
||||
entity.setPalletCode("TP-001");
|
||||
entity.setPalletType("STANDARD");
|
||||
entity.setCapacityCbm(new BigDecimal("1.200000"));
|
||||
entity.setWeightKg(new BigDecimal("8.000"));
|
||||
when(repository.findAllByWarehouse(0L, 20L)).thenReturn(java.util.List.of(entity));
|
||||
PalletRequests.SnapshotPageQuery query = new PalletRequests.SnapshotPageQuery(1, 20, "TP-0");
|
||||
when(repository.candidatePage(0L, 20L, query)).thenReturn(
|
||||
new PageResult<>(List.of(entity), 1, 20, 1000, 50));
|
||||
|
||||
org.assertj.core.api.Assertions.assertThat(service.snapshots(0L, 20L)).singleElement().satisfies(snapshot -> {
|
||||
PageResult<PalletRequests.Snapshot> result = service.snapshotCandidates(0L, 20L, query);
|
||||
|
||||
org.assertj.core.api.Assertions.assertThat(result.records()).singleElement().satisfies(snapshot -> {
|
||||
org.assertj.core.api.Assertions.assertThat(snapshot.palletId()).isEqualTo(30L);
|
||||
org.assertj.core.api.Assertions.assertThat(snapshot.tareWeightKg()).isEqualByComparingTo("8.000");
|
||||
});
|
||||
org.assertj.core.api.Assertions.assertThat(result.total()).isEqualTo(1000);
|
||||
org.assertj.core.api.Assertions.assertThat(result.records()).hasSize(1);
|
||||
verify(repository).candidatePage(0L, 20L, query);
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsCandidatesFromInactiveWarehouse() {
|
||||
WarehouseEntity warehouse = new WarehouseEntity();
|
||||
warehouse.setWarehouseType("DOMESTIC");
|
||||
warehouse.setStatus("INACTIVE");
|
||||
when(warehouseRepository.findOwned(0L, 20L)).thenReturn(warehouse);
|
||||
|
||||
assertThatThrownBy(() -> service.snapshotCandidates(
|
||||
0L, 20L, new PalletRequests.SnapshotPageQuery(1, 20, null)))
|
||||
.isInstanceOf(BizException.class)
|
||||
.hasMessageContaining("启用中");
|
||||
}
|
||||
|
||||
private static PalletEntity pallet() {
|
||||
|
||||
Reference in New Issue
Block a user