文件
hyb-oa/server/tests/unit/utils/businessValidationError.test.js
wangsli a837912638
ci-e2e / e2e (push) Canceled after 0s
ci-minimal / check-minimal (push) Canceled after 0s
feat: 完成错误原因合同与付款就绪提示(09-05-error-explainability-payment-readiness)
2026-09-05 19:00:35 +08:00

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);
});
});