Skip to content

Commit

Permalink
Update local_details_cleaner for CA
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Vinay P committed Oct 18, 2018
1 parent 19eef9d commit cb4f9aa
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 31 deletions.
4 changes: 3 additions & 1 deletion lib/ibandit/local_details_cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
42 changes: 12 additions & 30 deletions spec/ibandit/iban_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions spec/ibandit/local_details_cleaner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down

0 comments on commit cb4f9aa

Please sign in to comment.