test: 收紧出库单创建契约校验

This commit is contained in:
zhouz
2026-07-22 14:32:11 +08:00
parent 65f25655e7
commit eb35c99966
2 changed files with 17 additions and 5 deletions

View File

@@ -49,9 +49,9 @@ public class IostorInvCreateReqVO {
@Schema(description = "批次序列号")
private String pcsn;
@Schema(description = "计划数", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "计划数量不能为空")
@DecimalMin(value = "0.001", message = "计划数量不能小于 0.001")
@Schema(description = "出库重", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "出库重量不能为空")
@DecimalMin(value = "0.001", message = "出库重量必须大于0")
private BigDecimal planQty;
@Schema(description = "数量单位标识")

View File

@@ -7,7 +7,11 @@ import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import java.time.LocalDateTime;
import java.util.Collections;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@SpringBootTest
@ActiveProfiles("local")
@@ -17,9 +21,17 @@ class IostorInvServiceLocalSpringTest {
private IostorInvService iostorInvService;
@Test
void createOutboundShouldRejectEmptyRequest() {
void createOutboundShouldRejectEmptyDetails() {
IostorInvCreateReqVO reqVO = new IostorInvCreateReqVO();
reqVO.setBillType("OUTBOUND");
reqVO.setStorId("stor-1");
reqVO.setBizDate(LocalDateTime.now());
reqVO.setDetails(Collections.emptyList());
assertThrows(ConstraintViolationException.class, () -> iostorInvService.createOutbound(reqVO));
ConstraintViolationException exception = assertThrows(ConstraintViolationException.class,
() -> iostorInvService.createOutbound(reqVO));
assertTrue(exception.getConstraintViolations().stream()
.anyMatch(violation -> violation.getPropertyPath().toString().contains("details")));
}
}