fix: return A0404 for missing PDA pallets
This commit is contained in:
+5
@@ -82,6 +82,7 @@ class PdaOperationsOpenApiContractTest {
|
||||
assertTrue(yaml.contains("enum: [LOCATION, PALLET]"));
|
||||
assertTrue(yaml.contains("enum: [APPROVE, REWORK]"));
|
||||
assertTrue(yaml.contains("enum: [DAMAGED, MISSING_LABEL, LABEL_MISMATCH, UNREADABLE, OTHER]"));
|
||||
assertEquals(3, occurrences(yaml, "body.code=A0404"));
|
||||
assertFalse(yaml.contains("/api/pda/v1/last-leg/delivery"));
|
||||
for (String response : List.of("StocktakeSummaryPageResponse", "StocktakeDetailResponse",
|
||||
"StocktakeItemResponse", "InventoryMoveResponse", "InventoryScanResponse", "LocationResponse",
|
||||
@@ -101,4 +102,8 @@ class PdaOperationsOpenApiContractTest {
|
||||
return new String(input.readAllBytes(), StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
|
||||
private static int occurrences(String value, String token) {
|
||||
return (value.length() - value.replace(token, "").length()) / token.length();
|
||||
}
|
||||
}
|
||||
|
||||
+10
@@ -108,6 +108,16 @@ class PdaInventoryMoveServiceTest {
|
||||
verify(physical, never()).apply(anyLong(), any(), anyString(), anyLong(), anyString(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void missingSourcePalletIsReportedAsNotFound() {
|
||||
when(warehouse.resolvePallet("MISSING")).thenReturn(null);
|
||||
|
||||
assertThatThrownBy(() -> service.move(900L, "operator-1",
|
||||
new PdaInventoryMoveRequest("MISSING", "B-01", 2, "move-1", "库位优化")))
|
||||
.isInstanceOf(ResponseStatusException.class).hasMessageContaining("404");
|
||||
verify(physical, never()).apply(anyLong(), any(), anyString(), anyLong(), anyString(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void resumesWhenWarehouseCommittedButLastlegTransactionRolledBack() {
|
||||
when(warehouse.resolvePallet("PAL-1")).thenReturn(pallet(900L, 21L, 3));
|
||||
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
package com.baiyue.lastleg.pda.warehouse.controller;
|
||||
|
||||
import com.baiyue.common.security.AuthenticatedUser;
|
||||
import com.baiyue.common.web.GlobalExceptionHandler;
|
||||
import com.baiyue.lastleg.pda.warehouse.dto.PdaWarehouseRequests;
|
||||
import com.baiyue.lastleg.pda.warehouse.service.PdaWarehouseService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.bind.support.WebDataBinderFactory;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
import org.springframework.web.method.support.ModelAndViewContainer;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
class PdaWarehouseControllerTest {
|
||||
private PdaWarehouseService service;
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = mock(PdaWarehouseService.class);
|
||||
PdaWarehouseController controller = new PdaWarehouseController();
|
||||
ReflectionTestUtils.setField(controller, "service", service);
|
||||
mockMvc = MockMvcBuilders.standaloneSetup(controller)
|
||||
.setControllerAdvice(new GlobalExceptionHandler())
|
||||
.setCustomArgumentResolvers(new AuthenticatedUserResolver())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
void missingPalletReturnsHttp200WithStableA0404Body() throws Exception {
|
||||
when(service.pallet(900L, new PdaWarehouseRequests.Scan("MISSING")))
|
||||
.thenThrow(new ResponseStatusException(HttpStatus.NOT_FOUND, "Warehouse pallet was not found"));
|
||||
|
||||
mockMvc.perform(post("/api/pda/v1/last-leg/pallets/resolve")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.content("{\"code\":\"MISSING\"}"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value("A0404"))
|
||||
.andExpect(jsonPath("$.message").value("Warehouse pallet was not found"));
|
||||
}
|
||||
|
||||
private static AuthenticatedUser user() {
|
||||
return new AuthenticatedUser(42L, 0L, 0L, 8L, "picker", "PLATFORM", "PDA",
|
||||
Set.of("lastleg:pda:operate", "ROLE_OVERSEAS_WAREHOUSE_PDA_OPERATOR"),
|
||||
false, null, null, false, 900L);
|
||||
}
|
||||
|
||||
private static final class AuthenticatedUserResolver implements HandlerMethodArgumentResolver {
|
||||
@Override
|
||||
public boolean supportsParameter(MethodParameter parameter) {
|
||||
return parameter.hasParameterAnnotation(AuthenticationPrincipal.class)
|
||||
&& parameter.getParameterType() == AuthenticatedUser.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer container,
|
||||
NativeWebRequest request, WebDataBinderFactory binderFactory) {
|
||||
return user();
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
@@ -48,6 +48,14 @@ class PdaWarehouseServiceTest {
|
||||
.isInstanceOf(ResponseStatusException.class).hasMessageContaining("409");
|
||||
}
|
||||
|
||||
@Test
|
||||
void missingPalletIsReportedAsNotFound() {
|
||||
when(warehouse.resolvePallet("MISSING")).thenReturn(null);
|
||||
|
||||
assertThatThrownBy(() -> service.pallet(900L, new PdaWarehouseRequests.Scan("MISSING")))
|
||||
.isInstanceOf(ResponseStatusException.class).hasMessageContaining("404");
|
||||
}
|
||||
|
||||
@Test
|
||||
void locationCombinesPhysicalCapacityAndInventoryOccupation() {
|
||||
when(warehouse.resolveLocation(900L, "A-01")).thenReturn(
|
||||
|
||||
Reference in New Issue
Block a user