优化
This commit is contained in:
+27
-16
@@ -30,34 +30,33 @@ class PalletLabelPrintServiceTest {
|
||||
ReflectionTestUtils.setField(service, "warehouses", warehouses);
|
||||
ReflectionTestUtils.setField(service, "print", print);
|
||||
ReflectionTestUtils.setField(service, "internalToken", "test-token");
|
||||
pallet.setPalletCode("ABCD1234567-ABE3-003");
|
||||
pallet.setFbaWarehouseCode("ABE3");
|
||||
pallet.setPalletCode("MSCU6639870-141-001");
|
||||
pallet.setFbaWarehouseCode("SCK8");
|
||||
when(resources.pallet(0L, 200L, 9L)).thenReturn(pallet);
|
||||
when(warehouses.required(200L)).thenReturn(new SharedWarehouseReference(200L, "LAX", "洛杉矶仓", "ACTIVE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void reusesExistingRendererWithExactlyTheSelectedCode() {
|
||||
void usesSharedFbaRendererWithExactlyTheSelectedCode() {
|
||||
byte[] pdf = "%PDF-label".getBytes(java.nio.charset.StandardCharsets.US_ASCII);
|
||||
when(print.generateInboundMarks(anyString(), anyString(), any()))
|
||||
when(print.generateFbaPalletLabels(anyString(), anyString(), any()))
|
||||
.thenReturn(ResponseEntity.ok().contentType(MediaType.APPLICATION_PDF).body(pdf));
|
||||
|
||||
var response = service.print(200L, 9L, "request-1");
|
||||
|
||||
var request = ArgumentCaptor.forClass(PrintPdfClient.Request.class);
|
||||
verify(print).generateInboundMarks(eq("test-token"), eq("request-1"), request.capture());
|
||||
assertThat(request.getValue().templateCode()).isEqualTo("INBOUND_MARK_V1");
|
||||
assertThat(request.getValue().pageSpec().widthMm()).isEqualByComparingTo("100");
|
||||
assertThat(request.getValue().pageSpec().heightMm()).isEqualByComparingTo("100");
|
||||
var request = ArgumentCaptor.forClass(PrintPdfClient.FbaPalletRequest.class);
|
||||
verify(print).generateFbaPalletLabels(eq("test-token"), eq("request-1"), request.capture());
|
||||
assertThat(request.getValue().templateCode()).isEqualTo("FBA_PALLET_A4_LANDSCAPE_V1");
|
||||
assertThat(request.getValue().pageSpec().widthMm()).isEqualByComparingTo("297");
|
||||
assertThat(request.getValue().pageSpec().heightMm()).isEqualByComparingTo("210");
|
||||
assertThat(request.getValue().labels()).singleElement().satisfies(label -> {
|
||||
assertThat(label.topCode()).isEqualTo("ABCD1234567-ABE3-003");
|
||||
assertThat(label.qrContent()).isEqualTo(label.topCode());
|
||||
assertThat(label.warehouseText()).isEqualTo("ABE3");
|
||||
assertThat(label.routeText()).isEqualTo("洛杉矶仓");
|
||||
assertThat(label.palletCode()).isEqualTo("MSCU6639870-141-001");
|
||||
assertThat(label.fbaWarehouseCode()).isEqualTo("SCK8");
|
||||
});
|
||||
assertThat(response.getBody()).isEqualTo(pdf);
|
||||
verify(resources).pallet(0L, 200L, 9L);
|
||||
verifyNoMoreInteractions(resources);
|
||||
verify(print, never()).generateInboundMarks(any(), any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -69,7 +68,7 @@ class PalletLabelPrintServiceTest {
|
||||
|
||||
@Test
|
||||
void mapsCircuitBreakerWrappedPrintFailureToServiceUnavailable() {
|
||||
when(print.generateInboundMarks(anyString(), anyString(), any()))
|
||||
when(print.generateFbaPalletLabels(anyString(), anyString(), any()))
|
||||
.thenThrow(new NoFallbackAvailableException("No fallback available.",
|
||||
new IllegalStateException("No instances available for print-service")));
|
||||
|
||||
@@ -82,7 +81,7 @@ class PalletLabelPrintServiceTest {
|
||||
|
||||
@Test
|
||||
void rejectsJsonErrorInsteadOfDownloadingItAsPdf() {
|
||||
when(print.generateInboundMarks(anyString(), anyString(), any()))
|
||||
when(print.generateFbaPalletLabels(anyString(), anyString(), any()))
|
||||
.thenReturn(ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body("{}".getBytes()));
|
||||
assertThatThrownBy(() -> service.print(200L, 9L, "request-1"))
|
||||
.isInstanceOf(BizException.class).hasMessageContaining("有效 PDF");
|
||||
@@ -90,11 +89,23 @@ class PalletLabelPrintServiceTest {
|
||||
|
||||
@Test
|
||||
void neverTruncatesOrSubstitutesUnsupportedPalletCodes() {
|
||||
for (String code : new String[] { "", "托盘001", "A".repeat(35) }) {
|
||||
for (String code : new String[] { "", "托盘001", "A".repeat(81), " PALLET" }) {
|
||||
pallet.setPalletCode(code);
|
||||
assertThatThrownBy(() -> service.print(200L, 9L, "request-1"))
|
||||
.isInstanceOf(BizException.class).hasMessageContaining("托盘编码");
|
||||
}
|
||||
verifyNoInteractions(print);
|
||||
}
|
||||
|
||||
@Test
|
||||
void keepsNonFbaLabelsOnTheirOwnTemplate() {
|
||||
pallet.setFbaWarehouseCode(null);
|
||||
when(print.generateInboundMarks(anyString(), anyString(), any()))
|
||||
.thenReturn(ResponseEntity.ok().contentType(MediaType.APPLICATION_PDF).body("%PDF-other".getBytes()));
|
||||
service.print(200L, 9L, "request-1");
|
||||
var captor = ArgumentCaptor.forClass(PrintPdfClient.Request.class);
|
||||
verify(print).generateInboundMarks(anyString(), anyString(), captor.capture());
|
||||
assertThat(captor.getValue().templateCode()).isEqualTo("INBOUND_MARK_V1");
|
||||
verify(print, never()).generateFbaPalletLabels(any(), any(), any());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user