diff --git a/CHANGELOG.md b/CHANGELOG.md index a2e18f9..8732927 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.20.0 - October 13, 2023 + +- Do not allow all 0 transit numbers in CA + ## 1.19.0 - October 3, 2023 - Do not allow all-0 account numbers for CA diff --git a/data/raw/pseudo_ibans.yml b/data/raw/pseudo_ibans.yml index e439b91..e38f133 100644 --- a/data/raw/pseudo_ibans.yml +++ b/data/raw/pseudo_ibans.yml @@ -20,7 +20,7 @@ CA: end: 12 excl: false :bank_code_format: "\\d{4}" - :branch_code_format: "\\d{5}" + :branch_code_format: "0{0,4}[1-9][0-9]{0,4}" :account_number_format: "(?!0+\\z)\\d{7,12}" :national_id_length: 9 :pseudo_iban_bank_code_length: 4 diff --git a/data/structures.yml b/data/structures.yml index c42c74f..5878b57 100644 --- a/data/structures.yml +++ b/data/structures.yml @@ -1500,7 +1500,7 @@ CA: end: 12 excl: false :bank_code_format: "\\d{4}" - :branch_code_format: "\\d{5}" + :branch_code_format: 0{0,4}[1-9][0-9]{0,4} :account_number_format: "(?!0+\\z)\\d{7,12}" :national_id_length: 9 :pseudo_iban_bank_code_length: 4 diff --git a/lib/ibandit/version.rb b/lib/ibandit/version.rb index 02174db..9555b16 100644 --- a/lib/ibandit/version.rb +++ b/lib/ibandit/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Ibandit - VERSION = "1.19.0" + VERSION = "1.20.0" end diff --git a/spec/ibandit/iban_spec.rb b/spec/ibandit/iban_spec.rb index 75f6659..c53fc5d 100755 --- a/spec/ibandit/iban_spec.rb +++ b/spec/ibandit/iban_spec.rb @@ -422,10 +422,55 @@ { country_code: "CA", bank_code: bank_code, - branch_code: "00063", + branch_code: branch_code, account_number: account_number, } end + let(:branch_code) { "00063" } + + context "and a 5 digit branch code" do + let(:account_number) { "0123456" } + let(:bank_code) { "036" } + let(:branch_code) { "00063" } + + 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(: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(:swift_national_id) { is_expected.to eq("003600063") } + its(:pseudo_iban) { is_expected.to eq("CAZZ003600063_____0123456") } + + its(:iban) { is_expected.to be_nil } + its(:valid?) { is_expected.to eq(true) } + its(:to_s) { is_expected.to eq("") } + end + + context "for an all zero transit number" do + let(:account_number) { "0123456" } + let(:bank_code) { "036" } + let(:branch_code) { "00000" } + + it "is invalid and has the correct errors" do + expect(subject.valid?).to eq(false) + expect(subject.errors). + to eq(branch_code: "format is invalid") + end + end + + context "and a 4 digit branch code" do + let(:account_number) { "0123456" } + let(:bank_code) { "036" } + let(:branch_code) { "0063" } + + it "is invalid and has the correct errors" do + expect(subject.valid?).to eq(false) + expect(subject.errors). + to eq(branch_code: "is the wrong length (should be 5 characters)") + end + end context "and a 3 digit bank code" do let(:account_number) { "0123456" }