mirror of
https://github.com/we-promise/sure.git
synced 2026-07-26 19:52:15 +00:00
Fix enable banking not respecting pending transactions setting (#2686)
* Fix enable banking not respecting pending transactions setting * Nitpicks from coderabbit * Add tests for include_pending true and false * Fix RuboCop spacing in pending importer test --------- Co-authored-by: sure-admin <sure-admin@splashblot.com>
This commit is contained in:
@@ -143,4 +143,49 @@ class EnableBankingItem::ImporterPdngTest < ActiveSupport::TestCase
|
||||
|
||||
assert_equal @enable_banking_account.id, found.id
|
||||
end
|
||||
|
||||
# --- fetch_and_store_transactions behavior ---
|
||||
|
||||
test "fetch_and_store_transactions tags PDNG transaction as pending when include_pending is true" do
|
||||
@importer.stubs(:include_pending?).returns(true)
|
||||
|
||||
# Some ASPSPs ignore transaction_status=BOOK and return PDNG transactions anyway.
|
||||
tx = {
|
||||
entry_reference: "tx_ref",
|
||||
transaction_id: "tx_id",
|
||||
booking_date: "2026-03-05",
|
||||
transaction_amount: { amount: "10.00", currency: "EUR" },
|
||||
status: "PDNG"
|
||||
}
|
||||
|
||||
@importer.stubs(:fetch_paginated_transactions).with(@enable_banking_account, has_entries(transaction_status: "BOOK")).returns([ tx ])
|
||||
@importer.stubs(:fetch_paginated_transactions).with(@enable_banking_account, has_entries(transaction_status: "PDNG")).returns([ tx ])
|
||||
|
||||
result = @importer.send(:fetch_and_store_transactions, @enable_banking_account)
|
||||
|
||||
assert result[:success]
|
||||
stored = @enable_banking_account.raw_transactions_payload
|
||||
assert_equal 1, stored.size
|
||||
assert_equal true, stored.first.with_indifferent_access[:_pending]
|
||||
end
|
||||
|
||||
test "fetch_and_store_transactions filters out PDNG transaction when include_pending is false" do
|
||||
@importer.stubs(:include_pending?).returns(false)
|
||||
|
||||
# If include_pending is false, we must reject any PDNG transactions returned in the BOOK fetch.
|
||||
tx = {
|
||||
entry_reference: "tx_ref",
|
||||
transaction_id: "tx_id",
|
||||
booking_date: "2026-03-05",
|
||||
transaction_amount: { amount: "10.00", currency: "EUR" },
|
||||
status: "PDNG"
|
||||
}
|
||||
|
||||
@importer.stubs(:fetch_paginated_transactions).with(@enable_banking_account, has_entries(transaction_status: "BOOK")).returns([ tx ])
|
||||
|
||||
result = @importer.send(:fetch_and_store_transactions, @enable_banking_account)
|
||||
|
||||
assert result[:success]
|
||||
assert_nil @enable_banking_account.raw_transactions_payload
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user