This commit is contained in:
2026-08-25 12:27:47 +08:00
parent 0e0b6f8264
commit 4b5e5a1e4e
13 changed files with 183 additions and 33 deletions
@@ -4,9 +4,12 @@ import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.web.bind.annotation.RequestParam;
import org.yaml.snakeyaml.Yaml;
import java.nio.charset.StandardCharsets;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
@@ -82,9 +85,57 @@ class FbaPricingContractTest {
.doesNotContain("format: int64");
}
@Test
@DisplayName("客户规则列表响应锁定数组包络和实体核心字段")
void freezesCustomerRuleVersionListResponse() throws Exception {
String source = new ClassPathResource("openapi/fba-pricing-v1.yaml")
.getContentAsString(StandardCharsets.UTF_8);
Map<String, Object> api = map(new Yaml().load(source));
Map<String, Object> paths = map(api.get("paths"));
Map<String, Object> get = map(map(paths.get(
"/api/platform/v1/fba-pricing/customer-rules")).get("get"));
Map<String, Object> success = map(map(get.get("responses")).get("200"));
Map<String, Object> responseSchema = map(map(map(success.get("content"))
.get("application/json")).get("schema"));
assertThat(responseSchema).containsEntry(
"$ref", "#/components/schemas/CustomerRuleVersionListApiResponse");
Map<String, Object> schemas = map(map(api.get("components")).get("schemas"));
Map<String, Object> envelope = map(schemas.get("CustomerRuleVersionListApiResponse"));
assertThat(list(envelope.get("required"))).containsExactly("code", "message", "data", "timestamp");
Map<String, Object> envelopeProperties = map(envelope.get("properties"));
assertThat(envelopeProperties).containsOnlyKeys(
"code", "message", "data", "requestId", "traceId", "timestamp");
Map<String, Object> data = map(envelopeProperties.get("data"));
assertThat(data).containsEntry("type", "array");
assertThat(map(data.get("items"))).containsEntry(
"$ref", "#/components/schemas/CustomerRuleVersionResource");
Map<String, Object> resource = map(schemas.get("CustomerRuleVersionResource"));
assertThat(map(resource.get("properties"))).containsOnlyKeys(
"id", "tenantId", "ruleCode", "ruleVersion", "customerId", "customerName",
"businessType", "chargeMode", "taxMode", "conversionFactor", "roundingScale",
"roundingMode", "currency", "effectiveFrom", "effectiveTo", "status", "remark",
"createdBy", "createdAt", "updatedBy", "updatedAt", "deleted", "version");
for (String longField : List.of("id", "tenantId", "customerId", "createdBy", "updatedBy")) {
assertThat(map(map(resource.get("properties")).get(longField))).containsEntry("type", "string");
}
assertThat(source).doesNotContain("CustomerRuleVersionSummary");
}
private static Method method(String name) {
return java.util.Arrays.stream(PlatformFbaMasterDataController.class.getDeclaredMethods())
.filter(candidate -> candidate.getName().equals(name))
.findFirst().orElseThrow();
}
@SuppressWarnings("unchecked")
private static Map<String, Object> map(Object value) {
return (Map<String, Object>) value;
}
@SuppressWarnings("unchecked")
private static List<Object> list(Object value) {
return (List<Object>) value;
}
}