Adopt RUB-only API contract; remove currency cards, selectors, screener currency filter and multi-currency branches. BREAKING CHANGE: requires the RUB-only backend contract.
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { sumMoney } from "./decimal";
|
|
|
|
describe("sumMoney", () => {
|
|
it("adds exact signed decimals", () => {
|
|
expect(sumMoney([
|
|
{ currency: "RUB", value: "0.1" },
|
|
{ currency: "RUB", value: "0.2" },
|
|
{ currency: "RUB", value: "-1500000.45" },
|
|
{ currency: "RUB", value: "200" },
|
|
])).toEqual({ currency: "RUB", value: "-1499800.15" });
|
|
});
|
|
|
|
it("preserves significant fractional digits and a compensated zero", () => {
|
|
expect(sumMoney([
|
|
{ currency: "RUB", value: "100.5" },
|
|
{ currency: "RUB", value: "49.50" },
|
|
{ currency: "RUB", value: "0.005" },
|
|
])).toEqual({ currency: "RUB", value: "150.005" });
|
|
expect(sumMoney([
|
|
{ currency: "RUB", value: "100" },
|
|
{ currency: "RUB", value: "-100" },
|
|
])).toEqual({ currency: "RUB", value: "0" });
|
|
});
|
|
|
|
it.each(["", ".", "1.2.3", "not-a-number"])(
|
|
"rejects malformed amount %s instead of treating it as zero",
|
|
(value) => {
|
|
expect(sumMoney([
|
|
{ currency: "RUB", value: "100" },
|
|
{ currency: "RUB", value },
|
|
])).toBeNull();
|
|
},
|
|
);
|
|
});
|