From f99b1563a845883b859ebf47714d964b6d897e29 Mon Sep 17 00:00:00 2001 From: halorrr Date: Fri, 26 Jan 2024 02:44:14 -0500 Subject: [PATCH] finish plaid_accounts call --- .../plaid_accounts/plaid_account.rb | 20 ++++++-- test/helpers/fake_response_data_helper.rb | 46 +++++++++++++++++++ .../plaid_account_calls_test.rb | 29 ++++++++++++ 3 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 test/lunchmoney/plaid_accounts/plaid_account_calls_test.rb diff --git a/lib/lunchmoney/plaid_accounts/plaid_account.rb b/lib/lunchmoney/plaid_accounts/plaid_account.rb index 1eb8e3c..7b369b9 100644 --- a/lib/lunchmoney/plaid_accounts/plaid_account.rb +++ b/lib/lunchmoney/plaid_accounts/plaid_account.rb @@ -17,10 +17,12 @@ class PlaidAccount < LunchMoney::DataObject :last_import, :balance, :currency, - :balance_last_update + :balance_last_update, + :display_name, + :plaid_last_successful_update sig { returns(T.nilable(String)) } - attr_accessor :subtype + attr_accessor :subtype, :import_start_date, :last_fetch sig { returns(T.nilable(Integer)) } attr_accessor :limit @@ -37,16 +39,22 @@ class PlaidAccount < LunchMoney::DataObject balance: String, currency: String, balance_last_update: String, + display_name: String, id: Integer, + plaid_last_successful_update: String, limit: T.nilable(Integer), subtype: T.nilable(String), + import_start_date: T.nilable(String), + last_fetch: T.nilable(String), ).void end - def initialize(date_linked:, name:, type:, mask:, institution_name:, status:, last_import:, - balance:, currency:, balance_last_update:, id:, limit: nil, subtype: nil) + def initialize(date_linked:, name:, type:, mask:, institution_name:, status:, last_import:, balance:, currency:, + balance_last_update:, display_name:, id:, plaid_last_successful_update:, limit: nil, subtype: nil, + import_start_date: nil, last_fetch: nil) super() @date_linked = date_linked @name = name + @display_name = display_name @type = type @mask = mask @institution_name = institution_name @@ -56,8 +64,12 @@ def initialize(date_linked:, name:, type:, mask:, institution_name:, status:, la @currency = currency @balance_last_update = balance_last_update @id = id + @plaid_last_successful_update = plaid_last_successful_update @limit = limit @subtype = subtype + @balance_last_update = balance_last_update + @import_start_date = import_start_date + @last_fetch = last_fetch end end end diff --git a/test/helpers/fake_response_data_helper.rb b/test/helpers/fake_response_data_helper.rb index d65ef74..5ae9146 100644 --- a/test/helpers/fake_response_data_helper.rb +++ b/test/helpers/fake_response_data_helper.rb @@ -178,4 +178,50 @@ def fake_all_categories_response ], } end + + sig { returns(T::Hash[String, T.untyped]) } + def fake_plaid_accounts_call + { + "plaid_accounts": [ + { + "id": 91, + "date_linked": "2020-01-28T14:15:09.111Z", + "name": "401k", + "display_name": "", + "type": "brokerage", + "subtype": "401k", + "mask": "7468", + "institution_name": "Vanguard", + "status": "inactive", + "limit": nil, + "balance": "12345.6700", + "currency": "usd", + "import_start_date": "2023-01-01", + "balance_last_update": "2020-01-27T01:38:11.862Z", + "last_import": "2019-09-04T12:57:09.190Z", + "last_fetch": "2020-01-28T01:38:11.862Z", + "plaid_last_successful_update": "2020-01-27T01:38:11.862Z", + }, + { + "id": 89, + "date_linked": "2020-01-28T14:15:09.111Z", + "name": "Freedom", + "display_name": "Freedom Card", + "type": "credit", + "subtype": "credit card", + "mask": "1973", + "institution_name": "Chase", + "status": "active", + "limit": 15000, + "balance": "0.0000", + "currency": "usd", + "import_start_date": "2023-01-01", + "balance_last_update": "2023-01-27T01:38:07.460Z", + "last_import": "2023-01-24T12:57:03.250Z", + "last_fetch": "2023-01-28T01:38:11.862Z", + "plaid_last_successful_update": "2023-01-27T01:38:11.862Z", + }, + ], + } + end end diff --git a/test/lunchmoney/plaid_accounts/plaid_account_calls_test.rb b/test/lunchmoney/plaid_accounts/plaid_account_calls_test.rb new file mode 100644 index 0000000..4c2f529 --- /dev/null +++ b/test/lunchmoney/plaid_accounts/plaid_account_calls_test.rb @@ -0,0 +1,29 @@ +# typed: strict +# frozen_string_literal: true + +require "test_helper" + +class PlaidAccountCallsTest < ActiveSupport::TestCase + include MockResponseHelper + include FakeResponseDataHelper + + test "plaid_accounts returns an array of PlaidAccount objects on success response" do + response = mock_faraday_response(fake_plaid_accounts_call) + + LunchMoney::PlaidAccountCalls.any_instance.stubs(:get).returns(response) + + api_call = LunchMoney::PlaidAccountCalls.new.plaid_accounts + + assert_kind_of(LunchMoney::PlaidAccount, api_call.first) + end + + test "plaid_accounts returns an array of Error objects on error response" do + response = mock_faraday_response(fake_general_error) + + LunchMoney::PlaidAccountCalls.any_instance.stubs(:get).returns(response) + + api_call = LunchMoney::PlaidAccountCalls.new.plaid_accounts + + assert_kind_of(LunchMoney::Error, api_call.first) + end +end