UNPKG

french-ssn

Version:

🇫🇷 A parser / validator for French Social Security Number

75 lines • 2.57 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const parse_1 = __importDefault(require("./parse")); const makeSSN_1 = __importDefault(require("./makeSSN")); describe("born in France", () => { it("returns expected result", () => { Date.now = jest.fn(() => new Date("2018").valueOf()); expect((0, parse_1.default)((0, makeSSN_1.default)({ gender: "2", month: 4, year: 89, place: "78650", }))).toEqual({ provisional: false, gender: { name: "female", title: "Mme", }, approximateAge: 28, birth: { year: 1989, month: { name: "avril", index: 4, }, approximateDate: expect.any(Date), city: { insee: "78650", }, country: { insee: "100", name: "France", }, county: { insee: "78", name: "Yvelines", }, }, }); }); }); describe("provisional number", () => { it("is provisional if gender is greater than 2", () => { const ssn = (0, parse_1.default)((0, makeSSN_1.default)({ gender: 3 })); expect(ssn.provisional).toBe(true); }); it("is provisional if controlKey is 98", () => { const ssn = (0, parse_1.default)((0, makeSSN_1.default)({ controlKey: 98 })); expect(ssn.provisional).toBe(true); }); it("is not provisional otherwise", () => { const ssn = (0, parse_1.default)((0, makeSSN_1.default)({ gender: 1 })); expect(ssn.provisional).toBe(false); }); }); describe("corner cases", () => { it("works with unknown birth month", () => { expect((0, parse_1.default)((0, makeSSN_1.default)({ month: 20, }))).toEqual(expect.objectContaining({ birth: expect.objectContaining({ month: { unknown: true, }, }), })); }); it("throws an error if weird format", () => { expect(() => (0, parse_1.default)((0, makeSSN_1.default)({ place: "7b231" }))).toThrow("Unexpected error"); }); }); //# sourceMappingURL=parse.test.js.map