Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Simplify committed Dec 1, 2021
1 parent 4619781 commit 029b643
Show file tree
Hide file tree
Showing 3 changed files with 21 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-01 Saša Jovanić <sasa@simplify.ba>
* Improve test coverage

2021-11-30 Saša Jovanić <sasa@simplify.ba>
* Added Estonian (EE) BBAN validation
* Added Finland (FI) BBAN validation
Expand Down
27 changes: 9 additions & 18 deletions src/IBANTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,18 +516,14 @@ interface CountryMapInternal {
const checkNorwayBBAN = (bban: string): boolean => {
const weights = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2];
const bbanWithoutSpacesAndPeriods = bban.replace(/[\s.]+/g, '');
if (bbanWithoutSpacesAndPeriods.length !== 11) {
return false;
} else {
const controlDigit = parseInt(bbanWithoutSpacesAndPeriods.charAt(10), 10);
const bbanWithoutControlDigit = bbanWithoutSpacesAndPeriods.substring(0, 10);
let sum = 0;
for (let index = 0; index < 10; index++) {
sum += parseInt(bbanWithoutControlDigit.charAt(index), 10) * weights[index];
}
const remainder = sum % 11;
return controlDigit === (remainder === 0 ? 0 : 11 - remainder);
const controlDigit = parseInt(bbanWithoutSpacesAndPeriods.charAt(10), 10);
const bbanWithoutControlDigit = bbanWithoutSpacesAndPeriods.substring(0, 10);
let sum = 0;
for (let index = 0; index < 10; index++) {
sum += parseInt(bbanWithoutControlDigit.charAt(index), 10) * weights[index];
}
const remainder = sum % 11;
return controlDigit === (remainder === 0 ? 0 : 11 - remainder);
};

/**
Expand Down Expand Up @@ -557,11 +553,8 @@ const checkBelgianBBAN = (bban: string): boolean => {
const stripped = bban.replace(/[\s.]+/g, '');
const checkingPart = parseInt(stripped.substring(0, stripped.length - 2), 10);
const checksum = parseInt(stripped.substring(stripped.length - 2, stripped.length), 10);
let reminder = checkingPart % 97;
if (reminder === 0) {
reminder = 97;
}
return reminder === checksum;
const remainder = checkingPart % 97 === 0 ? 97 : checkingPart % 97;
return remainder === checksum;
};

/**
Expand Down Expand Up @@ -801,8 +794,6 @@ const checkFrenchBBAN = (bban: string): boolean => {
case 90:
normalized[index] = '9';
break;
default:
break;
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions test/ibantools_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ describe('IBANTools', function() {
it('with valid CZ IBAN should return true', function() {
expect(iban.isValidIBAN('CZ6508000000192000145399')).to.be.true;
});
it('with invalid CZ IBAN should return false', function() {
expect(iban.isValidIBAN('CZ6508000000182000145399')).to.be.false;
});
it('with valid EE IBAN should return true', function() {
expect(iban.isValidIBAN('EE443300338400100007')).to.be.true;
});
Expand All @@ -257,6 +260,9 @@ describe('IBANTools', function() {
it('with valid FR IBAN should return true', function() {
expect(iban.isValidIBAN('FR1420041010050500013M02606')).to.be.true;
});
it('with valid FR IBAN should return true', function() {
expect(iban.isValidIBAN('FR22200410100505QZABCMGEF65')).to.be.true;
});
it('with valid MC IBAN should return true', function() {
expect(iban.isValidIBAN('MC5811222000010123456789030')).to.be.true;
});
Expand Down Expand Up @@ -530,6 +536,9 @@ describe('IBANTools', function() {
it('with valid BBAN for country code NO should return true', function() {
expect(iban.isValidBBAN('12043175449', 'NO')).to.be.true;
});
it('with too short BBAN for country code NO should return false', function() {
expect(iban.isValidBBAN('1204317544', 'NO')).to.be.false;
});
});

describe('When calling composeIBAN()', function() {
Expand Down

0 comments on commit 029b643

Please sign in to comment.