Skip to content

Commit

Permalink
Fix issue when country spec can not be found
Browse files Browse the repository at this point in the history
Fixes #83
  • Loading branch information
Simplify committed Dec 14, 2021
1 parent 3ef5198 commit 8d5389c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2021-12-14 Saša Jovanić <sasa@simplify.ba>
* Fix issue #83 - Fix problem when country can not be found when calling `validateIBAN`

2021-12-05 Saša Jovanić <sasa@simplify.ba>
* Version 4.1.1
* Added Hungarian (HU) BBAN validation
Expand Down
1 change: 1 addition & 0 deletions src/IBANTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export function validateIBAN(iban?: string): ValidateIBANResult {
if (!spec || !(spec.bban_regexp || spec.chars)) {
result.valid = false;
result.errorCodes.push(ValidationErrorsIBAN.NoIBANCountry);
return result;
}
if (spec && spec.chars && spec.chars !== iban.length) {
result.valid = false;
Expand Down
38 changes: 20 additions & 18 deletions test/ibantools_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ describe('IBANTools', function() {
it('with valid HU IBAN should return true', function() {
expect(iban.isValidIBAN('HU90100320000160120200000000')).to.be.true;
});
it('with two dots should return false', function() {
expect(iban.isValidIBAN('..')).to.be.false;
});
});

describe('When calling validateIBAN()', function() {
Expand All @@ -298,6 +301,13 @@ describe('IBANTools', function() {
});
});

it('with two dots instead of IBAN should return false', function() {
expect(iban.validateIBAN('..')).to.deep.equal({
valid: false,
errorCodes: [iban.ValidationErrorsIBAN.NoIBANCountry],
});
});

it('with undefined IBAN should return false', function() {
expect(iban.validateIBAN(undefined)).to.deep.equal({
valid: false,
Expand All @@ -315,31 +325,23 @@ describe('IBANTools', function() {
});
});

it('with invalid IBAN country and correct checksum should return false with correct code', function() {
expect(iban.validateIBAN('XX09ABNA0517164300')).to.deep.equal({
valid: false,
errorCodes: [iban.ValidationErrorsIBAN.NoIBANCountry],
});
});

it('with invalid IBAN country and wrong checksum should return false with wrong code', function() {
it('with invalid IBAN country should return false with error codes', function() {
expect(iban.validateIBAN('XX91ABNA0517164300')).to.deep.equal({
valid: false,
errorCodes: [iban.ValidationErrorsIBAN.NoIBANCountry, iban.ValidationErrorsIBAN.WrongIBANChecksum],
});
});

it('with country with no IBAN support should return false with correct code', function() {
expect(iban.validateIBAN('US64SVBKUS6S3300958879')).to.deep.equal({
valid: false,
errorCodes: [iban.ValidationErrorsIBAN.NoIBANCountry],
});
});

it('with country with no IBAN support and wrong checksum should return false with wrong code', function() {
expect(iban.validateIBAN('US46SVBKUS6S3300958879')).to.deep.equal({
it('with country code only should return false with wrong code', function() {
expect(iban.validateIBAN('NL')).to.deep.equal({
valid: false,
errorCodes: [iban.ValidationErrorsIBAN.NoIBANCountry, iban.ValidationErrorsIBAN.WrongIBANChecksum],
errorCodes: [
iban.ValidationErrorsIBAN.WrongBBANLength,
iban.ValidationErrorsIBAN.WrongBBANFormat,
iban.ValidationErrorsIBAN.WrongAccountBankBranchChecksum,
iban.ValidationErrorsIBAN.ChecksumNotNumber,
iban.ValidationErrorsIBAN.WrongIBANChecksum,
],
});
});

Expand Down

0 comments on commit 8d5389c

Please sign in to comment.