Skip to content

Commit

Permalink
fix: Added Costa Rican IBAN test and splitted reserve digit in the fo…
Browse files Browse the repository at this point in the history
…rmatting
  • Loading branch information
MrGussio committed Mar 22, 2022
1 parent d5472b0 commit 617d3d3
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/iban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,18 @@ export = {
bban: [
{
type: 'n',
count: 4,
count: 1,
},
{
type: 'n',
count: 3,
},
{
type: 'n',
count: 14,
},
],
format: 'CRkk bbbb cccc cccc cccc cc',
format: 'CRkk xbbb cccc cccc cccc cc',
},
{
country: 'HR',
Expand Down
44 changes: 44 additions & 0 deletions test/finance_iban.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,50 @@ describe('finance_iban', () => {
'the result should be equal to 1'
).toBe(1);
});

it('IBAN for Costa Rica is correct', () => {
// Costa Rica
// https://wise.com/us/iban/costa-rica
// Length 22
// BBAN 1n,3n,14n
// GEkk xbbb cccc cccc cccc cccc cccc
// x = reserve digit
// b = National bank code (digits)
// c = Account number (digits)

// example IBAN CR05 0152 0200 1026 2840 66

const iban = faker.finance.iban(false, 'CR');

expect(iban).satisfy(validator.isIBAN);

const ibanFormated = iban.match(/.{1,4}/g).join(' ');
const bban = iban.substring(4) + iban.substring(0, 4);

expect(
22,
`CR IBAN would be 22 chars length, given is ${iban.length}`
).toBe(iban.length);

expect(
iban.substring(0, 2),
iban.substring(0, 2) +
' must contains only characters in CR IBAN ' +
ibanFormated
).match(/^[A-Z]{2}$/);

expect(
iban.substring(2, 22),
iban.substring(2, 22) +
' must contains only digit in AZ IBAN ' +
ibanFormated
).match(/^\d{20}$/);

expect(
ibanLib.mod97(ibanLib.toDigitString(bban)),
'the result should be equal to 1'
).toBe(1);
});
});
}
});
Expand Down

0 comments on commit 617d3d3

Please sign in to comment.