Skip to content

Commit 86d75f6

Browse files
committed
Fix integration tests due to new paginated responses
1 parent cf2e5cd commit 86d75f6

File tree

7 files changed

+38
-20
lines changed

7 files changed

+38
-20
lines changed

lib/square/inventory/client.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ def batch_create_changes(request_options: {}, **params)
170170
#
171171
# @return [Square::Types::BatchGetInventoryChangesResponse]
172172
def batch_get_changes(request_options: {}, **params)
173+
params = Square::Internal::Types::Utils.symbolize_keys(params)
174+
_query_param_names = %i[cursor]
175+
_query = params.slice(*_query_param_names)
176+
params = params.except(*_query_param_names)
177+
173178
Square::Internal::CursorItemIterator.new(
174179
cursor_field: :cursor,
175180
item_field: :changes,
@@ -211,6 +216,11 @@ def batch_get_changes(request_options: {}, **params)
211216
#
212217
# @return [Square::Types::BatchGetInventoryCountsResponse]
213218
def batch_get_counts(request_options: {}, **params)
219+
params = Square::Internal::Types::Utils.symbolize_keys(params)
220+
_query_param_names = %i[cursor]
221+
_query = params.slice(*_query_param_names)
222+
params = params.except(*_query_param_names)
223+
214224
Square::Internal::CursorItemIterator.new(
215225
cursor_field: :cursor,
216226
item_field: :counts,

test/square/integration/client_tests/test_customers_groups.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@ def delete_test_customer_group(group_id)
4242
# list
4343
list_response = client.customers.groups.list
4444
refute_nil list_response
45-
assert_equal list_response.class, Square::Types::ListCustomerGroupsResponse
46-
refute_nil list_response.groups
47-
assert list_response.groups.length > 0
45+
assert_equal Square::Internal::CursorItemIterator, list_response.class
46+
groups = list_response.to_a
47+
refute_nil groups
48+
assert groups.length > 0
4849

49-
puts "list_response #{list_response.to_h}" if verbose?
50+
puts "list_response #{groups}" if verbose?
5051

5152
# Cleanup
5253
delete_test_customer_group(response.group.id)

test/square/integration/client_tests/test_customers_segments.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,19 @@
88

99
response = client.customers.segments.list
1010
refute_nil response
11-
assert_equal response.class, Square::Types::ListCustomerSegmentsResponse
12-
refute_nil response.segments
11+
assert_equal Square::Internal::CursorItemIterator, response.class
12+
# Iterator wraps the response, we need to access the first page to get segments
13+
refute_nil response.to_a
1314

14-
puts "response #{response.to_h}" if verbose?
15+
puts "response #{response.to_a}" if verbose?
1516
end
1617
end
1718

1819
describe "#get" do
1920
it "should retrieve a customer segment" do
2021
list_response = client.customers.segments.list
21-
segment_id = list_response.segments.first.id
22+
segments = list_response.to_a
23+
segment_id = segments.first.id
2224

2325
_request = Square::Customers::Segments::Types::GetSegmentsRequest.new(
2426
segment_id: segment_id

test/square/integration/client_tests/test_merchants.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@
66
before do
77
# Get first merchant ID
88
merchant_response = client.merchants.list
9-
@merchant_id = merchant_response.merchant.first.id
9+
merchants = merchant_response.to_a
10+
@merchant_id = merchants.first.id
1011
end
1112

1213
describe "#list" do
1314
it "should list merchants" do
1415

1516
response = client.merchants.list
1617
refute_nil response
17-
assert_equal response.class, Square::Types::ListMerchantsResponse
18-
refute_nil response.merchant
19-
assert response.merchant.length > 0
18+
assert_equal Square::Internal::CursorItemIterator, response.class
19+
merchants = response.to_a
20+
refute_nil merchants
21+
assert merchants.length > 0
2022

21-
puts "response #{response.to_h}" if verbose?
23+
puts "response #{merchants}" if verbose?
2224
end
2325
end
2426

test/square/integration/client_tests/test_payments.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ def create_sample_payment
3131

3232
response = client.payments.list
3333
refute_nil response
34-
assert_equal response.class, Square::Types::ListPaymentsResponse
35-
refute_nil response.payments
36-
assert response.payments.length > 0
34+
assert_equal Square::Internal::CursorItemIterator, response.class
35+
payments = response.to_a
36+
refute_nil payments
37+
assert payments.length > 0
3738

38-
puts "response #{response.to_h}" if verbose?
39+
puts "response #{payments}" if verbose?
3940
end
4041
end
4142

test/square/integration/client_tests/test_refunds.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@
4747
puts "request #{_request.to_h}" if verbose?
4848

4949
response = client.refunds.list
50-
refute_nil response.refunds
51-
assert response.refunds.length > 0
50+
refunds = response.to_a
51+
refute_nil refunds
52+
assert refunds.length > 0
5253

53-
puts "response #{response.to_h}" if verbose?
54+
puts "response #{refunds}" if verbose?
5455
end
5556
end
5657

test/square/internal/multipart/test_form_data.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
require "stringio"
55
require "json"
66
require "test_helper"
7+
require "square/file_param"
78

89
class MockFile
910
attr_reader :name, :content, :content_type

0 commit comments

Comments
 (0)