This commit is contained in:
2026-08-20 15:20:05 +08:00
parent 6c7a670f1e
commit b55b049e77
30 changed files with 727 additions and 12 deletions
@@ -22,6 +22,7 @@ import org.springframework.web.server.ResponseStatusException;
import org.springframework.test.util.ReflectionTestUtils;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -42,6 +43,7 @@ class InboundPdaWorkflowServiceTest {
@Mock PdaWorkflowRepository repository;
@Mock WarehouseResourceGateway warehouse;
@Mock InboundStockReceiptService stockReceipts;
@Mock InboundUnloadCompletedOutboxService unloadCompletedOutbox;
private InboundPdaWorkflowService service;
private InboundPlan plan;
@@ -61,6 +63,7 @@ class InboundPdaWorkflowServiceTest {
ReflectionTestUtils.setField(service, "repository", repository);
ReflectionTestUtils.setField(service, "warehouse", warehouse);
ReflectionTestUtils.setField(service, "stockReceipts", stockReceipts);
ReflectionTestUtils.setField(service, "unloadCompletedOutbox", unloadCompletedOutbox);
ReflectionTestUtils.setField(service, "sourceObjectMapper", new ObjectMapper().findAndRegisterModules());
service.initializeObjectMapper();
plan = plan();
@@ -300,6 +303,47 @@ class InboundPdaWorkflowServiceTest {
verify(repository, never()).update(plan);
}
@Test
void completionRequiresSuccessfullyUploadedUnloadPhotos() {
activeTask();
task.setUnloadPhotoFileIds(null);
task.setUnloadPhotoUploadedAt(null);
task.setEstimatedEmptyReturnAt(null);
assertThrows(ResponseStatusException.class, () -> service.complete("100", "LIP1"));
verify(repository, never()).allocations(plan.getId());
verify(unloadCompletedOutbox, never()).publish(any(), any(), any());
}
@Test
void uploadUnloadPhotosRecordsEstimatedEmptyReturnTwoDaysLaterAndIsIdempotent() {
activeTask();
PdaRequests.UnloadPhotos request = new PdaRequests.UnloadPhotos(List.of(103L, 101L),
"unload-photo-1", "7", "worker");
var result = service.uploadUnloadPhotos("100", "LIP1", request);
assertEquals(List.of(101L, 103L), result.unloadPhotoFileIds());
assertEquals(result.unloadPhotoUploadedAt().plusDays(2), result.estimatedEmptyReturnAt());
verify(repository).update(task);
ArgumentCaptor<InboundPdaOperation> operation = ArgumentCaptor.forClass(InboundPdaOperation.class);
verify(repository).insert(operation.capture());
when(repository.operation("100", "unload-photo-1")).thenReturn(operation.getValue());
var replay = service.uploadUnloadPhotos("100", "LIP1", request);
assertEquals(result, replay);
verify(repository, times(1)).update(task);
}
@Test
void uploadUnloadPhotosRejectsDuplicateFileIds() {
activeTask();
assertThrows(ResponseStatusException.class, () -> service.uploadUnloadPhotos("100", "LIP1",
new PdaRequests.UnloadPhotos(List.of(101L, 101L), "unload-photo-duplicate", "7", "worker")));
verify(repository, never()).update(task);
}
@Test
void completesWhenMergedAllocationsPreserveExactLineTotals() {
activeTask();
@@ -316,6 +360,7 @@ class InboundPdaWorkflowServiceTest {
verify(repository).update(plan);
verify(stockReceipts).stockIn(eq("100"), eq(plan), eq(task), eq(List.of(targetLine)),
eq(List.of(target, moved)), any(), any());
verify(unloadCompletedOutbox).publish(eq(plan), eq(task), eq(List.of(101L)));
}
@Test
@@ -387,6 +432,9 @@ class InboundPdaWorkflowServiceTest {
value.setCustomerId("100");
value.setTaskNo("PDA2");
value.setStatus("PDA_PENDING");
value.setUnloadPhotoFileIds("[101]");
value.setUnloadPhotoUploadedAt(LocalDateTime.of(2026, 8, 20, 10, 0));
value.setEstimatedEmptyReturnAt(LocalDateTime.of(2026, 8, 22, 10, 0));
value.setVersion(0);
return value;
}