salix/loopback/util/specs/validateTin.spec.js

82 lines
2.4 KiB
JavaScript
Raw Normal View History

2018-03-21 11:57:23 +00:00
const validateDni = require('../validateTin');
2018-03-21 11:57:23 +00:00
describe('TIN validation', () => {
it('should return true for any TIN when no country is passed', () => {
let isValid = validateDni('Pepinillos');
2018-03-13 11:14:06 +00:00
expect(isValid).toBeTruthy();
});
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');
expect(isValid).toBeTruthy();
});
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');
expect(isValid).toBeFalsy();
});
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');
expect(isValid).toBeFalsy();
});
it('should return true for valid spanish CIF', () => {
2018-03-13 11:14:06 +00:00
let isValid = validateDni('B97367486', 'es');
expect(isValid).toBeTruthy();
});
it('should return false for spanish CIF with invalid letter', () => {
2018-03-13 11:14:06 +00:00
let isValid = validateDni('A97527786', 'es');
expect(isValid).toBeFalsy();
});
});
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');
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');
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');
expect(isValid).toBeFalsy();
});
});
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');
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');
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');
expect(isValid).toBeFalsy();
});
});
});