Merge remote-tracking branch 'origin/test' into dev
# Conflicts: # scripts/admin-test-env-modules/phase3-producer-chain-contract.test.mjs # scripts/admin-test-env-modules/phase4-overseas-warehouse-contract.test.mjs
This commit is contained in:
@@ -44,6 +44,7 @@ import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.clearInvocations;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -579,6 +580,28 @@ class InboundMeasurementServiceTest {
|
||||
assertThat(result.slotStatus()).isEqualTo("BOUND");
|
||||
}
|
||||
|
||||
@Test
|
||||
void locationAllocationFailureDoesNotBlockWeightConfirmation() {
|
||||
InboundOrderEntity inbound = inbound("WAIT_MEASURE");
|
||||
InboundWeightResultEntity weight = weight(20L, "30.000", "KG", "PENDING_CONFIRM", 0);
|
||||
when(repository.findInbound(1L, 10L)).thenReturn(inbound);
|
||||
when(repository.findWeight(1L, 10L, 20L)).thenReturn(weight);
|
||||
when(repository.updateWeight(weight)).thenReturn(true);
|
||||
when(repository.listWeights(1L, 10L)).thenReturn(List.of(weight));
|
||||
doThrow(new IllegalStateException("warehouse unavailable"))
|
||||
.when(locationOccupation).ensureForConfirmedWeight(1L, 10L, 9L, 20L, 1);
|
||||
|
||||
InboundMeasurementResponses.WeightResult result = service.confirmWeightResult(
|
||||
1L, 10L, 20L, 9L, "操作员",
|
||||
new InboundMeasurementRequests.ConfirmWeightResultRequest(0, null, null, null));
|
||||
|
||||
assertThat(result.recognitionStatus()).isEqualTo("CONFIRMED");
|
||||
assertThat(result.grossWeightKg()).isEqualByComparingTo("30.000");
|
||||
assertThat(result.locationCode()).isNull();
|
||||
verify(repository).insertRevision(any(InboundWeightRevisionEntity.class));
|
||||
verify(repository).updateInboundWeightSummary(inbound);
|
||||
}
|
||||
|
||||
@Test
|
||||
void confirmingFifthPalletSeparatelyAggregatesGrossAndCargoNetWeight() {
|
||||
InboundOrderEntity inbound = inbound("WAIT_MEASURE");
|
||||
|
||||
+58
-1
@@ -320,7 +320,7 @@ class MeasurementLocationOccupationServiceTest {
|
||||
when(measurements.listWeights(BUSINESS_TENANT, INBOUND)).thenReturn(weights);
|
||||
when(allocations.list(BUSINESS_TENANT, INBOUND)).thenReturn(List.of(first, second));
|
||||
|
||||
service.requireOccupied(BUSINESS_TENANT, INBOUND);
|
||||
service.ensureForSubmission(BUSINESS_TENANT, INBOUND, OPERATOR);
|
||||
|
||||
verify(warehouse, never()).reserveBlock(org.mockito.ArgumentMatchers.anyString(),
|
||||
org.mockito.ArgumentMatchers.any());
|
||||
@@ -330,6 +330,51 @@ class MeasurementLocationOccupationServiceTest {
|
||||
org.mockito.ArgumentMatchers.any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void submissionReconcilesMissingBlockFromLatestConfirmedWeight() {
|
||||
InboundOrderEntity inbound = inbound();
|
||||
inbound.setActualVolumeCbm(new BigDecimal("2.5000"));
|
||||
List<InboundWeightResultEntity> weights = confirmedWeights().subList(0, 1);
|
||||
when(workflow.findOwned(BUSINESS_TENANT, INBOUND)).thenReturn(inbound);
|
||||
when(measurements.listWeights(BUSINESS_TENANT, INBOUND)).thenReturn(weights);
|
||||
when(warehouse.reserveBlock(org.mockito.ArgumentMatchers.eq("internal-token"),
|
||||
org.mockito.ArgumentMatchers.any())).thenReturn(ApiResponse.success(block("RESERVED", 3)));
|
||||
when(warehouse.confirmBlock(org.mockito.ArgumentMatchers.eq("internal-token"),
|
||||
org.mockito.ArgumentMatchers.any())).thenReturn(ApiResponse.success(block("OCCUPIED", 3)));
|
||||
when(allocations.list(BUSINESS_TENANT, INBOUND))
|
||||
.thenReturn(List.of(), blockSlotsBoundTo(weights));
|
||||
|
||||
service.ensureForSubmission(BUSINESS_TENANT, INBOUND, OPERATOR);
|
||||
|
||||
verify(warehouse).reserveBlock(org.mockito.ArgumentMatchers.eq("internal-token"),
|
||||
org.mockito.ArgumentMatchers.argThat(request -> request.requiredSlotCount() == 3));
|
||||
verify(allocations).bindConfirmedWeights(BUSINESS_TENANT, INBOUND, weights);
|
||||
}
|
||||
|
||||
@Test
|
||||
void submissionExpandsUndersizedBlockWhenMeasuredVolumeGrows() {
|
||||
InboundOrderEntity inbound = inbound();
|
||||
inbound.setActualVolumeCbm(new BigDecimal("2.5000"));
|
||||
List<InboundWeightResultEntity> weights = confirmedWeights().subList(0, 1);
|
||||
var current = slot(1);
|
||||
current.setWeightResultId(weights.get(0).getId());
|
||||
current.setSlotStatus("BOUND");
|
||||
when(workflow.findOwned(BUSINESS_TENANT, INBOUND)).thenReturn(inbound);
|
||||
when(measurements.listWeights(BUSINESS_TENANT, INBOUND)).thenReturn(weights);
|
||||
when(allocations.list(BUSINESS_TENANT, INBOUND))
|
||||
.thenReturn(List.of(current), blockSlotsBoundTo(weights));
|
||||
when(warehouse.expandBlock(org.mockito.ArgumentMatchers.eq("internal-token"),
|
||||
org.mockito.ArgumentMatchers.any())).thenReturn(ApiResponse.success(block("OCCUPIED", 3)));
|
||||
|
||||
service.ensureForSubmission(BUSINESS_TENANT, INBOUND, OPERATOR);
|
||||
|
||||
verify(warehouse).expandBlock(org.mockito.ArgumentMatchers.eq("internal-token"),
|
||||
org.mockito.ArgumentMatchers.argThat(request -> request.blockId() == 500L
|
||||
&& request.requiredSlotCount() == 3));
|
||||
verify(allocations).replaceBlock(BUSINESS_TENANT, INBOUND, WAREHOUSE,
|
||||
20, new BigDecimal("2.5000"), block("OCCUPIED", 3));
|
||||
}
|
||||
|
||||
private static InboundProperties properties() {
|
||||
InboundProperties value = new InboundProperties();
|
||||
value.setDefaultPalletCapacityCbm(new BigDecimal("1.200000"));
|
||||
@@ -377,6 +422,18 @@ class MeasurementLocationOccupationServiceTest {
|
||||
return value;
|
||||
}
|
||||
|
||||
private static List<com.baiyue.firstleg.entity.InboundPalletAllocationEntity> blockSlotsBoundTo(
|
||||
List<InboundWeightResultEntity> weights) {
|
||||
return java.util.stream.IntStream.rangeClosed(1, 3).mapToObj(slotNo -> {
|
||||
var slot = slot(slotNo);
|
||||
if (slotNo <= weights.size()) {
|
||||
slot.setWeightResultId(weights.get(slotNo - 1).getId());
|
||||
slot.setSlotStatus("BOUND");
|
||||
}
|
||||
return slot;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
private static List<InboundWeightResultEntity> confirmedWeights() {
|
||||
return java.util.stream.LongStream.rangeClosed(1, 3).mapToObj(index -> {
|
||||
InboundWeightResultEntity weight = new InboundWeightResultEntity();
|
||||
|
||||
+6
-2
@@ -9,6 +9,7 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -35,7 +36,7 @@ class MeasurementSubmissionServiceTest {
|
||||
|
||||
assertThat(service.submit(10001L, 88L, 9L, request)).isSameAs(submitted);
|
||||
|
||||
verify(locations).requireOccupied(10001L, 88L);
|
||||
verify(locations).ensureForSubmission(10001L, 88L, 9L);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -44,7 +45,10 @@ class MeasurementSubmissionServiceTest {
|
||||
var submitted = new InboundMeasurementResponses.MeasurementSubmitted(
|
||||
30L, 3, "MEASURE_PENDING", "PENDING", "STANDARD", null, null, null);
|
||||
when(measurements.submit(10001L, 88L, 9L, request)).thenReturn(submitted);
|
||||
doThrow(new IllegalStateException("warehouse unavailable"))
|
||||
.when(locations).ensureForSubmission(10001L, 88L, 9L);
|
||||
|
||||
assertThat(service.submit(10001L, 88L, 9L, request)).isSameAs(submitted);
|
||||
verify(locations).requireOccupied(10001L, 88L);
|
||||
verify(locations).ensureForSubmission(10001L, 88L, 9L);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user