dev #1731
|
@ -1,21 +1,45 @@
|
||||||
const validateIban = require('../validateIban');
|
const validateIban = require('../validateIban');
|
||||||
|
|
||||||
describe('IBAN validation', () => {
|
describe('IBAN validation', () => {
|
||||||
it('should return false for non-IBAN input', () => {
|
it('should return false for invalid Spanish IBAN format', () => {
|
||||||
let isValid = validateIban('Pepinillos');
|
let isValid = validateIban('ES00 9999 0000 9999 0000 9999', 'ES');
|
||||||
|
|
||||||
expect(isValid).toBeFalsy();
|
expect(isValid).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return false for invalid spanish IBAN input', () => {
|
it('should return true for valid Spanish IBAN', () => {
|
||||||
let isValid = validateIban('ES00 9999 0000 9999 0000 9999');
|
let isValid = validateIban('ES91 2100 0418 4502 0005 1332', 'ES');
|
||||||
|
|
||||||
expect(isValid).toBeFalsy();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return true for valid spanish IBAN', () => {
|
|
||||||
let isValid = validateIban('ES91 2100 0418 4502 0005 1332');
|
|
||||||
|
|
||||||
expect(isValid).toBeTruthy();
|
expect(isValid).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return false for invalid Spanish IBAN with incorrect length', () => {
|
||||||
|
let isValid = validateIban('ES91210004184502000513', 'ES');
|
||||||
|
|
||||||
|
expect(isValid).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for invalid Spanish IBAN with incorrect module97 result', () => {
|
||||||
|
let isValid = validateIban('ES9121000418450200051331', 'ES');
|
||||||
|
|
||||||
|
expect(isValid).toBeFalsy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true for a non-Spanish countryCode', () => {
|
||||||
|
let isValid = validateIban('DE89370400440532013000', 'AT');
|
||||||
|
|
||||||
|
expect(isValid).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true for null IBAN', () => {
|
||||||
|
let isValid = validateIban(null, 'ES');
|
||||||
|
|
||||||
|
expect(isValid).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false for non-string IBAN', () => {
|
||||||
|
let isValid = validateIban(12345, 'ES');
|
||||||
|
|
||||||
|
expect(isValid).toBeFalsy();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -90,6 +90,9 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
async function ibanNeedsValidation(err, done) {
|
async function ibanNeedsValidation(err, done) {
|
||||||
|
if (!this.bankEntityFk)
|
||||||
|
return done();
|
||||||
|
|
||||||
const bankEntity = await Self.app.models.BankEntity.findById(this.bankEntityFk);
|
const bankEntity = await Self.app.models.BankEntity.findById(this.bankEntityFk);
|
||||||
const filter = {
|
const filter = {
|
||||||
fields: ['code'],
|
fields: ['code'],
|
||||||
|
|
|
@ -7,6 +7,9 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
async function ibanValidation(err, done) {
|
async function ibanValidation(err, done) {
|
||||||
|
if (!this.bankEntityFk)
|
||||||
|
return done();
|
||||||
|
|
||||||
const bankEntity = await Self.app.models.BankEntity.findById(this.bankEntityFk);
|
const bankEntity = await Self.app.models.BankEntity.findById(this.bankEntityFk);
|
||||||
const filter = {
|
const filter = {
|
||||||
fields: ['code'],
|
fields: ['code'],
|
||||||
|
|
Loading…
Reference in New Issue