polish-validators
Version:
A set of validator functions that check common polish numbers.
39 lines (38 loc) • 2.53 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const postal_code_1 = require("./postal-code");
describe('Postal Code', () => {
it('should return true for a correctly formatted postal code with a dash', () => {
expect((0, postal_code_1.isPostalCodeValid)('12-345')).toBe(true); // with dash
});
it('should return true for a correctly formatted postal code without a dash', () => {
expect((0, postal_code_1.isPostalCodeValid)('12345')).toBe(true); // without dash
});
it('should return true for valid postal codes with leading zeros', () => {
expect((0, postal_code_1.isPostalCodeValid)('00-001')).toBe(true); // with dash
expect((0, postal_code_1.isPostalCodeValid)('00001')).toBe(true); // without dash
});
it('should return false for a postal code with an incorrect dash position', () => {
expect((0, postal_code_1.isPostalCodeValid)('123-45')).toBe(false); // dash in wrong position
expect((0, postal_code_1.isPostalCodeValid)('1-2345')).toBe(false); // dash in wrong position
});
it('should return false for valid postal codes but with other characters instead of a dash', () => {
expect((0, postal_code_1.isPostalCodeValid)('00/001')).toBe(false); // with slash
expect((0, postal_code_1.isPostalCodeValid)('00 001')).toBe(false); // with space
expect((0, postal_code_1.isPostalCodeValid)('00_001')).toBe(false); // with underscore
expect((0, postal_code_1.isPostalCodeValid)('00\\001')).toBe(false); // with backslash
expect((0, postal_code_1.isPostalCodeValid)('00.001')).toBe(false); // with dot
expect((0, postal_code_1.isPostalCodeValid)('00,001')).toBe(false); // with comma
});
it('should return false for a postal code with extra digits', () => {
expect((0, postal_code_1.isPostalCodeValid)('123-456')).toBe(false); // too many digits
expect((0, postal_code_1.isPostalCodeValid)('123456')).toBe(false); // too many digits without dash
});
it('should return false for a postal code with non-numeric characters', () => {
expect((0, postal_code_1.isPostalCodeValid)('12-34A')).toBe(false); // contains letter
expect((0, postal_code_1.isPostalCodeValid)('AB-345')).toBe(false); // letters instead of digits
});
it('should return false for an empty string', () => {
expect((0, postal_code_1.isPostalCodeValid)('')).toBe(false); // empty string
});
});