Skip to content

Commit

Permalink
Merge pull request #188 from halorrr/clean-up-type-hacks
Browse files Browse the repository at this point in the history
clean up usage of T.cast and T.unsafe
  • Loading branch information
mmenanno authored Jan 31, 2024
2 parents 08090e7 + 2b8d2fd commit 381019f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
2 changes: 0 additions & 2 deletions test/lunchmoney/categories/category_calls_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ class CategoryCallsTest < ActiveSupport::TestCase
test "create_category returns an id of created category success response" do
VCR.use_cassette("categories/create_category_success") do
api_call = LunchMoney::CategoryCalls.new.create_category(name: "Create Category Test")
api_call = T.cast(api_call, T::Hash[Symbol, Integer])

assert_kind_of(Integer, api_call[:category_id])
end
Expand All @@ -113,7 +112,6 @@ class CategoryCallsTest < ActiveSupport::TestCase
test "create_category_group returns anid of created category group on success response" do
VCR.use_cassette("categories/create_category_group_success") do
api_call = LunchMoney::CategoryCalls.new.create_category_group(name: "Create Category Group Test")
api_call = T.cast(api_call, T::Hash[Symbol, Integer])

assert_kind_of(Integer, api_call[:category_id])
end
Expand Down
12 changes: 4 additions & 8 deletions test/lunchmoney/transactions/transaction_calls_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ class TransactionCallsTest < ActiveSupport::TestCase
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)
refute_nil(api_call[:ids])

T.unsafe(ids).each do |id|
api_call[:ids].each do |id|
assert_kind_of(Integer, id)
end
end
Expand All @@ -95,9 +94,8 @@ class TransactionCallsTest < ActiveSupport::TestCase
897349559,
transaction: random_update_transaction(status: "cleared"),
)
updated = T.cast(api_call, T::Hash[Symbol, T::Boolean])[:updated]

assert(updated)
assert(api_call[:updated])
end
end
end
Expand All @@ -109,7 +107,6 @@ class TransactionCallsTest < ActiveSupport::TestCase
LunchMoney::Split.new(amount: "47.54"),
]
api_call = LunchMoney::TransactionCalls.new.update_transaction(904778058, split:)
api_call = T.cast(api_call, { updated: T::Boolean, split: T.nilable(T::Array[Integer]) })

assert(api_call[:updated])

Expand Down Expand Up @@ -186,9 +183,8 @@ class TransactionCallsTest < ActiveSupport::TestCase
test "delete_transaction_group returns an array of transaction ids from the deleted group on success response" do
VCR.use_cassette("transactions/delete_transaction_group_success") do
api_call = LunchMoney::TransactionCalls.new.delete_transaction_group(905483362)
api_call = T.cast(api_call, T::Hash[Symbol, T::Array[Integer]])

T.must(api_call[:transactions]).each do |transaction_id|
api_call[:transactions].each do |transaction_id|
assert_kind_of(Integer, transaction_id)
end
end
Expand Down

0 comments on commit 381019f

Please sign in to comment.