2018-02-27 19:28:07 +00:00
|
|
|
const validateDni = require('../validateDni');
|
|
|
|
|
2018-02-27 19:28:59 +00:00
|
|
|
describe('DNI validation', () => {
|
2018-02-28 09:02:57 +00:00
|
|
|
it('should return false for invented DNI', () => {
|
2018-02-27 19:28:07 +00:00
|
|
|
let isValid = validateDni('Pepinillos');
|
2018-02-28 09:02:57 +00:00
|
|
|
|
2018-02-27 19:28:07 +00:00
|
|
|
expect(isValid).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
2018-02-28 09:02:57 +00:00
|
|
|
describe('Spanish', () => {
|
|
|
|
it('should return true for valid spanish DNI', () => {
|
|
|
|
let isValid = validateDni('20849756A');
|
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-12 13:13:36 +00:00
|
|
|
it('should return false for spanish DNI with exceeded digits', () => {
|
2018-02-28 09:02:57 +00:00
|
|
|
let isValid = validateDni('208497563239A');
|
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 false for spanish DNI with invalid letter', () => {
|
|
|
|
let isValid = validateDni('20243746E');
|
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', () => {
|
|
|
|
let isValid = validateDni('B97367486');
|
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', () => {
|
|
|
|
let isValid = validateDni('A97527786');
|
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('French', () => {
|
|
|
|
it('should return true for valid french DNI', () => {
|
2018-03-12 13:13:36 +00:00
|
|
|
let isValid = validateDni('1B123456789', 'fr');
|
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-12 13:13:36 +00:00
|
|
|
it('should return false for french DNI with exceeded digits', () => {
|
|
|
|
let isValid = validateDni('1B12345678910', 'fr');
|
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-12 13:13:36 +00:00
|
|
|
it('should return false for french DNI with bad syntax', () => {
|
|
|
|
let isValid = validateDni('1B12345678A', 'fr');
|
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', () => {
|
|
|
|
it('should return true for valid italian DNI', () => {
|
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-12 13:13:36 +00:00
|
|
|
it('should return false for italian DNI with exceeded digits', () => {
|
|
|
|
let isValid = validateDni('123456789112', 'it');
|
2018-02-28 09:02:57 +00:00
|
|
|
|
|
|
|
expect(isValid).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
2018-03-12 13:13:36 +00:00
|
|
|
it('should return false for italian DNI with bad syntax', () => {
|
|
|
|
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', () => {
|
|
|
|
it('should return true for valid portuguese DNI', () => {
|
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-12 13:13:36 +00:00
|
|
|
it('should return false for portuguese DNI with exceeded digits', () => {
|
|
|
|
let isValid = validateDni('12345678910', 'pt');
|
2018-02-28 09:02:57 +00:00
|
|
|
|
|
|
|
expect(isValid).toBeFalsy();
|
|
|
|
});
|
|
|
|
|
2018-03-12 13:13:36 +00:00
|
|
|
it('should return false for portuguese DNI with bad syntax', () => {
|
|
|
|
let isValid = validateDni('12345678A', 'pt');
|
2018-02-28 09:02:57 +00:00
|
|
|
|
|
|
|
expect(isValid).toBeFalsy();
|
|
|
|
});
|
2018-02-27 19:28:07 +00:00
|
|
|
});
|
|
|
|
});
|