feat: 完成错误原因合同与付款就绪提示(09-05-error-explainability-payment-readiness)
这个提交包含在:
@@ -0,0 +1,22 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
在新工单中引用
屏蔽一个用户