Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

finish insert transaction call #161

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/lunchmoney/transactions/transaction_calls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ def transaction(transaction_id, debit_as_negative: nil)

sig do
params(
transactions: T::Array[LunchMoney::Transaction],
transactions: T::Array[LunchMoney::UpdateTransaction],
apply_rules: T.nilable(T::Boolean),
skip_duplicates: T.nilable(T::Boolean),
check_for_recurring: T.nilable(T::Boolean),
debit_as_negative: T.nilable(T::Boolean),
skip_balance_update: T.nilable(T::Boolean),
).returns(T.any(T::Hash[String, T::Array[Integer]], LunchMoney::Errors))
).returns(T.any(T::Hash[Symbol, T::Array[Integer]], LunchMoney::Errors))
end
def insert_transactions(transactions, apply_rules: nil, skip_duplicates: nil,
check_for_recurring: nil, debit_as_negative: nil, skip_balance_update: nil)
Expand Down
56 changes: 56 additions & 0 deletions test/cassettes/transactions/insert_transactions_success.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions test/lunchmoney/transactions/transaction_calls_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,39 @@ class TransactionCallsTest < ActiveSupport::TestCase
assert_kind_of(LunchMoney::Error, error)
end
end

test "insert_transactions returns a hash containing an array of ids on success response" do
VCR.use_cassette("transactions/insert_transactions_success") do
api_call = LunchMoney::TransactionCalls.new.insert_transactions([random_update_transaction])
ids = T.cast(api_call, T::Hash[Symbol, T::Array[Integer]])[:ids]

refute_nil(ids)

T.unsafe(ids).each do |id|
assert_kind_of(Integer, id)
end
end
end

test "insert_transactions returns an array of Error objects on error response" do
response = mock_faraday_lunchmoney_error_response
LunchMoney::TransactionCalls.any_instance.stubs(:post).returns(response)

api_call = LunchMoney::TransactionCalls.new.insert_transactions([random_update_transaction])

T.unsafe(api_call).each do |error|
assert_kind_of(LunchMoney::Error, error)
end
end

private

sig { returns(LunchMoney::UpdateTransaction) }
def random_update_transaction
date = Time.now.utc.strftime("%F")
amount = rand(0.1..99.9).to_s
payee = "Gem Remote Testing"
notes = "Remote test at #{Time.now.utc}"
LunchMoney::UpdateTransaction.new(date:, amount:, payee:, notes:)
end
end