修改提交

This commit is contained in:
2026-09-06 15:02:33 +08:00
parent 42ddc19826
commit 3ae8964fe5
15 changed files with 242 additions and 137 deletions
@@ -40,6 +40,7 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.times;
@ExtendWith(MockitoExtension.class)
class RelabelApplicationServiceTest {
@@ -98,7 +99,7 @@ class RelabelApplicationServiceTest {
assertEquals("RELABEL:PENDING_PROCESSING", tailOrder.getValue().getSubOrderStatus());
assertEquals("CUSTOMER", tailOrder.getValue().getSourceRegion());
assertTrue(tailOrder.getValue().getOrderNo().matches("RL-WH-\\d{8}-\\d{6}"));
assertEquals(tailOrder.getValue().getInboundCode(), tailOrder.getValue().getSourceInboundId());
assertEquals(tailOrder.getValue().getInboundCode() + ":WH-1", tailOrder.getValue().getSourceInboundId());
assertEquals(tailOrder.getValue().getInboundCode(), application.getValue().getRelabelNo());
assertTrue(tailOrder.getValue().getInboundCode().startsWith("RL-"));
assertEquals(10, tailOrder.getValue().getPackageCount());
@@ -120,6 +121,71 @@ class RelabelApplicationServiceTest {
verify(items, never()).insert(any(RelabelItem.class));
}
@Test
void createPersistsCartonMarkBinding() {
RelabelRequests.Item attachedItem = new RelabelRequests.Item("SKU-A", null, null, null,
"Chinese name", 2, 2, "SHP-1", null, "SKU-NEW", null, null, null, null, null,
"BOX-1", "FBA-BOX-1", "WH-1");
RelabelRequests.Create request = new RelabelRequests.Create("CUSTOMER-1", "WH-1",
LocalDateTime.of(2026, 8, 20, 10, 0), "Li", "13800000000", BigDecimal.ONE, null, "key-marks",
List.of(attachedItem));
RelabelApplication persisted = application(11L, "FBR-1", "100", "key-files", null,
RelabelApplicationService.PENDING_PROCESSING);
persisted.setLastlegOrderId(21L); persisted.setItemCount(1); persisted.setTotalPackageCount(2);
persisted.setNotifiedPackageCount(2);
when(applications.findNo(eq("100"), any())).thenReturn(persisted);
when(items.selectList(any())).thenReturn(List.of(item(31L, 11L, "SKU-A", 2, 2)));
when(histories.selectList(any())).thenReturn(List.of());
when(orders.selectById(21L)).thenReturn(order(21L, "100", "LMO-RELABEL-1",
RelabelApplicationService.PENDING_PROCESSING));
service.create("100", "operator-1", request);
ArgumentCaptor<RelabelItem> saved = ArgumentCaptor.forClass(RelabelItem.class);
verify(items).insert(saved.capture());
assertEquals("BOX-1", saved.getValue().getCartonMark());
assertEquals("FBA-BOX-1", saved.getValue().getFbaCartonMark());
assertEquals("WH-1", saved.getValue().getDestinationWarehouseId());
}
@Test
void createGroupsCartonsIntoOneTailOrderPerDestinationWarehouse() {
RelabelRequests.Item west = carton("SKU-A", "BOX-1", "FBA-1", "ONT8");
RelabelRequests.Item east = carton("SKU-B", "BOX-2", "FBA-2", "ABE8");
RelabelRequests.Create request = new RelabelRequests.Create("CUSTOMER-1", null,
LocalDateTime.of(2026, 8, 20, 10, 0), "Li", "13800000000", BigDecimal.ONE, null, "key-multi",
List.of(west, east));
RelabelApplication persisted = application(11L, "FBR-1", "10001", "key-multi", null,
RelabelApplicationService.PENDING_PROCESSING);
persisted.setLastlegOrderId(21L);
when(applications.findNo(eq("10001"), any())).thenReturn(persisted);
when(items.selectList(any())).thenReturn(List.of(item(31L, 11L, "SKU-A", 1, 1)));
when(histories.selectList(any())).thenReturn(List.of());
when(orders.selectById(21L)).thenReturn(order(21L, "10001", "LMO-RELABEL-1",
RelabelApplicationService.PENDING_PROCESSING));
service.create("10001", "operator-1", request);
ArgumentCaptor<LastlegOrder> created = ArgumentCaptor.forClass(LastlegOrder.class);
verify(orders, times(2)).insert(created.capture());
assertEquals(List.of("ONT8", "ABE8"), created.getAllValues().stream()
.map(LastlegOrder::getOverseasWarehouseId).toList());
assertTrue(created.getAllValues().stream().allMatch(value -> value.getPackageCount() == 1));
}
@Test
void createRejectsCartonWithoutDetailOrDefaultDestinationWarehouse() {
RelabelRequests.Create request = new RelabelRequests.Create("CUSTOMER-1", null,
LocalDateTime.of(2026, 8, 20, 10, 0), "Li", "13800000000", BigDecimal.ONE, null, "key-no-destination",
List.of(carton("SKU-A", "BOX-1", "FBA-1", null)));
ResponseStatusException exception = assertThrows(ResponseStatusException.class,
() -> service.create("10001", "operator-1", request));
assertEquals(400, exception.getStatusCode().value());
verify(orders, never()).insert(any(LastlegOrder.class));
}
@Test
void sameIdempotencyKeyAndPayloadReturnsExistingApplicationWithoutWrites() {
RelabelRequests.Create request = request("key-1", 10, 6);
@@ -224,6 +290,13 @@ class RelabelApplicationServiceTest {
"SKU-NEW", "Label on carton", "file-1", "relabel.pdf", "https://files/relabel.pdf")));
}
private static RelabelRequests.Item carton(String sku, String cartonMark, String fbaCartonMark,
String destinationWarehouseId) {
return new RelabelRequests.Item(sku, null, null, null, "Chinese name", 1, 1,
"SHP-1", null, sku + "-NEW", null, null, null, null, null,
cartonMark, fbaCartonMark, destinationWarehouseId);
}
private static RelabelApplication application(long id, String no, String customerId, String key, String requestHash,
String status) {
RelabelApplication value = new RelabelApplication();