32 行
1.1 KiB
JavaScript
32 行
1.1 KiB
JavaScript
const { ensureNonNegativeAmount } = require("../../../src/routes/reimbursements").__testables;
|
|
const { AppError } = require("../../../src/utils/AppError");
|
|
|
|
describe("reimbursement total amount defense", () => {
|
|
function assertRejected(value, detail, reasonCode) {
|
|
let caught;
|
|
try {
|
|
ensureNonNegativeAmount(value);
|
|
} catch (error) {
|
|
caught = error;
|
|
}
|
|
expect(caught).toBeInstanceOf(AppError);
|
|
expect(caught).toMatchObject({
|
|
code: "VALID_001",
|
|
statusCode: 400,
|
|
details: { total_amount: detail, reasonCode },
|
|
});
|
|
}
|
|
|
|
it.each([-1, "-0.01", -Number.MIN_VALUE])("directly rejects negative total %s", (value) => {
|
|
assertRejected(value, "negative_not_allowed", "reimbursement.total_amount_negative_not_allowed");
|
|
});
|
|
|
|
it.each([NaN, Infinity, -Infinity, "not-a-number", undefined])("directly rejects non-finite total %s", (value) => {
|
|
assertRejected(value, "invalid", "reimbursement.total_amount_invalid");
|
|
});
|
|
|
|
it.each([0, "0.00", 1, "188.80"])("preserves acceptance of finite nonnegative total %s", (value) => {
|
|
expect(() => ensureNonNegativeAmount(value)).not.toThrow();
|
|
});
|
|
});
|