From d5472b00b3168af7d40199e7129db818b7e0a3d9 Mon Sep 17 00:00:00 2001 From: Jelle Hulter Date: Mon, 21 Mar 2022 16:00:45 +0100 Subject: [PATCH 1/4] fix: corrected the Costa Rican IBAN format (#643) Co-authored-by: Halvor --- src/iban.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/iban.ts b/src/iban.ts index 3f10e91be2e..89f1ecb5970 100644 --- a/src/iban.ts +++ b/src/iban.ts @@ -206,18 +206,18 @@ export = { }, { country: 'CR', - total: 21, + total: 22, bban: [ { type: 'n', - count: 3, + count: 4, }, { type: 'n', count: 14, }, ], - format: 'CRkk bbbc cccc cccc cccc c', + format: 'CRkk bbbb cccc cccc cccc cc', }, { country: 'HR', From 617d3d3b9d2aee0953946c888f06c82be10652fb Mon Sep 17 00:00:00 2001 From: Jelle Hulter Date: Tue, 22 Mar 2022 23:27:45 +0100 Subject: [PATCH 2/4] fix: Added Costa Rican IBAN test and splitted reserve digit in the formatting --- src/iban.ts | 8 +++++-- test/finance_iban.spec.ts | 44 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/iban.ts b/src/iban.ts index 89f1ecb5970..b608357ee93 100644 --- a/src/iban.ts +++ b/src/iban.ts @@ -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', diff --git a/test/finance_iban.spec.ts b/test/finance_iban.spec.ts index 23768387d85..220d73f17c8 100644 --- a/test/finance_iban.spec.ts +++ b/test/finance_iban.spec.ts @@ -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); + }); }); } }); From 2e2a5d1f849376d7e5502bbf43fb318403be2a1e Mon Sep 17 00:00:00 2001 From: Jelle Hulter Date: Tue, 22 Mar 2022 23:40:11 +0100 Subject: [PATCH 3/4] fix: Updated invalid comment for CR IBAN --- test/finance_iban.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/finance_iban.spec.ts b/test/finance_iban.spec.ts index 220d73f17c8..6cf182ec969 100644 --- a/test/finance_iban.spec.ts +++ b/test/finance_iban.spec.ts @@ -261,7 +261,7 @@ describe('finance_iban', () => { // https://wise.com/us/iban/costa-rica // Length 22 // BBAN 1n,3n,14n - // GEkk xbbb cccc cccc cccc cccc cccc + // CRkk xbbb cccc cccc cccc cccc cccc // x = reserve digit // b = National bank code (digits) // c = Account number (digits) From d0519e68a05c8c435f5370635a07a812b00cf4bb Mon Sep 17 00:00:00 2001 From: Jelle Hulter Date: Wed, 23 Mar 2022 08:07:52 +0100 Subject: [PATCH 4/4] fix: Changed test on first two characters of CR --- test/finance_iban.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/finance_iban.spec.ts b/test/finance_iban.spec.ts index 6cf182ec969..5c3fb9c9b6b 100644 --- a/test/finance_iban.spec.ts +++ b/test/finance_iban.spec.ts @@ -283,9 +283,9 @@ describe('finance_iban', () => { expect( iban.substring(0, 2), iban.substring(0, 2) + - ' must contains only characters in CR IBAN ' + + "must start with 'CR' in CR IBAN " + ibanFormated - ).match(/^[A-Z]{2}$/); + ).to.eq('CR'); expect( iban.substring(2, 22),