Merge branch 'dev' of http://git.verdnatura.es/salix into dev
This commit is contained in:
commit
9bcd859963
|
@ -72,9 +72,11 @@ export function validateAll(value, validations) {
|
|||
export function validate(value, conf) {
|
||||
let validator = validators[conf.validation];
|
||||
try {
|
||||
checkNull(value, conf);
|
||||
let isEmpty = value == null || value === '';
|
||||
|
||||
if (validator) // && value != null ??
|
||||
if (isEmpty)
|
||||
checkNull(value, conf);
|
||||
if (validator && (!isEmpty || conf.validation == 'presence'))
|
||||
validator(value, conf);
|
||||
} catch (e) {
|
||||
let message = conf.message ? conf.message : e.message;
|
||||
|
|
|
@ -58,7 +58,7 @@ describe('create client path', () => {
|
|||
it('should receive an error when clicking the create button having all the form fields empty but Tax Number', () => {
|
||||
return nightmare
|
||||
.clearInput(selectors.createClientView.name)
|
||||
.type(selectors.createClientView.taxNumber, 'AVG tax')
|
||||
.type(selectors.createClientView.taxNumber, '16195279J')
|
||||
.click(selectors.createClientView.createButton)
|
||||
.waitForSnackbar()
|
||||
.then(result => {
|
||||
|
@ -127,7 +127,7 @@ describe('create client path', () => {
|
|||
.wait(selectors.createClientView.email)
|
||||
.clearInput(selectors.createClientView.email)
|
||||
.type(selectors.createClientView.name, 'Carol Danvers')
|
||||
.type(selectors.createClientView.taxNumber, 'Avengers Tax Number')
|
||||
.type(selectors.createClientView.taxNumber, '16195279J')
|
||||
.type(selectors.createClientView.socialName, 'AVG tax')
|
||||
.type(selectors.createClientView.userName, 'CaptainMarvel')
|
||||
.type(selectors.createClientView.email, 'CarolDanvers@verdnatura.es')
|
||||
|
|
|
@ -43,7 +43,9 @@ module.exports = function(Self) {
|
|||
|
||||
var validateIban = require('../validations/validateIban');
|
||||
Self.validateBinded('iban', validateIban, {
|
||||
message: 'El iban no tiene el formato correcto'
|
||||
message: 'El iban no tiene el formato correcto',
|
||||
allowNull: true, // FIXME: Ignored by loopback when it's false
|
||||
allowBlank: true
|
||||
});
|
||||
|
||||
let validateDni = require('../validations/validateDni');
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
const validateDni = require('../validateDni');
|
||||
|
||||
describe('DNI validation', () => {
|
||||
it('should return false for invented DNI', async () => {
|
||||
let isValid = validateDni('Pepinillos');
|
||||
expect(isValid).toBeFalsy();
|
||||
});
|
||||
|
||||
// Spanish
|
||||
|
||||
it('should return true for valid spanish DNI', async () => {
|
||||
let isValid = validateDni('20849756A');
|
||||
expect(isValid).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should return true for spanish DNI with exceeded digits', async () => {
|
||||
let isValid = validateDni('208497563239A');
|
||||
expect(isValid).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should return false for spanish DNI with invalid letter', async () => {
|
||||
let isValid = validateDni('20243746E');
|
||||
expect(isValid).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should return true for valid spanish CIF', async () => {
|
||||
let isValid = validateDni('B97367486');
|
||||
expect(isValid).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should return false for spanish CIF with invalid letter', async () => {
|
||||
let isValid = validateDni('A97527786');
|
||||
expect(isValid).toBeFalsy();
|
||||
});
|
||||
|
||||
// French
|
||||
|
||||
it('should return true for valid french DNI', async () => {
|
||||
let isValid = validateDni('FR1B123456789');
|
||||
expect(isValid).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should return true for french DNI with exceeded digits', async () => {
|
||||
let isValid = validateDni('FR1B12345678910');
|
||||
expect(isValid).toBeFalsy();
|
||||
});
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
|
@ -1,6 +1,6 @@
|
|||
module.exports = fiWithCountry => {
|
||||
if (fiWithCountry == null)
|
||||
return true;
|
||||
module.exports = function(fiWithCountry) {
|
||||
if (fiWithCountry == null) return true;
|
||||
if (typeof fiWithCountry != 'string') return false;
|
||||
|
||||
fiWithCountry = fiWithCountry.toUpperCase();
|
||||
|
||||
|
@ -46,22 +46,21 @@ module.exports = fiWithCountry => {
|
|||
let index = 'XYZ'.indexOf(fi.charAt(0));
|
||||
let nif = index == -1 ? fi : index.toString() + fi.substring(1);
|
||||
|
||||
let number = parseInt(nif.substring(0, 8));
|
||||
let rest = number % 23;
|
||||
let rest = parseInt(nif.substring(0, 8)) % 23;
|
||||
computedDigit = 'TRWAGMYFPDXBNJZSQVHLCKE'.charAt(rest);
|
||||
}
|
||||
|
||||
return computedDigit == lastDigit;
|
||||
}
|
||||
},
|
||||
pt: {
|
||||
regExp: /^\d{9}$/
|
||||
},
|
||||
fr: {
|
||||
regExp: /^[A-Z0-9]{2}\d{9}$/
|
||||
},
|
||||
it: {
|
||||
regExp: /^\d{11}$/
|
||||
},
|
||||
pt: {
|
||||
regExp: /^\d{9}$/
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue