Files
yara724api/src/utils/unicode-digits.spec.ts
2026-05-20 11:08:47 +03:30

35 lines
992 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import {
normalizeMoneyAmountString,
normalizeUnicodeDigitsDeep,
normalizeUnicodeDigitsToEnglish,
parseMoneyAmountToman,
} from "./unicode-digits";
describe("unicode-digits", () => {
it("converts Persian digits to ASCII", () => {
expect(normalizeUnicodeDigitsToEnglish("۱۲۳۴۵۶۷۸۹۰")).toBe("1234567890");
});
it("normalizes nested request bodies", () => {
expect(
normalizeUnicodeDigitsDeep({
partPrice: "۵۰۰۰۰۰۰",
nested: [{ total: "۱۰۰" }],
}),
).toEqual({
partPrice: "5000000",
nested: [{ total: "100" }],
});
});
it("strips grouping separators for money strings", () => {
expect(normalizeMoneyAmountString("۵,۰۰۰,۰۰۰")).toBe("5000000");
});
it("parses integer Toman amount strings", () => {
expect(parseMoneyAmountToman("۵۳۰۰۰۰۰")).toBe(5300000);
expect(parseMoneyAmountToman("1000")).toBe(1000);
expect(parseMoneyAmountToman("12.5")).toBeNull();
});
});