Skip to content
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
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList[
'test/square/integration/catalog/test_client.rb',
'test/square_legacy/api/test_*.rb'
]
t.warning = false
Expand Down
9 changes: 7 additions & 2 deletions lib/square/catalog/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,13 @@ def batch_get(request_options: {}, **params)
#
# @return [Square::Types::BatchUpsertCatalogObjectsResponse]
def batch_upsert(request_options: {}, **params)
_request = params
_response = @client.send(_request)
_response = @client.send(Internal::JSON::Request.new(
base_url: Square::Environment::SANDBOX,
path: "/v2/catalog/batch-upsert",
method: "POST",
body: Types::BatchUpsertCatalogObjectsRequest.new(params[:request]).to_h,
request_options: request_options
))
if _response.code >= "200" && _response.code < "300"
return Square::Types::BatchUpsertCatalogObjectsResponse.load(_response.body)
else
Expand Down
119 changes: 61 additions & 58 deletions test/square/integration/catalog/test_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,73 +5,76 @@
describe Square::Catalog::Client do
describe "#batch_upsert" do
it "creates multiple catalog objects" do
skip "Skipping for now."

response = client.catalog.batch_upsert(
request: {
idempotency_key: SecureRandom.uuid,
batches: [
{
objects: [
{
type: "ITEM",
id: "##{SecureRandom.uuid}",
present_at_all_locations: true,
item_data: {
name: "Coffee",
description: "Strong coffee",
abbreviation: "C",
variations: [
{
type: "ITEM_VARIATION",
id: "##{SecureRandom.uuid}",
present_at_all_locations: true,
item_variation_data: {
name: "Kona Coffee",
track_inventory: false,
pricing_type: "FIXED_PRICING",
price_money: {
amount: 1000,
currency: "USD"
}
_request = Square::Catalog::Types::BatchUpsertCatalogObjectsRequest.new(
idempotency_key: SecureRandom.uuid,
batches: [
{
objects: [
{
type: "ITEM",
id: "##{SecureRandom.uuid}",
present_at_all_locations: true,
item_data: {
name: "Coffee",
description: "Strong coffee",
abbreviation: "C",
variations: [
{
type: "ITEM_VARIATION",
id: "##{SecureRandom.uuid}",
present_at_all_locations: true,
item_variation_data: {
name: "Kona Coffee",
track_inventory: false,
pricing_type: "FIXED_PRICING",
price_money: {
amount: 1000,
currency: "USD"
}
}
]
}
},
{
type: "ITEM",
id: "##{SecureRandom.uuid}",
present_at_all_locations: true,
item_data: {
name: "Tea",
description: "Strong tea",
abbreviation: "T",
variations: [
{
type: "ITEM_VARIATION",
id: "##{SecureRandom.uuid}",
present_at_all_locations: true,
item_variation_data: {
name: "Gunpowder Green",
track_inventory: false,
pricing_type: "FIXED_PRICING",
price_money: {
amount: 2000,
currency: "USD"
}
}
]
}
},
{
type: "ITEM",
id: "##{SecureRandom.uuid}",
present_at_all_locations: true,
item_data: {
name: "Tea",
description: "Strong tea",
abbreviation: "T",
variations: [
{
type: "ITEM_VARIATION",
id: "##{SecureRandom.uuid}",
present_at_all_locations: true,
item_variation_data: {
name: "Gunpowder Green",
track_inventory: false,
pricing_type: "FIXED_PRICING",
price_money: {
amount: 2000,
currency: "USD"
}
}
]
}
}
]
}
]
}
]
}
}
]
}
]
)

puts "request #{_request.to_h}" if verbose?

response = client.catalog.batch_upsert(request: _request.to_h)
refute_nil response

puts "response #{response.to_h}" if verbose?

end
end
end
19 changes: 19 additions & 0 deletions test/square/integration/inventory/test_inventory_client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

require_relative "../../test_helper"

describe Square::Inventory::Client do
describe "#batch_get_changes" do
it "gets inventory changes" do

response = client.inventory.batch_get_changes(
request: {
catalog_object_ids: ["W62UWFY35CWMYGVWK6TWJDNI"],
location_ids: ["C6W5YS5QM06F5"]
}
)

refute_nil response
end
end
end
18 changes: 17 additions & 1 deletion test/square/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,26 @@ def test_token

def client
@client ||= Square::Client.new(
token: test_token
token: test_token,
base_url: Square::Environment::SANDBOX
)
end

def verbose_mode?
@verbose_mode ||= ENV.fetch("VERBOSE", "false") == "true"
end

def minitest_verbose?
return false unless defined?(Minitest)

# Check TESTOPTS environment variable for --verbose flag
ENV['TESTOPTS']&.include?('--verbose') || ARGV.include?('--verbose')
end

def verbose?
verbose_mode? || minitest_verbose?
end

require "minitest/autorun"
require "minitest/rg"

Expand Down