Skip to content

Commit 9cd75a1

Browse files
fern-supportjsklan
andauthored
Enable catalog integration tests (#169)
* enable catalog test * modify test setup * messy status * current state * fix typo in multipart request * simplify state * progress, some nested values converting * progress, some nested values converting * log in coerce * restore request * request succeeds * remove logging from client and raw client * test passes, response parsed * update catalog client * add verbose mode handling in integration test helper --------- Co-authored-by: jsklan <jsklan.development@gmail.com>
1 parent 37bb9c6 commit 9cd75a1

File tree

5 files changed

+105
-61
lines changed

5 files changed

+105
-61
lines changed

Rakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Rake::TestTask.new(:test) do |t|
1111
t.libs << "test"
1212
t.libs << "lib"
1313
t.test_files = FileList[
14+
'test/square/integration/catalog/test_client.rb',
1415
'test/square_legacy/api/test_*.rb'
1516
]
1617
t.warning = false

lib/square/catalog/client.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,13 @@ def batch_get(request_options: {}, **params)
6767
#
6868
# @return [Square::Types::BatchUpsertCatalogObjectsResponse]
6969
def batch_upsert(request_options: {}, **params)
70-
_request = params
71-
_response = @client.send(_request)
70+
_response = @client.send(Internal::JSON::Request.new(
71+
base_url: Square::Environment::SANDBOX,
72+
path: "/v2/catalog/batch-upsert",
73+
method: "POST",
74+
body: Types::BatchUpsertCatalogObjectsRequest.new(params[:request]).to_h,
75+
request_options: request_options
76+
))
7277
if _response.code >= "200" && _response.code < "300"
7378
return Square::Types::BatchUpsertCatalogObjectsResponse.load(_response.body)
7479
else

test/square/integration/catalog/test_client.rb

Lines changed: 61 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,73 +5,76 @@
55
describe Square::Catalog::Client do
66
describe "#batch_upsert" do
77
it "creates multiple catalog objects" do
8-
skip "Skipping for now."
98

10-
response = client.catalog.batch_upsert(
11-
request: {
12-
idempotency_key: SecureRandom.uuid,
13-
batches: [
14-
{
15-
objects: [
16-
{
17-
type: "ITEM",
18-
id: "##{SecureRandom.uuid}",
19-
present_at_all_locations: true,
20-
item_data: {
21-
name: "Coffee",
22-
description: "Strong coffee",
23-
abbreviation: "C",
24-
variations: [
25-
{
26-
type: "ITEM_VARIATION",
27-
id: "##{SecureRandom.uuid}",
28-
present_at_all_locations: true,
29-
item_variation_data: {
30-
name: "Kona Coffee",
31-
track_inventory: false,
32-
pricing_type: "FIXED_PRICING",
33-
price_money: {
34-
amount: 1000,
35-
currency: "USD"
36-
}
9+
_request = Square::Catalog::Types::BatchUpsertCatalogObjectsRequest.new(
10+
idempotency_key: SecureRandom.uuid,
11+
batches: [
12+
{
13+
objects: [
14+
{
15+
type: "ITEM",
16+
id: "##{SecureRandom.uuid}",
17+
present_at_all_locations: true,
18+
item_data: {
19+
name: "Coffee",
20+
description: "Strong coffee",
21+
abbreviation: "C",
22+
variations: [
23+
{
24+
type: "ITEM_VARIATION",
25+
id: "##{SecureRandom.uuid}",
26+
present_at_all_locations: true,
27+
item_variation_data: {
28+
name: "Kona Coffee",
29+
track_inventory: false,
30+
pricing_type: "FIXED_PRICING",
31+
price_money: {
32+
amount: 1000,
33+
currency: "USD"
3734
}
3835
}
39-
]
40-
}
41-
},
42-
{
43-
type: "ITEM",
44-
id: "##{SecureRandom.uuid}",
45-
present_at_all_locations: true,
46-
item_data: {
47-
name: "Tea",
48-
description: "Strong tea",
49-
abbreviation: "T",
50-
variations: [
51-
{
52-
type: "ITEM_VARIATION",
53-
id: "##{SecureRandom.uuid}",
54-
present_at_all_locations: true,
55-
item_variation_data: {
56-
name: "Gunpowder Green",
57-
track_inventory: false,
58-
pricing_type: "FIXED_PRICING",
59-
price_money: {
60-
amount: 2000,
61-
currency: "USD"
62-
}
36+
}
37+
]
38+
}
39+
},
40+
{
41+
type: "ITEM",
42+
id: "##{SecureRandom.uuid}",
43+
present_at_all_locations: true,
44+
item_data: {
45+
name: "Tea",
46+
description: "Strong tea",
47+
abbreviation: "T",
48+
variations: [
49+
{
50+
type: "ITEM_VARIATION",
51+
id: "##{SecureRandom.uuid}",
52+
present_at_all_locations: true,
53+
item_variation_data: {
54+
name: "Gunpowder Green",
55+
track_inventory: false,
56+
pricing_type: "FIXED_PRICING",
57+
price_money: {
58+
amount: 2000,
59+
currency: "USD"
6360
}
6461
}
65-
]
66-
}
62+
}
63+
]
6764
}
68-
]
69-
}
70-
]
71-
}
65+
}
66+
]
67+
}
68+
]
7269
)
7370

71+
puts "request #{_request.to_h}" if verbose?
72+
73+
response = client.catalog.batch_upsert(request: _request.to_h)
7474
refute_nil response
75+
76+
puts "response #{response.to_h}" if verbose?
77+
7578
end
7679
end
7780
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "../../test_helper"
4+
5+
describe Square::Inventory::Client do
6+
describe "#batch_get_changes" do
7+
it "gets inventory changes" do
8+
9+
response = client.inventory.batch_get_changes(
10+
request: {
11+
catalog_object_ids: ["W62UWFY35CWMYGVWK6TWJDNI"],
12+
location_ids: ["C6W5YS5QM06F5"]
13+
}
14+
)
15+
16+
refute_nil response
17+
end
18+
end
19+
end

test/square/test_helper.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,26 @@ def test_token
88

99
def client
1010
@client ||= Square::Client.new(
11-
token: test_token
11+
token: test_token,
12+
base_url: Square::Environment::SANDBOX
1213
)
1314
end
1415

16+
def verbose_mode?
17+
@verbose_mode ||= ENV.fetch("VERBOSE", "false") == "true"
18+
end
19+
20+
def minitest_verbose?
21+
return false unless defined?(Minitest)
22+
23+
# Check TESTOPTS environment variable for --verbose flag
24+
ENV['TESTOPTS']&.include?('--verbose') || ARGV.include?('--verbose')
25+
end
26+
27+
def verbose?
28+
verbose_mode? || minitest_verbose?
29+
end
30+
1531
require "minitest/autorun"
1632
require "minitest/rg"
1733

0 commit comments

Comments
 (0)