mirror of
https://github.com/we-promise/sure.git
synced 2026-04-13 00:57:22 +00:00
feat(enable-banking): enhance transaction import, metadata handling, and UI (#1406)
* feat(enable-banking): enhance transaction import, metadata handling, and UI * fix(enable-banking): address security, sync edge cases and PR feedback * fix(enable-banking): resolve silent failures, auth overrides, and sync logic bugs * fix(enable-banking): resolve sync logic bugs, trailing whitespaces, and apply safe_psu_headers * test(enable-banking): mock set_current_balance to return success result * fix(budget): properly filter pending transactions and classify synced loan payments * style: fix trailing whitespace detected by rubocop * refactor: address code review feedback for Enable Banking sync and reporting --------- Signed-off-by: Louis <contact@boul2gom.com> Signed-off-by: Juan José Mata <juanjo.mata@gmail.com> Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
This commit is contained in:
@@ -117,4 +117,95 @@ class EnableBankingEntry::ProcessorTest < ActiveSupport::TestCase
|
||||
entry = @account.entries.find_by!(external_id: "enable_banking_string_key_ref", source: "enable_banking")
|
||||
assert_equal 15.0, entry.amount.to_f
|
||||
end
|
||||
|
||||
test "includes note field in transaction notes alongside remittance_information" do
|
||||
tx = {
|
||||
entry_reference: "ref_note",
|
||||
transaction_id: nil,
|
||||
booking_date: Date.current.to_s,
|
||||
transaction_amount: { amount: "10.00", currency: "EUR" },
|
||||
credit_debit_indicator: "DBIT",
|
||||
remittance_information: [ "Facture 2026-001" ],
|
||||
note: "Détail comptable interne",
|
||||
status: "BOOK"
|
||||
}
|
||||
|
||||
EnableBankingEntry::Processor.new(tx, enable_banking_account: @enable_banking_account).process
|
||||
entry = @account.entries.find_by!(external_id: "enable_banking_ref_note")
|
||||
assert_includes entry.notes, "Facture 2026-001"
|
||||
assert_includes entry.notes, "Détail comptable interne"
|
||||
end
|
||||
|
||||
test "stores exchange_rate in extra when present" do
|
||||
tx = {
|
||||
entry_reference: "ref_fx",
|
||||
transaction_id: nil,
|
||||
booking_date: Date.current.to_s,
|
||||
transaction_amount: { amount: "100.00", currency: "EUR" },
|
||||
credit_debit_indicator: "DBIT",
|
||||
exchange_rate: {
|
||||
unit_currency: "USD",
|
||||
exchange_rate: "1.0821",
|
||||
rate_type: "SPOT",
|
||||
instructed_amount: { amount: "108.21", currency: "USD" }
|
||||
},
|
||||
status: "BOOK"
|
||||
}
|
||||
|
||||
EnableBankingEntry::Processor.new(tx, enable_banking_account: @enable_banking_account).process
|
||||
entry = @account.entries.find_by!(external_id: "enable_banking_ref_fx")
|
||||
eb_extra = entry.transaction&.extra&.dig("enable_banking")
|
||||
assert_equal "1.0821", eb_extra["fx_rate"]
|
||||
assert_equal "USD", eb_extra["fx_unit_currency"]
|
||||
assert_equal "108.21", eb_extra["fx_instructed_amount"]
|
||||
end
|
||||
|
||||
test "stores merchant_category_code in extra when present" do
|
||||
tx = {
|
||||
entry_reference: "ref_mcc",
|
||||
transaction_id: nil,
|
||||
booking_date: Date.current.to_s,
|
||||
transaction_amount: { amount: "25.00", currency: "EUR" },
|
||||
credit_debit_indicator: "DBIT",
|
||||
merchant_category_code: "5411",
|
||||
status: "BOOK"
|
||||
}
|
||||
|
||||
EnableBankingEntry::Processor.new(tx, enable_banking_account: @enable_banking_account).process
|
||||
entry = @account.entries.find_by!(external_id: "enable_banking_ref_mcc")
|
||||
eb_extra = entry.transaction&.extra&.dig("enable_banking")
|
||||
assert_equal "5411", eb_extra["merchant_category_code"]
|
||||
end
|
||||
|
||||
test "stores pending true in extra for PDNG-tagged transactions" do
|
||||
tx = {
|
||||
entry_reference: "ref_pdng",
|
||||
transaction_id: nil,
|
||||
booking_date: Date.current.to_s,
|
||||
transaction_amount: { amount: "15.00", currency: "EUR" },
|
||||
credit_debit_indicator: "DBIT",
|
||||
status: "PDNG",
|
||||
_pending: true
|
||||
}
|
||||
|
||||
EnableBankingEntry::Processor.new(tx, enable_banking_account: @enable_banking_account).process
|
||||
entry = @account.entries.find_by!(external_id: "enable_banking_ref_pdng")
|
||||
eb_extra = entry.transaction&.extra&.dig("enable_banking")
|
||||
assert_equal true, eb_extra["pending"]
|
||||
end
|
||||
|
||||
test "does not add enable_banking extra key when no extra data present" do
|
||||
tx = {
|
||||
entry_reference: "ref_noextra",
|
||||
transaction_id: nil,
|
||||
booking_date: Date.current.to_s,
|
||||
transaction_amount: { amount: "5.00", currency: "EUR" },
|
||||
credit_debit_indicator: "DBIT",
|
||||
status: "BOOK"
|
||||
}
|
||||
|
||||
EnableBankingEntry::Processor.new(tx, enable_banking_account: @enable_banking_account).process
|
||||
entry = @account.entries.find_by!(external_id: "enable_banking_ref_noextra")
|
||||
assert_nil entry.transaction&.extra&.dig("enable_banking")
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user