forked from Yara724/api
35 lines
992 B
TypeScript
35 lines
992 B
TypeScript
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();
|
||
});
|
||
});
|