From 296dcd7f264e0933bfffd911b45cf27fecf7b196 Mon Sep 17 00:00:00 2001 From: Zach Gollwitzer Date: Fri, 23 May 2025 13:59:01 -0400 Subject: [PATCH] Transaction processor test cases --- .../investments/holdings_processor_test.rb | 15 +++++ .../investments/security_resolver_test.rb | 15 +++++ .../transactions_processor_test.rb | 15 +++++ .../transactions/processor_test.rb | 60 +++++++++++++++++++ 4 files changed, 105 insertions(+) create mode 100644 test/models/plaid_account/investments/holdings_processor_test.rb create mode 100644 test/models/plaid_account/investments/security_resolver_test.rb create mode 100644 test/models/plaid_account/investments/transactions_processor_test.rb create mode 100644 test/models/plaid_account/transactions/processor_test.rb diff --git a/test/models/plaid_account/investments/holdings_processor_test.rb b/test/models/plaid_account/investments/holdings_processor_test.rb new file mode 100644 index 00000000..5d0a06ab --- /dev/null +++ b/test/models/plaid_account/investments/holdings_processor_test.rb @@ -0,0 +1,15 @@ +require "test_helper" + +class PlaidAccount::Investments::HoldingsProcessorTest < ActiveSupport::TestCase + setup do + # TODO: set up holdings data and security resolver stub + end + + test "creates holding records from Plaid holdings snapshot" do + # TODO + end + + test "upserts security records via SecurityResolver" do + # TODO + end +end diff --git a/test/models/plaid_account/investments/security_resolver_test.rb b/test/models/plaid_account/investments/security_resolver_test.rb new file mode 100644 index 00000000..d154d536 --- /dev/null +++ b/test/models/plaid_account/investments/security_resolver_test.rb @@ -0,0 +1,15 @@ +require "test_helper" + +class PlaidAccount::Investments::SecurityResolverTest < ActiveSupport::TestCase + setup do + # TODO: stub security provider lookup + end + + test "finds existing security by identifiers" do + # TODO + end + + test "creates new security when none found" do + # TODO + end +end diff --git a/test/models/plaid_account/investments/transactions_processor_test.rb b/test/models/plaid_account/investments/transactions_processor_test.rb new file mode 100644 index 00000000..a377865b --- /dev/null +++ b/test/models/plaid_account/investments/transactions_processor_test.rb @@ -0,0 +1,15 @@ +require "test_helper" + +class PlaidAccount::Investments::TransactionsProcessorTest < ActiveSupport::TestCase + setup do + # TODO: set up investment plaid account and security resolver stub + end + + test "creates trade entries from Plaid investment transactions" do + # TODO + end + + test "handles security resolution for unknown securities" do + # TODO + end +end diff --git a/test/models/plaid_account/transactions/processor_test.rb b/test/models/plaid_account/transactions/processor_test.rb new file mode 100644 index 00000000..3c5bc10d --- /dev/null +++ b/test/models/plaid_account/transactions/processor_test.rb @@ -0,0 +1,60 @@ +require "test_helper" + +class PlaidAccount::Transactions::ProcessorTest < ActiveSupport::TestCase + setup do + @plaid_account = plaid_accounts(:one) + end + + test "processes added and modified plaid transactions" do + added_transactions = [ { "transaction_id" => "123" } ] + modified_transactions = [ { "transaction_id" => "456" } ] + + @plaid_account.update!(raw_transactions_payload: { + added: added_transactions, + modified: modified_transactions, + removed: [] + }) + + mock_processor = mock("PlaidEntry::TransactionProcessor") + PlaidEntry::TransactionProcessor.expects(:new) + .with(added_transactions.first, plaid_account: @plaid_account) + .returns(mock_processor) + .once + + PlaidEntry::TransactionProcessor.expects(:new) + .with(modified_transactions.first, plaid_account: @plaid_account) + .returns(mock_processor) + .once + + mock_processor.expects(:process).twice + + processor = PlaidAccount::Transactions::Processor.new(@plaid_account) + processor.process + end + + test "removes transactions no longer in plaid" do + destroyable_transaction_id = "destroy_me" + @plaid_account.account.entries.create!( + plaid_id: destroyable_transaction_id, + date: Date.current, + amount: 100, + name: "Destroy me", + currency: "USD", + entryable: Transaction.new + ) + + @plaid_account.update!(raw_transactions_payload: { + added: [], + modified: [], + removed: [ { "transaction_id" => destroyable_transaction_id } ] + }) + + processor = PlaidAccount::Transactions::Processor.new(@plaid_account) + + assert_difference [ "Entry.count", "Transaction.count" ], -1 do + processor.process + end + + assert_nil Entry.find_by(plaid_id: destroyable_transaction_id) + end +end