diff --git a/services/loopback/common/validations/specs/validateDni.spec.js b/services/loopback/common/validations/specs/validateDni.spec.js index 77b1fcea1..2e902d6a2 100644 --- a/services/loopback/common/validations/specs/validateDni.spec.js +++ b/services/loopback/common/validations/specs/validateDni.spec.js @@ -1,86 +1,101 @@ const validateDni = require('../validateDni'); describe('DNI validation', () => { - it('should return false for invented DNI', async () => { + it('should return false for invented DNI', () => { let isValid = validateDni('Pepinillos'); + expect(isValid).toBeFalsy(); }); - // Spanish + describe('Spanish', () => { + it('should return true for valid spanish DNI', () => { + let isValid = validateDni('20849756A'); - it('should return true for valid spanish DNI', async () => { - let isValid = validateDni('20849756A'); - expect(isValid).toBeTruthy(); + expect(isValid).toBeTruthy(); + }); + + it('should return true for spanish DNI with exceeded digits', () => { + let isValid = validateDni('208497563239A'); + + expect(isValid).toBeFalsy(); + }); + + it('should return false for spanish DNI with invalid letter', () => { + let isValid = validateDni('20243746E'); + + expect(isValid).toBeFalsy(); + }); + + it('should return true for valid spanish CIF', () => { + let isValid = validateDni('B97367486'); + + expect(isValid).toBeTruthy(); + }); + + it('should return false for spanish CIF with invalid letter', () => { + let isValid = validateDni('A97527786'); + + expect(isValid).toBeFalsy(); + }); }); - it('should return true for spanish DNI with exceeded digits', async () => { - let isValid = validateDni('208497563239A'); - expect(isValid).toBeFalsy(); + describe('French', () => { + it('should return true for valid french DNI', () => { + let isValid = validateDni('FR1B123456789'); + + expect(isValid).toBeTruthy(); + }); + + it('should return true for french DNI with exceeded digits', () => { + let isValid = validateDni('FR1B12345678910'); + + expect(isValid).toBeFalsy(); + }); + + it('should return true for french DNI with bad syntax', () => { + let isValid = validateDni('FR1B12345678A'); + + expect(isValid).toBeFalsy(); + }); }); - it('should return false for spanish DNI with invalid letter', async () => { - let isValid = validateDni('20243746E'); - expect(isValid).toBeFalsy(); + describe('Italian', () => { + it('should return true for valid italian DNI', () => { + let isValid = validateDni('IT12345678911'); + + expect(isValid).toBeTruthy(); + }); + + it('should return true for italian DNI with exceeded digits', () => { + let isValid = validateDni('IT123456789112'); + + expect(isValid).toBeFalsy(); + }); + + it('should return true for italian DNI with bad syntax', () => { + let isValid = validateDni('IT1234567891A'); + + expect(isValid).toBeFalsy(); + }); }); - it('should return true for valid spanish CIF', async () => { - let isValid = validateDni('B97367486'); - expect(isValid).toBeTruthy(); - }); + describe('Portuguese', () => { + it('should return true for valid portuguese DNI', () => { + let isValid = validateDni('PT123456789'); - it('should return false for spanish CIF with invalid letter', async () => { - let isValid = validateDni('A97527786'); - expect(isValid).toBeFalsy(); - }); + expect(isValid).toBeTruthy(); + }); - // French + it('should return true for portuguese DNI with exceeded digits', () => { + let isValid = validateDni('PT12345678910'); - it('should return true for valid french DNI', async () => { - let isValid = validateDni('FR1B123456789'); - expect(isValid).toBeTruthy(); - }); + expect(isValid).toBeFalsy(); + }); - it('should return true for french DNI with exceeded digits', async () => { - let isValid = validateDni('FR1B12345678910'); - expect(isValid).toBeFalsy(); - }); + it('should return true for portuguese DNI with bad syntax', () => { + let isValid = validateDni('PT12345678A'); - it('should return true for french DNI with bad syntax', async () => { - let isValid = validateDni('FR1B12345678A'); - expect(isValid).toBeFalsy(); - }); - - // Italian - - it('should return true for valid italian DNI', async () => { - let isValid = validateDni('IT12345678911'); - expect(isValid).toBeTruthy(); - }); - - it('should return true for italian DNI with exceeded digits', async () => { - let isValid = validateDni('IT123456789112'); - expect(isValid).toBeFalsy(); - }); - - it('should return true for italian DNI with bad syntax', async () => { - let isValid = validateDni('IT1234567891A'); - expect(isValid).toBeFalsy(); - }); - - // Portuguese - - it('should return true for valid portuguese DNI', async () => { - let isValid = validateDni('PT123456789'); - expect(isValid).toBeTruthy(); - }); - - it('should return true for portuguese DNI with exceeded digits', async () => { - let isValid = validateDni('PT12345678910'); - expect(isValid).toBeFalsy(); - }); - - it('should return true for portuguese DNI with bad syntax', async () => { - let isValid = validateDni('PT12345678A'); - expect(isValid).toBeFalsy(); + expect(isValid).toBeFalsy(); + }); }); });