2018-03-21 11:57:23 +00:00
|
|
|
const validateDni = require('../validateTin');
|
2018-02-27 19:28:07 +00:00
|
|
|
|
2018-03-21 11:57:23 +00:00
|
|
|
describe('TIN validation', () => {
|
|
|
|
it('should return true for any TIN when no country is passed', () => {
|
2018-02-27 19:28:07 +00:00
|
|
|
let isValid = validateDni('Pepinillos');
|
2018-02-28 09:02:57 +00:00
|
|
|
|
2018-03-13 11:14:06 +00:00
|
|
|
expect(isValid).toBeTruthy();
|
2018-02-27 19:28:07 +00:00
|
|
|
});
|
|
|
|
|
2018-02-28 09:02:57 +00:00
|
|
|
describe('Spanish', () => {
|
2018-03-21 11:57:23 +00:00
|
|
|
it('should return true for valid spanish TIN', () => {
|
2018-03-13 11:14:06 +00:00
|
|
|
let isValid = validateDni('20849756A', 'es');
|
2018-02-27 19:28:07 +00:00
|
|
|
|
2018-02-28 09:02:57 +00:00
|
|
|
expect(isValid).toBeTruthy();
|
|
|
|
});
|
2018-02-27 19:28:07 +00:00
|
|
|
|
2018-03-21 11:57:23 +00:00
|
|
|
it('should return false for spanish TIN with exceeded digits', () => {
|
2018-03-13 11:14:06 +00:00
|
|
|
let isValid = validateDni('208497563239A', 'es');
|
2018-02-27 19:28:07 +00:00
|
|
|
|
2018-02-28 09:02:57 +00:00
|
|
|
expect(isValid).toBeFalsy();
|
|
|
|
});
|
2018-02-27 19:28:07 +00:00
|
|
|
|
2018-03-21 11:57:23 +00:00
|
|
|
it('should return false for spanish TIN with invalid letter', () => {
|
2018-03-13 11:14:06 +00:00
|
|
|
let isValid = validateDni('20243746E', 'es');
|
2018-02-27 19:28:07 +00:00
|
|
|
|
2018-02-28 09:02:57 +00:00
|
|
|
expect(isValid).toBeFalsy();
|
|
|
|
});
|
2018-02-27 19:28:07 +00:00
|
|
|
|
2018-02-28 09:02:57 +00:00
|
|
|
it('should return true for valid spanish CIF', () => {
|
2018-03-13 11:14:06 +00:00
|
|
|
let isValid = validateDni('B97367486', 'es');
|
2018-02-27 19:28:07 +00:00
|
|
|
|
2018-02-28 09:02:57 +00:00
|
|
|
expect(isValid).toBeTruthy();
|
|
|
|
});
|
2018-02-27 19:28:07 +00:00
|
|
|
|
2018-02-28 09:02:57 +00:00
|
|
|
it('should return false for spanish CIF with invalid letter', () => {
|
2018-03-13 11:14:06 +00:00
|
|
|
let isValid = validateDni('A97527786', 'es');
|
2018-02-27 19:28:07 +00:00
|
|
|
|
2018-02-28 09:02:57 +00:00
|
|
|
expect(isValid).toBeFalsy();
|
|
|
|
});
|
2018-02-27 19:28:07 +00:00
|
|
|
});
|
|
|
|
|
2018-02-28 09:02:57 +00:00
|
|
|
describe('Italian', () => {
|
2018-03-21 11:57:23 +00:00
|
|
|
it('should return true for valid italian TIN', () => {
|
2018-03-12 13:13:36 +00:00
|
|
|
let isValid = validateDni('12345678911', 'it');
|
2018-02-28 09:02:57 +00:00
|
|
|
|
|
|
|
expect(isValid).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
2018-03-21 11:57:23 +00:00
|
|
|
it('should return false for italian TIN with exceeded digits', () => {
|
2018-03-12 13:13:36 +00:00
|
|
|
let isValid = validateDni('123456789112', 'it');
|
2018-02-28 09:02:57 +00:00
|
|
|
|
|
|
|
expect(isValid).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
2018-03-21 11:57:23 +00:00
|
|
|
it('should return false for italian TIN with bad syntax', () => {
|
2018-03-12 13:13:36 +00:00
|
|
|
let isValid = validateDni('1234567891A', 'it');
|
2018-02-28 09:02:57 +00:00
|
|
|
|
|
|
|
expect(isValid).toBeFalsy();
|
|
|
|
});
|
2018-02-27 19:28:07 +00:00
|
|
|
});
|
|
|
|
|
2018-02-28 09:02:57 +00:00
|
|
|
describe('Portuguese', () => {
|
2018-03-21 11:57:23 +00:00
|
|
|
it('should return true for valid portuguese TIN', () => {
|
2018-03-12 13:13:36 +00:00
|
|
|
let isValid = validateDni('123456789', 'pt');
|
2018-02-28 09:02:57 +00:00
|
|
|
|
|
|
|
expect(isValid).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
2018-03-21 11:57:23 +00:00
|
|
|
it('should return false for portuguese TIN with exceeded digits', () => {
|
2018-03-12 13:13:36 +00:00
|
|
|
let isValid = validateDni('12345678910', 'pt');
|
2018-02-28 09:02:57 +00:00
|
|
|
|
|
|
|
expect(isValid).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
2018-03-21 11:57:23 +00:00
|
|
|
it('should return false for portuguese TIN with bad syntax', () => {
|
2018-03-12 13:13:36 +00:00
|
|
|
let isValid = validateDni('12345678A', 'pt');
|
2018-02-28 09:02:57 +00:00
|
|
|
|
|
|
|
expect(isValid).toBeFalsy();
|
|
|
|
});
|
2018-02-27 19:28:07 +00:00
|
|
|
});
|
|
|
|
});
|