mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-04 21:15:19 +02:00
Only fetch needed Plaid products, improve Plaid tests and mocks
This commit is contained in:
parent
03a146222d
commit
6935ffa3d1
5 changed files with 188 additions and 246 deletions
105
test/models/plaid_item/accounts_snapshot_test.rb
Normal file
105
test/models/plaid_item/accounts_snapshot_test.rb
Normal file
|
@ -0,0 +1,105 @@
|
|||
require "test_helper"
|
||||
|
||||
class PlaidItem::AccountsSnapshotTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@plaid_item = plaid_items(:one)
|
||||
@plaid_item.plaid_accounts.destroy_all # Clean slate
|
||||
|
||||
@plaid_provider = mock
|
||||
@snapshot = PlaidItem::AccountsSnapshot.new(@plaid_item, plaid_provider: @plaid_provider)
|
||||
end
|
||||
|
||||
test "fetches accounts" do
|
||||
@plaid_provider.expects(:get_item_accounts).with(@plaid_item.access_token).returns(
|
||||
OpenStruct.new(accounts: [])
|
||||
)
|
||||
@snapshot.accounts
|
||||
end
|
||||
|
||||
test "fetches transactions data if item supports transactions and any accounts present" do
|
||||
@plaid_item.update!(available_products: [ "transactions" ], billed_products: [])
|
||||
|
||||
@snapshot.expects(:accounts).returns([
|
||||
OpenStruct.new(
|
||||
account_id: "123",
|
||||
type: "depository"
|
||||
)
|
||||
]).at_least_once
|
||||
|
||||
@plaid_provider.expects(:get_transactions).with(@plaid_item.access_token).once
|
||||
@plaid_provider.expects(:get_item_investments).never
|
||||
@plaid_provider.expects(:get_item_liabilities).never
|
||||
|
||||
@snapshot.get_account_data("123")
|
||||
end
|
||||
|
||||
test "does not fetch transactions if no accounts" do
|
||||
@plaid_item.update!(available_products: [ "transactions" ], billed_products: [])
|
||||
|
||||
@snapshot.expects(:accounts).returns([]).at_least_once
|
||||
|
||||
@plaid_provider.expects(:get_transactions).never
|
||||
@plaid_provider.expects(:get_item_investments).never
|
||||
@plaid_provider.expects(:get_item_liabilities).never
|
||||
|
||||
@snapshot.get_account_data("123")
|
||||
end
|
||||
|
||||
test "fetches investments data if item supports investments and investment accounts present" do
|
||||
@plaid_item.update!(available_products: [ "investments" ], billed_products: [])
|
||||
|
||||
@snapshot.expects(:accounts).returns([
|
||||
OpenStruct.new(
|
||||
account_id: "123",
|
||||
type: "investment"
|
||||
)
|
||||
]).at_least_once
|
||||
|
||||
@plaid_provider.expects(:get_transactions).never
|
||||
@plaid_provider.expects(:get_item_investments).with(@plaid_item.access_token).once
|
||||
@plaid_provider.expects(:get_item_liabilities).never
|
||||
|
||||
@snapshot.get_account_data("123")
|
||||
end
|
||||
|
||||
test "does not fetch investments if no investment accounts" do
|
||||
@plaid_item.update!(available_products: [ "investments" ], billed_products: [])
|
||||
|
||||
@snapshot.expects(:accounts).returns([]).at_least_once
|
||||
|
||||
@plaid_provider.expects(:get_transactions).never
|
||||
@plaid_provider.expects(:get_item_investments).never
|
||||
@plaid_provider.expects(:get_item_liabilities).never
|
||||
|
||||
@snapshot.get_account_data("123")
|
||||
end
|
||||
|
||||
test "fetches liabilities data if item supports liabilities and liabilities accounts present" do
|
||||
@plaid_item.update!(available_products: [ "liabilities" ], billed_products: [])
|
||||
|
||||
@snapshot.expects(:accounts).returns([
|
||||
OpenStruct.new(
|
||||
account_id: "123",
|
||||
type: "credit"
|
||||
)
|
||||
]).at_least_once
|
||||
|
||||
@plaid_provider.expects(:get_transactions).never
|
||||
@plaid_provider.expects(:get_item_investments).never
|
||||
@plaid_provider.expects(:get_item_liabilities).with(@plaid_item.access_token).once
|
||||
|
||||
@snapshot.get_account_data("123")
|
||||
end
|
||||
|
||||
test "does not fetch liabilities if no liabilities accounts" do
|
||||
@plaid_item.update!(available_products: [ "liabilities" ], billed_products: [])
|
||||
|
||||
@snapshot.expects(:accounts).returns([]).at_least_once
|
||||
|
||||
@plaid_provider.expects(:get_transactions).never
|
||||
@plaid_provider.expects(:get_item_investments).never
|
||||
@plaid_provider.expects(:get_item_liabilities).never
|
||||
|
||||
@snapshot.get_account_data("123")
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue