Skip to content

Commit

Permalink
Merge pull request #130 from halorrr/plaid_accounts_call
Browse files Browse the repository at this point in the history
finish plaid_accounts call
  • Loading branch information
mmenanno authored Jan 26, 2024
2 parents 233a738 + f99b156 commit c8840d9
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 4 deletions.
20 changes: 16 additions & 4 deletions lib/lunchmoney/plaid_accounts/plaid_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
46 changes: 46 additions & 0 deletions test/helpers/fake_response_data_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 29 additions & 0 deletions test/lunchmoney/plaid_accounts/plaid_account_calls_test.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c8840d9

Please sign in to comment.