This commit is contained in:
2026-09-15 13:43:12 +08:00
parent f9649c44e9
commit 6a2075fe4b
5 changed files with 51 additions and 5 deletions
@@ -19,6 +19,7 @@ class DropshipOutboundCandidateMapperContractTest {
assertTrue(sql.contains(token), token);
}
assertTrue(sql.contains("LEAST(pos.available_packages,s.package_count"));
assertTrue(sql.contains("#{customerId} IS NULL OR #{customerId}='' OR p.customer_id=#{customerId}"));
}
@Test
@@ -36,6 +36,37 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
class PlatformDispatchOutboundContractTest {
@Test
void candidateHttpQueryAcceptsWarehouseWithoutCustomerAndPreservesExplicitFilter() throws Exception {
DeliveryTransferController controller = new DeliveryTransferController();
var service = mock(com.baiyue.lastleg.delivery.service.DeliveryTransferService.class);
ReflectionTestUtils.setField(controller, "service", service);
MockMvc mvc = MockMvcBuilders.standaloneSetup(controller)
.setCustomArgumentResolvers(new AuthenticationPrincipalArgumentResolver()).build();
AuthenticatedUser platform = new AuthenticatedUser(1000001L, 0L, 0L, 1L, "platform_admin",
"PLATFORM", "WEB", Set.of(OverseasPermissions.OUTBOUND_CREATE));
SecurityContextHolder.getContext().setAuthentication(
new UsernamePasswordAuthenticationToken(platform, null, Set.of()));
String path = "/api/platform/v1/last-leg/outbound-orders/one-click-dropship/candidates";
try {
mvc.perform(get(path).param("warehouseId", "WH-1")).andExpect(status().isOk());
org.mockito.Mockito.verify(service).oneClickCandidates(null, "WH-1");
mvc.perform(get(path).param("customerId", "101").param("warehouseId", "WH-1"))
.andExpect(status().isOk());
org.mockito.Mockito.verify(service).oneClickCandidates("101", "WH-1");
SecurityContextHolder.clearContext();
mvc.perform(get(path).param("warehouseId", "WH-1")).andExpect(status().isUnauthorized());
AuthenticatedUser merchant = new AuthenticatedUser(7L, 100L, 100L, 8L, "merchant",
"MERCHANT", "WEB", Set.of(OverseasPermissions.OUTBOUND_CREATE));
SecurityContextHolder.getContext().setAuthentication(
new UsernamePasswordAuthenticationToken(merchant, null, Set.of()));
mvc.perform(get(path).param("warehouseId", "WH-1")).andExpect(status().isForbidden());
org.mockito.Mockito.verifyNoMoreInteractions(service);
} finally {
SecurityContextHolder.clearContext();
}
}
@Test
void outboundDetailAcceptsTheDocumentUrlWithoutPagingParameters() throws Exception {
DeliveryTransferController controller = new DeliveryTransferController();
@@ -87,7 +118,7 @@ class PlatformDispatchOutboundContractTest {
}
@Test
void oneClickRequiresCustomerWhileOutboundListKeepsOptionalFilter() throws Exception {
void oneClickCreationRequiresCustomerWhileCandidateAndListFiltersAreOptional() throws Exception {
Method create = DeliveryTransferController.class.getMethod("createOneClick", AuthenticatedUser.class,
String.class, DeliveryRequests.OneClickOutbound.class);
Method candidates = DeliveryTransferController.class.getMethod("oneClickCandidates", AuthenticatedUser.class,
@@ -102,7 +133,7 @@ class PlatformDispatchOutboundContractTest {
RequestParam pageCustomer = page.getParameters()[1].getAnnotation(RequestParam.class);
assertNotNull(createCustomer);
assertTrue(createCustomer.required());
assertTrue(candidates.getParameters()[1].getAnnotation(RequestParam.class).required());
assertFalse(candidates.getParameters()[1].getAnnotation(RequestParam.class).required());
assertFalse(candidates.getParameters()[2].getAnnotation(RequestParam.class).required());
assertNotNull(pageCustomer);
assertFalse(pageCustomer.required());
@@ -557,6 +557,20 @@ class DeliveryTransferServiceTest {
verify(inventoryPositions, never()).selectById(any());
}
@Test
void oneClickCandidatesAllowPlatformWarehouseQueryWithoutCustomer() {
DropshipOutboundCandidate first = dropshipCandidate(901L, 1001L, "WH-1", "DS-A001", "SKU-1", 1L);
DropshipOutboundCandidate second = dropshipCandidate(902L, 1002L, "WH-1", "DS-A002", "SKU-1", 3L);
when(dropshipProfiles.listOutboundCandidates(null, "WH-1")).thenReturn(List.of(first, second));
var result = service.oneClickCandidates(null, " WH-1 ");
assertEquals(2, result.size());
assertEquals("DS-A001", result.get(0).palletNo());
assertEquals("DS-A002", result.get(1).palletNo());
verify(dropshipProfiles).listOutboundCandidates(null, "WH-1");
}
@Test
void oneClickCreationRejectsOrdinaryInventoryBeforeAnyWrite() {