feat: freeze and propagate first-leg pallet labels
This commit is contained in:
+6
@@ -9,6 +9,7 @@ import com.baiyue.firstleg.mapper.LoadingCompletedEventMapper.Row;
|
||||
import com.baiyue.firstleg.mapper.LoadingCompletedEventMapper.PalletRow;
|
||||
import com.baiyue.firstleg.mapper.LoadingCartonManifestMapper;
|
||||
import com.baiyue.firstleg.mapper.LoadingCartonManifestMapper.LabelRow;
|
||||
import com.baiyue.firstleg.mapper.LoadingPalletLabelMapper;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -30,14 +31,19 @@ class LoadingCompletedOutboxServiceTest {
|
||||
private final LoadingCompletedEventMapper snapshots = mock(LoadingCompletedEventMapper.class);
|
||||
private final InboundOutboxMapper outbox = mock(InboundOutboxMapper.class);
|
||||
private final LoadingCartonManifestMapper manifests = mock(LoadingCartonManifestMapper.class);
|
||||
private final LoadingPalletLabelMapper palletLabels = mock(LoadingPalletLabelMapper.class);
|
||||
private final LoadingPalletLabelService palletLabelService = mock(LoadingPalletLabelService.class);
|
||||
private final ObjectMapper mapper = new ObjectMapper().findAndRegisterModules();
|
||||
private final LoadingCompletedOutboxService service = new LoadingCompletedOutboxService();
|
||||
|
||||
@BeforeEach void setup() {
|
||||
ReflectionTestUtils.setField(service,"snapshotMapper",snapshots);
|
||||
ReflectionTestUtils.setField(service,"cartonManifestMapper",manifests);
|
||||
ReflectionTestUtils.setField(service,"palletLabelMapper",palletLabels);
|
||||
ReflectionTestUtils.setField(service,"palletLabelService",palletLabelService);
|
||||
ReflectionTestUtils.setField(service,"outboxMapper",outbox);
|
||||
ReflectionTestUtils.setField(service,"objectMapper",mapper);
|
||||
when(palletLabels.labels(anyLong())).thenReturn(List.of());
|
||||
when(manifests.labelPool(anyLong(), anyLong())).thenAnswer(invocation -> List.of(
|
||||
label(101, "BOX-101"), label(102, "BOX-102"),
|
||||
label(202, "BOX-202"), label(302, "BOX-302")));
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.baiyue.firstleg.service;
|
||||
|
||||
import com.baiyue.firstleg.mapper.LoadingPalletLabelMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class LoadingPalletLabelServiceTest {
|
||||
@Test
|
||||
void generatesStableIndexesPerContainerAndFbaAndSkipsDropship() {
|
||||
LoadingPalletLabelMapper mapper = mock(LoadingPalletLabelMapper.class);
|
||||
LoadingPalletLabelService service = new LoadingPalletLabelService();
|
||||
ReflectionTestUtils.setField(service, "mapper", mapper);
|
||||
List<LoadingPalletLabelMapper.LabelRow> saved = new ArrayList<>();
|
||||
when(mapper.lockSources(10L)).thenReturn(List.of(source(3, "LAX9", 1, "STANDARD"),
|
||||
source(1, "ONT8", 2, "STANDARD"), source(2, "ONT8", 1, "STANDARD"),
|
||||
source(4, "ONT8", 4, "ONE_CLICK_DROPSHIP")));
|
||||
when(mapper.labels(10L)).thenAnswer(ignored -> List.copyOf(saved));
|
||||
when(mapper.insert(any())).thenAnswer(invocation -> { saved.add(invocation.getArgument(0)); return 1; });
|
||||
|
||||
var manifest = service.prepare(10L, 20L);
|
||||
|
||||
assertThat(manifest.totalCount()).isEqualTo(4);
|
||||
assertThat(manifest.groups()).extracting(group -> group.destinationWarehouseCode() + ":" + group.totalCount())
|
||||
.containsExactly("LAX9:1", "ONT8:3");
|
||||
assertThat(saved).extracting(LoadingPalletLabelMapper.LabelRow::getPalletCode)
|
||||
.containsExactly("MSCU6639870-LAX9-001", "MSCU6639870-ONT8-001",
|
||||
"MSCU6639870-ONT8-002", "MSCU6639870-ONT8-003");
|
||||
}
|
||||
|
||||
private LoadingPalletLabelMapper.SourceRow source(long itemId, String destination, int pallets, String fulfillment) {
|
||||
var row = new LoadingPalletLabelMapper.SourceRow(); row.setPlanId(10L); row.setPlanNo("LP-1");
|
||||
row.setPlanStatus("LOADING"); row.setContainerNo("MSCU6639870"); row.setWarehouseId(20L);
|
||||
row.setItemId(itemId); row.setAccountId(100L); row.setInboundId(itemId + 1000);
|
||||
row.setInboundCode("RK-" + itemId); row.setDestinationWarehouseCode(destination);
|
||||
row.setDestinationWarehouseName(destination); row.setPalletCount(pallets);
|
||||
row.setFulfillmentType(fulfillment); row.setDestinationType("FBA"); return row;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user