UNPKG

french-ssn

Version:

🇫🇷 A parser / validator for French Social Security Number

36 lines • 2.02 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const normalize_1 = __importDefault(require("./normalize")); const makeSSN_1 = __importDefault(require("./makeSSN")); it("is a string", () => { // @ts-expect-error this is to test a pure JS behavior expect(() => (0, normalize_1.default)()).toThrow("Input must be a string or a 15 digits number"); // @ts-expect-error this is to test a pure JS behavior expect(() => (0, normalize_1.default)({})).toThrow("Input must be a string or a 15 digits number"); // @ts-expect-error this is to test a pure JS behavior expect(() => (0, normalize_1.default)([1, 23, 34])).toThrow("Input must be a string or a 15 digits number"); }); it("has 15 characters", () => { expect(() => (0, normalize_1.default)("12345671234567")).toThrow("Input must be 15 characters long"); expect(() => (0, normalize_1.default)("1234567812345678")).toThrow("Input must be 15 characters long"); }); it("has only (mostly) digits", () => { expect(() => (0, normalize_1.default)((0, makeSSN_1.default)({ year: "5a" }))).toThrow("French Social Security Number only allows digits, except for the letters A and B in 7th position"); }); it("accepts spaces", () => { expect((0, normalize_1.default)("2 55 08 14 168 025 12")).toBe("255081416802512"); }); it("accepts all sorts of things", () => { expect((0, normalize_1.default)("SSN: 2 55,08 2B.168 025 12qgls")).toBe("255082B16802512"); }); it("accepts numbers", () => { expect((0, normalize_1.default)(255081416802512)).toBe("255081416802512"); }); it("allows a variable length", () => { expect((0, normalize_1.default)(2550814168025, { length: 13 })).toBe("2550814168025"); expect(() => (0, normalize_1.default)(255081416802512, { length: 13 })).toThrow("Input must be 13 characters long"); }); //# sourceMappingURL=normalize.test.js.map