forked from Yara724/api
Validation for prices and objection
This commit is contained in:
34
src/utils/unicode-digits.spec.ts
Normal file
34
src/utils/unicode-digits.spec.ts
Normal 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();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user