fix: stabilize smart loading plan reads
This commit is contained in:
+35
@@ -23,6 +23,7 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.dao.DataAccessResourceFailureException;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
@@ -107,6 +108,40 @@ class SmartLoadingProvisionalAdjustmentTest {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void planReadFallsBackToAssignedCountWhenQuantityEnrichmentFails() {
|
||||
LoadingPlanEntity plan = plan(103);
|
||||
when(repository.planByBooking(99L)).thenReturn(plan);
|
||||
when(repository.booking(99L)).thenReturn(booking());
|
||||
when(repository.items(1L)).thenReturn(List.of(item));
|
||||
when(repository.inbound(9L, 10L))
|
||||
.thenThrow(new DataAccessResourceFailureException("read query failed"));
|
||||
|
||||
Plan result = service.draftByBooking(99L);
|
||||
|
||||
assertThat(result.items()).singleElement().satisfies(updated -> {
|
||||
assertThat(updated.getTotalPackageCount()).isEqualTo(20);
|
||||
assertThat(updated.getRemainingPackageCount()).isZero();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void planReadUsesApprovedMeasurementWithoutCallingTheLockedAdjustmentQuery() {
|
||||
inbound.setProcessStatus("WAIT_SPLIT");
|
||||
when(repository.planByBooking(99L)).thenReturn(plan(103));
|
||||
when(repository.booking(99L)).thenReturn(booking());
|
||||
when(repository.items(1L)).thenReturn(List.of(item));
|
||||
when(repository.inbound(9L, 10L)).thenReturn(inbound);
|
||||
when(repository.measuredPackageCount(9L, 10L, 20L)).thenReturn(100);
|
||||
|
||||
Plan result = service.draftByBooking(99L);
|
||||
|
||||
assertThat(result.items()).singleElement().satisfies(updated -> {
|
||||
assertThat(updated.getTotalPackageCount()).isEqualTo(100);
|
||||
assertThat(updated.getRemainingPackageCount()).isEqualTo(80);
|
||||
});
|
||||
}
|
||||
|
||||
private static LoadingPlanEntity plan(int version) {
|
||||
LoadingPlanEntity value = new LoadingPlanEntity();
|
||||
value.setId(1L);
|
||||
|
||||
Reference in New Issue
Block a user