From cb4f9aacdf1c7f634d671e6b293a46205d311ee5 Mon Sep 17 00:00:00 2001 From: Vinay P Date: Thu, 18 Oct 2018 08:52:49 +0100 Subject: [PATCH] Update local_details_cleaner for CA https://gocardless.myjetbrains.com/youtrack/issue/BANKINT-147 so that we generate valid IBANs for CA that allow for a minimum account number length of 7, and a maximum of 12. we do this by validating that the length is 12, and padding account number with 0s till it reaches that length. a workaround for not having account number validation that checks for length in a range. --- lib/ibandit/local_details_cleaner.rb | 4 ++- spec/ibandit/iban_spec.rb | 42 +++++++--------------- spec/ibandit/local_details_cleaner_spec.rb | 12 +++++++ 3 files changed, 27 insertions(+), 31 deletions(-) diff --git a/lib/ibandit/local_details_cleaner.rb b/lib/ibandit/local_details_cleaner.rb index e02d55f..19fcabc 100644 --- a/lib/ibandit/local_details_cleaner.rb +++ b/lib/ibandit/local_details_cleaner.rb @@ -85,7 +85,9 @@ def self.clean_be_details(local_details) end def self.clean_ca_details(local_details) - local_details + return {} if local_details[:account_number].length < 7 # minimum length + + { account_number: local_details[:account_number].rjust(12, "0") } end def self.clean_bg_details(local_details) diff --git a/spec/ibandit/iban_spec.rb b/spec/ibandit/iban_spec.rb index b027811..d479497 100755 --- a/spec/ibandit/iban_spec.rb +++ b/spec/ibandit/iban_spec.rb @@ -374,20 +374,14 @@ its(:country_code) { is_expected.to eq("CA") } its(:bank_code) { is_expected.to eq("0036") } its(:branch_code) { is_expected.to eq("00063") } - its(:account_number) { is_expected.to eq("0123456") } + its(:account_number) { is_expected.to eq("000000123456") } its(:swift_bank_code) { is_expected.to eq("0036") } its(:swift_branch_code) { is_expected.to eq("00063") } - its(:swift_account_number) { is_expected.to eq("0123456") } - its(:pseudo_iban) { is_expected.to eq("CAZZ003600063_____0123456") } - - # ibandit account number length validation can check for maximum - # length but not against a range, say, 7 to 12 digits, allowed in CA. - # - # given we are only going to deal with pseudo-IBANs in CA, choosing to - # not complete IBAN validation unless we need it. - # + its(:swift_account_number) { is_expected.to eq("000000123456") } + its(:pseudo_iban) { is_expected.to eq("CAZZ003600063000000123456") } + its(:iban) { is_expected.to be_nil } - its(:valid?) { is_expected.to eq(false) } + its(:valid?) { is_expected.to eq(true) } its(:to_s) { is_expected.to eq("") } end @@ -403,14 +397,8 @@ its(:swift_account_number) { is_expected.to eq("012345678900") } its(:pseudo_iban) { is_expected.to eq("CAZZ003600063012345678900") } - # ibandit account number length validation can check for maximum - # length but not against a range, say, 7 to 12 digits, allowed in CA. - # - # given we are only going to deal with pseudo-IBANs in CA, choosing to - # not complete IBAN validation unless we need it. - # its(:iban) { is_expected.to be_nil } - its(:valid?) { is_expected.to eq(true) } + its(:valid?) { is_expected.to be true } its(:to_s) { is_expected.to eq("") } end end @@ -421,24 +409,18 @@ its(:country_code) { is_expected.to eq("CA") } its(:bank_code) { is_expected.to eq("0036") } its(:branch_code) { is_expected.to eq("00063") } - its(:account_number) { is_expected.to eq("0123456") } + its(:account_number) { is_expected.to eq("000000123456") } its(:swift_bank_code) { is_expected.to eq("0036") } its(:swift_branch_code) { is_expected.to eq("00063") } - its(:swift_account_number) { is_expected.to eq("0123456") } - its(:pseudo_iban) { is_expected.to eq("CAZZ003600063_____0123456") } - - # ibandit account number length validation can check for maximum - # length but not against a range, say, 7 to 12 digits, allowed in CA. - # - # given we are only going to deal with pseudo-IBANs in CA, choosing to - # not complete IBAN validation unless we need it. - # + its(:swift_account_number) { is_expected.to eq("000000123456") } + its(:pseudo_iban) { is_expected.to eq("CAZZ003600063000000123456") } + its(:iban) { is_expected.to be_nil } - its(:valid?) { is_expected.to eq(false) } + its(:valid?) { is_expected.to be true } its(:to_s) { is_expected.to eq("") } end - context "when the input is an invalid Canadan pseudo-IBAN" do + context "when the input is an invalid Canadian pseudo-IBAN" do let(:arg) { "CAZZ00360006301234" } it "is invalid and has the correct errors" do diff --git a/spec/ibandit/local_details_cleaner_spec.rb b/spec/ibandit/local_details_cleaner_spec.rb index c0caeda..af42dde 100644 --- a/spec/ibandit/local_details_cleaner_spec.rb +++ b/spec/ibandit/local_details_cleaner_spec.rb @@ -141,6 +141,18 @@ end end + context "Canada" do + let(:country_code) { "CA" } + let(:account_number) { "0123456" } + let(:bank_code) { "0036" } + let(:branch_code) { "00063" } + + its([:account_number]) { is_expected.to eq("000000123456") } + its([:country_code]) { is_expected.to eq(country_code) } + its([:bank_code]) { is_expected.to eq("0036") } + its([:branch_code]) { is_expected.to eq("00063") } + end + context "Cyprus" do let(:country_code) { "CY" } let(:account_number) { "0000001200527600" }