Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle nil meta_data for truelayer bank transactions #7221

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/bank_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def bank_and_account_name
end

def has_tax_credits?
meta_data_codes = bank_transactions.pluck(:meta_data).pluck(:code)
meta_data_codes = bank_transactions.pluck(:meta_data).compact.pluck(:code)
meta_data_codes.include?("TC") || meta_data_codes.include?("WTC") || meta_data_codes.include?("CTC")
end

Expand Down
8 changes: 7 additions & 1 deletion spec/models/bank_account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,19 @@
end
end

describe "#tax_credits" do
describe "#has_tax_credits?" do
it "returns false if tax credits not present" do
bank_account = create(:bank_account)
create(:bank_transaction, :benefits, bank_account:)
expect(bank_account.has_tax_credits?).to be false
end

it "returns false if meta_data for all transactions is nil" do
bank_account = create(:bank_account)
create(:bank_transaction, :uncategorised_debit_transaction, meta_data: nil, bank_account:)
expect(bank_account.has_tax_credits?).to be false
end

it "returns true if tax credits are present" do
bank_account = create(:bank_account)
create(:bank_transaction, :with_meta_tax, bank_account:)
Expand Down