Validation for prices and objection

This commit is contained in:
SepehrYahyaee
2026-05-20 11:08:47 +03:30
parent 511d478064
commit e4dfe7c572
18 changed files with 467 additions and 60 deletions

View File

@@ -0,0 +1,34 @@
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();
});
});