UNPKG

polish-validators

Version:

A set of validator functions that check common polish numbers.

41 lines (40 loc) 2.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const nip_1 = require("./nip"); describe('NIP', () => { it('should return true for a valid NIP with 10 digits', () => { expect((0, nip_1.isNipValid)('1234567890')).toBe(true); // 10-digit }); it('should return true for a valid NIP with 13 digits', () => { expect((0, nip_1.isNipValid)('1234563218123')).toBe(true); // 13-digit }); it('should return true for a valid NIP with dashes and whitespace', () => { expect((0, nip_1.isNipValid)('123-456-32 18')).toBe(true); // with separators }); it('should return false for a NIP with incorrect length', () => { expect((0, nip_1.isNipValid)('123456789')).toBe(false); // 9 digits expect((0, nip_1.isNipValid)('12345678901234')).toBe(false); // 14 digits }); it('should return false for an all-zero NIP', () => { expect((0, nip_1.isNipValid)('0000000000')).toBe(false); // 10 zeros expect((0, nip_1.isNipValid)('0000000000000')).toBe(false); // 13 zeros }); it('should return false for a NIP with non-numeric characters', () => { expect((0, nip_1.isNipValid)('12345678AB')).toBe(false); // contains letters expect((0, nip_1.isNipValid)('12345-678C')).toBe(false); // contains letters with dashes }); it('should return false if control number is incorrect', () => { expect((0, nip_1.isNipValid)('1234563219')).toBe(false); // wrong control number }); it('should return false for an empty string', () => { expect((0, nip_1.isNipValid)('')).toBe(false); // empty string }); }); describe('formatNip', () => { it('should format a valid NIP correctly', () => { expect((0, nip_1.formatNip)('1234567890')).toEqual('123-45-67-890'); }); it('should throw an error for an invalid NIP', () => { expect((0, nip_1.formatNip)('1234567891')).toEqual('Nieprawidłowy NIP'); }); });