test(phase4): provision overseas lifecycle fixtures
This commit is contained in:
+8
-1
@@ -27,7 +27,7 @@ public class RelabelApplicationController {
|
||||
public ApiResponse<RelabelResponses.Detail> create(@AuthenticationPrincipal AuthenticatedUser user,
|
||||
@Valid @RequestBody RelabelRequests.Create request) {
|
||||
requirePlatform(user);
|
||||
return ApiResponse.success(service.create("0", operator(user), request));
|
||||
return ApiResponse.success(service.create(requiredCustomer(request.customerId()), operator(user), request));
|
||||
}
|
||||
@GetMapping
|
||||
@PreAuthorize("hasAuthority('" + OverseasPermissions.RELABEL_ORDER_LIST + "')")
|
||||
@@ -60,5 +60,12 @@ public class RelabelApplicationController {
|
||||
throw new ResponseStatusException(HttpStatus.FORBIDDEN, "Platform application required");
|
||||
}
|
||||
}
|
||||
private String requiredCustomer(String customerId) {
|
||||
String value = customerId == null ? null : customerId.trim();
|
||||
if (value == null || value.isEmpty() || "0".equals(value)) {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Target customerId is required");
|
||||
}
|
||||
return value;
|
||||
}
|
||||
private String operator(AuthenticatedUser user) { return user.userId() == null ? user.username() : String.valueOf(user.userId()); }
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ public final class RelabelRequests {
|
||||
private RelabelRequests() {}
|
||||
|
||||
public record Create(
|
||||
@Size(max = 32) String customerId,
|
||||
@NotBlank @Size(max = 128) String customerOrderNo,
|
||||
@NotBlank @Size(max = 128) String overseasWarehouseId,
|
||||
@NotNull LocalDateTime labelDeadline,
|
||||
|
||||
@@ -466,8 +466,9 @@ components:
|
||||
RelabelStatus: { type: string, enum: [PENDING_PROCESSING, PROCESSING, COMPLETED, REJECTED, CANCELLED] }
|
||||
RelabelCreate:
|
||||
type: object
|
||||
required: [customerOrderNo, overseasWarehouseId, labelDeadline, contactName, contactPhone, idempotencyKey, items]
|
||||
required: [customerId, customerOrderNo, overseasWarehouseId, labelDeadline, contactName, contactPhone, idempotencyKey, items]
|
||||
properties:
|
||||
customerId: { type: string, maxLength: 32, description: Target customer ID required by the platform create endpoint }
|
||||
customerOrderNo: { type: string, maxLength: 128 }
|
||||
overseasWarehouseId: { type: string, maxLength: 128 }
|
||||
labelDeadline: { type: string, format: date-time }
|
||||
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
package com.baiyue.lastleg.relabel.controller;
|
||||
|
||||
import com.baiyue.common.security.AuthenticatedUser;
|
||||
import com.baiyue.lastleg.relabel.dto.RelabelRequests;
|
||||
import com.baiyue.lastleg.relabel.service.RelabelApplicationService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
class RelabelApplicationControllerTest {
|
||||
private final RelabelApplicationService service = mock(RelabelApplicationService.class);
|
||||
private final RelabelApplicationController controller = controller();
|
||||
|
||||
@Test
|
||||
void platformCreateUsesExplicitTargetCustomer() {
|
||||
RelabelRequests.Create request = request("190000000000000001");
|
||||
|
||||
controller.create(platform(), request);
|
||||
|
||||
verify(service).create("190000000000000001", "7", request);
|
||||
}
|
||||
|
||||
@Test
|
||||
void platformCreateRejectsMissingOrPlatformCustomer() {
|
||||
assertThrows(ResponseStatusException.class, () -> controller.create(platform(), request(null)));
|
||||
assertThrows(ResponseStatusException.class, () -> controller.create(platform(), request("0")));
|
||||
}
|
||||
|
||||
private RelabelRequests.Create request(String customerId) {
|
||||
return new RelabelRequests.Create(customerId, "CUSTOMER-1", "WH-1",
|
||||
LocalDateTime.of(2026, 8, 20, 10, 0), "Li", "13800000000", null, "key-1",
|
||||
List.of(new RelabelRequests.Item("SKU-A", null, null, null, "Product", 1, 1,
|
||||
"SHIP-1", null, "SKU-B", "Replace", null, null, null)));
|
||||
}
|
||||
|
||||
private AuthenticatedUser platform() {
|
||||
return new AuthenticatedUser(7L, 0L, 0L, 8L, "operator", "PLATFORM", "WEB", Set.of());
|
||||
}
|
||||
|
||||
private RelabelApplicationController controller() {
|
||||
RelabelApplicationController value = new RelabelApplicationController();
|
||||
ReflectionTestUtils.setField(value, "service", service);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -212,7 +212,7 @@ class RelabelApplicationServiceTest {
|
||||
}
|
||||
|
||||
private static RelabelRequests.Create request(String key, int total, int notified) {
|
||||
return new RelabelRequests.Create("CUSTOMER-1", "WH-1", LocalDateTime.of(2026, 8, 20, 10, 0),
|
||||
return new RelabelRequests.Create(null, "CUSTOMER-1", "WH-1", LocalDateTime.of(2026, 8, 20, 10, 0),
|
||||
"Li", "13800000000", "remark", key, List.of(new RelabelRequests.Item("SKU-A", "img-1",
|
||||
"image.png", "https://files/image.png", "Chinese name", total, notified, "SHP-1", "TRACK-1",
|
||||
"SKU-NEW", "Label on carton", "file-1", "relabel.pdf", "https://files/relabel.pdf")));
|
||||
|
||||
+1
-1
@@ -92,7 +92,7 @@ class TaillegRealConsumerAcceptanceTest {
|
||||
|
||||
if (!exists("ll_relabel_application", MARKER + "-RELABEL-KEY")) {
|
||||
relabel.create(CUSTOMER, "real-acceptance", new RelabelRequests.Create(
|
||||
MARKER + "-RELABEL", "92", RELABEL_DEADLINE, "验收联系人", "13800000000",
|
||||
null, MARKER + "-RELABEL", "92", RELABEL_DEADLINE, "验收联系人", "13800000000",
|
||||
MARKER, MARKER + "-RELABEL-KEY", List.of(new RelabelRequests.Item("SKU-REAL-A", null, null,
|
||||
null, "真实验收商品", 3, 3, MARKER + "-SHIP", MARKER + "-TRACK", "SKU-REAL-A-NEW",
|
||||
"换标验收", null, null, null))));
|
||||
|
||||
Reference in New Issue
Block a user