Files
edr-platform/apps/edr-payment-api/src/modules/cbe-bill/cbe-bill.amount.spec.ts
2026-08-07 08:47:04 +00:00

23 lines
825 B
TypeScript

import { amountsMatchToTheCent } from "./cbe-bill.service";
describe("amountsMatchToTheCent (CBE payment amount gate)", () => {
it("accepts the exact amount", () => {
expect(amountsMatchToTheCent(1234.34, 1234.34)).toBe(true);
});
it("rejects a cents-only difference (the 1234.89 vs 1234.34 bug)", () => {
expect(amountsMatchToTheCent(1234.89, 1234.34)).toBe(false);
expect(amountsMatchToTheCent(1234.35, 1234.34)).toBe(false);
});
it("rejects whole-unit differences", () => {
expect(amountsMatchToTheCent(1235.34, 1234.34)).toBe(false);
});
it("absorbs double-precision storage noise", () => {
expect(amountsMatchToTheCent(1234.34, 1234.3399999999999)).toBe(true);
// classic float artifact: 0.1 + 0.2 !== 0.3
expect(amountsMatchToTheCent(0.1 + 0.2, 0.3)).toBe(true);
});
});