23 行
1.3 KiB
JavaScript
23 行
1.3 KiB
JavaScript
const { ERROR_REASONS, getErrorReason } = require("../../../src/constants/errorReasons");
|
|
const { buildBusinessValidationError } = require("../../../src/utils/businessValidationError");
|
|
|
|
describe("business validation reason contract", () => {
|
|
it("preserves status, top-level code and legacy fields without allowing reason override", () => {
|
|
const error = buildBusinessValidationError("payment_batch.legal_entity_required", {
|
|
legalEntity: "single_legal_entity_required", reasonCode: "not_registered",
|
|
}, 409);
|
|
expect(error).toMatchObject({
|
|
code: "VALID_001", statusCode: 409, message: "参数校验失败",
|
|
details: { legalEntity: "single_legal_entity_required", reasonCode: "payment_batch.legal_entity_required" },
|
|
});
|
|
expect(getErrorReason(error.details.reasonCode).defaultMessage).toBe("报销人尚未维护所属公司,请联系管理员补充后再安排付款。");
|
|
});
|
|
|
|
it("rejects unknown reasons and protects registered metadata", () => {
|
|
expect(() => buildBusinessValidationError("payment_batch.typo")).toThrow(TypeError);
|
|
expect(new Set(ERROR_REASONS.map((reason) => reason.code)).size).toBe(ERROR_REASONS.length);
|
|
expect(Object.isFrozen(ERROR_REASONS)).toBe(true);
|
|
expect(ERROR_REASONS.every(Object.isFrozen)).toBe(true);
|
|
});
|
|
});
|