Skip to content

Commit

Permalink
add missing tests and docs for asset calls
Browse files Browse the repository at this point in the history
  • Loading branch information
mmenanno committed Feb 1, 2024
1 parent a2a8e12 commit eaf5eff
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/lunchmoney/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,16 @@ def budget_calls
# @example [Get All Assets](https://lunchmoney.dev/#get-all-assets)
# api = LunchMoney::Api.new
# api.assets
# @example [Create Asset](https://lunchmoney.dev/#create-asset)
# api = LunchMoney::Api.new
# api.create_asset(
# type_name: "cash",
# name: "Create Asset Test",
# balance: "10.00",
# )
# @example [Update Asset](https://lunchmoney.dev/#update-asset)
# api = LunchMoney::Api.new
# api.update_asset(93746, balance: "99.99")
sig { returns(LunchMoney::Calls::Base) }
def asset_calls
with_valid_api_key do
Expand Down
1 change: 1 addition & 0 deletions lib/lunchmoney/objects/asset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Asset < LunchMoney::Objects::Object
"employee compensation",
"other liability",
"other asset",
"depository",
],
T::Array[String],
)
Expand Down
56 changes: 56 additions & 0 deletions test/cassettes/assets/create_asset_success.yml

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

56 changes: 56 additions & 0 deletions test/cassettes/assets/update_asset_success.yml

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

42 changes: 42 additions & 0 deletions test/lunchmoney/calls/assets_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,48 @@ class AssetsTest < ActiveSupport::TestCase

assert_kind_of(LunchMoney::Errors, api_call)
end

test "create_asset returns an Asset object on success response" do
VCR.use_cassette("assets/create_asset_success") do
api_call = LunchMoney::Calls::Assets.new.create_asset(
type_name: "cash",
name: "Create Asset Test",
balance: "10.00",
)

assert_kind_of(LunchMoney::Objects::Asset, api_call)
end
end

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

api_call = LunchMoney::Calls::Assets.new.create_asset(
type_name: "cash",
name: "Create Asset Test",
balance: "10.00",
)

assert_kind_of(LunchMoney::Errors, api_call)
end

test "update_asset returns an Asset object on success response" do
VCR.use_cassette("assets/update_asset_success") do
api_call = LunchMoney::Calls::Assets.new.update_asset(93746, balance: "99.99")

assert_kind_of(LunchMoney::Objects::Asset, api_call)
end
end

test "update_asset returns an array of Error objects on error response" do
response = mock_faraday_lunchmoney_error_response
LunchMoney::Calls::Assets.any_instance.stubs(:put).returns(response)

api_call = LunchMoney::Calls::Assets.new.update_asset(93746, balance: "99.99")

assert_kind_of(LunchMoney::Errors, api_call)
end
end
end
end

0 comments on commit eaf5eff

Please sign in to comment.