diff --git a/Rakefile b/Rakefile index bbe7b3e3..7f869fa4 100644 --- a/Rakefile +++ b/Rakefile @@ -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 diff --git a/lib/square/catalog/client.rb b/lib/square/catalog/client.rb index 0c476a19..66db48ab 100644 --- a/lib/square/catalog/client.rb +++ b/lib/square/catalog/client.rb @@ -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 diff --git a/test/square/integration/catalog/test_client.rb b/test/square/integration/catalog/test_client.rb index 61a7c01c..7b14d644 100644 --- a/test/square/integration/catalog/test_client.rb +++ b/test/square/integration/catalog/test_client.rb @@ -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 diff --git a/test/square/integration/inventory/test_inventory_client.rb b/test/square/integration/inventory/test_inventory_client.rb new file mode 100644 index 00000000..1e64c2e7 --- /dev/null +++ b/test/square/integration/inventory/test_inventory_client.rb @@ -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 diff --git a/test/square/test_helper.rb b/test/square/test_helper.rb index 958ef9f0..9cde6344 100644 --- a/test/square/test_helper.rb +++ b/test/square/test_helper.rb @@ -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"