1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-09 07:25:19 +02:00

Transaction processor test cases

This commit is contained in:
Zach Gollwitzer 2025-05-23 13:59:01 -04:00
parent 4d9f86d073
commit 296dcd7f26
4 changed files with 105 additions and 0 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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