From 50c7a5fd73505ca95a169ab75d1919922db8ce5d Mon Sep 17 00:00:00 2001 From: jsklan Date: Tue, 19 Aug 2025 19:06:15 -0400 Subject: [PATCH 1/2] cash, catalog, customers groups --- .../client_tests/test_cash_drawers.rb | 5 +- .../integration/client_tests/test_catalog.rb | 113 +++++++++++------- .../client_tests/test_customers_groups.rb | 34 +++--- 3 files changed, 90 insertions(+), 62 deletions(-) diff --git a/test/square/integration/client_tests/test_cash_drawers.rb b/test/square/integration/client_tests/test_cash_drawers.rb index 79a3ff42..2cfd0a4c 100644 --- a/test/square/integration/client_tests/test_cash_drawers.rb +++ b/test/square/integration/client_tests/test_cash_drawers.rb @@ -9,16 +9,17 @@ start_time = Time.now - 3600 # 1 hour ago end_time = Time.now - _request = { + _request = Square::CashDrawers::Types::ListCashDrawerShiftsRequest.new( location_id: client.locations.list.locations.first.id, begin_time: start_time.iso8601, end_time: end_time.iso8601 - } + ) puts "request #{_request.to_h}" if verbose? response = client.cash_drawers.shifts.list(request: _request.to_h) refute_nil response + assert_equal response.class, Square::Types::ListCashDrawerShiftsResponse puts "response #{response.to_h}" if verbose? end diff --git a/test/square/integration/client_tests/test_catalog.rb b/test/square/integration/client_tests/test_catalog.rb index ac973c33..611604aa 100644 --- a/test/square/integration/client_tests/test_catalog.rb +++ b/test/square/integration/client_tests/test_catalog.rb @@ -9,6 +9,8 @@ def delete_all_catalog_objects(client) catalog_objects_resp = client.catalog.list + refute_nil catalog_objects_resp + assert_equal catalog_objects_resp.class, Square::Types::ListCatalogResponse object_ids = [] catalog_objects_resp.data.each do |catalog_object| @@ -24,7 +26,10 @@ def delete_all_catalog_objects(client) object_ids << variation.id end - client.catalog.batch_delete(object_ids: object_ids) + _batch_delete_request = Square::Catalog::Types::BatchDeleteCatalogObjectsRequest.new( + object_ids: object_ids + ) + client.catalog.batch_delete(request: _batch_delete_request.to_h) end def create_test_catalog_item(name: "Test Item #{SecureRandom.uuid}", description: "Test Description", abbreviation: "TI", price: 100, variation_name: "Regular") @@ -177,14 +182,14 @@ def get_test_file } } - _request = { + _request = Square::Catalog::Types::BatchUpsertCatalogObjectsRequest.new( idempotency_key: SecureRandom.uuid, batches: [ { objects: [tax, modifier_list] } ] - } + ) puts "request #{_request.to_h}" if verbose? @@ -192,6 +197,7 @@ def get_test_file assert response assert_equal 2, response.objects.length + assert_equal response.class, Square::Types::BatchUpsertCatalogObjectsResponse # Store IDs for later use response.id_mappings&.each do |mapping| @@ -232,6 +238,7 @@ def get_test_file # Create the catalog objects in a bulk request create_catalog_objects_resp = client.catalog.batch_upsert(request: _request.to_h) assert_equal 200, create_catalog_objects_resp.objects.length + assert_equal create_catalog_objects_resp.class, Square::Types::BatchUpsertCatalogObjectsResponse sleep(2) # Wait after bulk creation puts "create_response objects_count=#{create_catalog_objects_resp.objects.length}" if verbose? @@ -287,14 +294,14 @@ def get_test_file sleep(3) puts 'Creating catalog object...' if verbose? - _create_request = { + _create_request = Square::Catalog::Types::BatchUpsertCatalogObjectsRequest.new( idempotency_key: SecureRandom.uuid, batches: [ { objects: [catalog_object] } ] - } + ) puts "create_catalog_request #{_create_request.keys}" if verbose? @@ -314,7 +321,7 @@ def get_test_file # Create a new catalog image image_name = "Test Image #{SecureRandom.uuid}" - _image_request = { + _image_request = Square::Catalog::Types::UpsertCatalogImageRequest.new( image_file: image_file, request: { idempotency_key: SecureRandom.uuid, @@ -327,7 +334,7 @@ def get_test_file } } } - } + ) puts "image_upload_request #{_image_request[:request].to_h}" if verbose? @@ -343,9 +350,12 @@ def get_test_file puts 'Starting cleanup...' if verbose? # Cleanup: Delete the created catalog object and image - client.catalog.batch_delete( + _batch_delete_request = Square::Catalog::Types::BatchDeleteCatalogObjectsRequest.new( object_ids: [created_catalog_object.id, create_catalog_image_resp.image.id] ) + _batch_delete_resp = client.catalog.batch_delete(request: _batch_delete_request.to_h) + refute_nil _batch_delete_resp + assert_equal _batch_delete_resp.class, Square::Types::BatchDeleteCatalogObjectsResponse puts 'Cleanup completed' if verbose? # If we get here, the test succeeded, so break out of retry loop @@ -368,13 +378,10 @@ def get_test_file it "catalog info" do skip "Skipping for now." sleep(2) # Wait before info request - - _request = {} - - puts "request #{_request.to_h}" if verbose? response = client.catalog.info - assert response + refute_nil response + assert_equal response.class, Square::Types::CatalogInfoResponse puts "response #{response.to_h}" if verbose? end @@ -384,13 +391,10 @@ def get_test_file it "list catalog" do skip "Skipping for now." sleep(2) # Wait before list request - - _request = {} - - puts "request #{_request.to_h}" if verbose? response = client.catalog.list - assert response + refute_nil response + assert_equal response.class, Square::Types::ListCatalogResponse puts "response items_count=#{response.data&.length || 0}" if verbose? end @@ -401,12 +405,13 @@ def get_test_file skip "Skipping for now." sleep(2) # Wait before search - _request = { limit: 1 } - - puts "request #{_request.to_h}" if verbose? + _request = Square::Catalog::Types::SearchCatalogObjectsRequest.new( + limit: 1 + ) - response = client.catalog.search(limit: 1) - assert response + response = client.catalog.search(request: _request.to_h) + refute_nil response + assert_equal response.class, Square::Types::SearchCatalogObjectsResponse puts "response items_count=#{response.objects&.length || 0}" if verbose? end @@ -434,15 +439,17 @@ def get_test_file sleep(2) # Wait before batch retrieve # Use the IDs created in the batch upsert test - _request = { + _request = Square::Catalog::Types::BatchRetrieveCatalogObjectsRequest.new( object_ids: [@catalog_modifier_id, @catalog_modifier_list_id, @catalog_tax_id] - } + ) puts "request #{_request.to_h}" if verbose? response = client.catalog.batch_get(request: _request.to_h) - assert response.objects + refute_nil response + assert_equal response.class, Square::Types::BatchRetrieveCatalogObjectsResponse + refute_nil response.objects assert_equal 3, response.objects.length assert_equal [@catalog_modifier_id, @catalog_modifier_list_id, @catalog_tax_id].sort, response.objects.map(&:id).sort @@ -465,23 +472,27 @@ def get_test_file sleep(2) # Wait before update - _request = { + _request = Square::Catalog::Types::UpdateItemTaxesRequest.new( item_ids: [create_resp.catalog_object.id], taxes_to_enable: [@catalog_tax_id] - } + ) puts "request #{_request.to_h}" if verbose? response = client.catalog.update_item_taxes(request: _request.to_h) - assert response.updated_at + refute_nil response + assert_equal response.class, Square::Types::UpdateItemTaxesResponse + refute_nil response.updated_at puts "response updated_at=#{response.updated_at}" if verbose? sleep(2) # Wait before cleanup # Cleanup - client.catalog.object.delete(object_id: create_resp.catalog_object.id) + _delete_resp = client.catalog.object.delete(object_id: create_resp.catalog_object.id) + refute_nil _delete_resp + assert_equal _delete_resp.class, Square::Types::DeleteCatalogObjectResponse end end @@ -499,30 +510,34 @@ def get_test_file sleep(2) # Wait before update - _request = { + _request = Square::Catalog::Types::UpdateItemModifierListsRequest.new( item_ids: [create_resp.catalog_object.id], modifier_lists_to_enable: [@catalog_modifier_list_id] - } + ) puts "request #{_request.to_h}" if verbose? response = client.catalog.update_item_modifier_lists(request: _request.to_h) - assert response.updated_at + refute_nil response + assert_equal response.class, Square::Types::UpdateItemModifierListsResponse + refute_nil response.updated_at puts "response updated_at=#{response.updated_at}" if verbose? sleep(2) # Wait before cleanup # Cleanup - client.catalog.object.delete(object_id: create_resp.catalog_object.id) + _delete_resp = client.catalog.object.delete(object_id: create_resp.catalog_object.id) + refute_nil _delete_resp + assert_equal _delete_resp.class, Square::Types::DeleteCatalogObjectResponse end end describe "#upsert" do it "upserts an object" do skip "Skipping for now." - _request = { + _request = Square::Catalog::Types::UpsertCatalogObjectRequest.new( idempotency_key: SecureRandom.uuid, object: { type: "ITEM", @@ -550,12 +565,14 @@ def get_test_file ] } } - } + ) puts "request #{_request.to_h}" if verbose? - response = client.catalog.object.upsert(request: _request) + response = client.catalog.object.upsert(request: _request.to_h) refute_nil response + assert_equal response.class, Square::Types::UpsertCatalogObjectResponse + refute_nil response.catalog_object puts "response #{response.to_h}" if verbose? end @@ -572,18 +589,20 @@ def get_test_file sleep(2) # Wait before upsert - _request = { + _request = Square::Catalog::Types::UpsertCatalogObjectRequest.new( object: coffee, idempotency_key: SecureRandom.uuid - } + ) puts "request #{_request.to_h}" if verbose? response = client.catalog.object.upsert(request: _request.to_h) - + refute_nil response + assert_equal response.class, Square::Types::UpsertCatalogObjectResponse + refute_nil response.catalog_object + catalog_object = response.catalog_object - assert response assert catalog_object assert_equal "ITEM", catalog_object.type assert_equal 1, catalog_object.item_data.variations.length @@ -603,10 +622,10 @@ def get_test_file # First create a catalog object coffee = create_test_catalog_item - _create_request = { + _create_request = Square::Catalog::Types::UpsertCatalogObjectRequest.new( object: coffee, idempotency_key: SecureRandom.uuid - } + ) puts "create_request #{_create_request.keys}" if verbose? @@ -620,7 +639,9 @@ def get_test_file # Then retrieve it response = client.catalog.object.get(object_id: create_resp.catalog_object.id) - assert response.object + refute_nil response + assert_equal response.class, Square::Types::GetCatalogObjectResponse + refute_nil response.object assert_equal create_resp.catalog_object.id, response.object.id puts "response object_id=#{response.object.id}" if verbose? @@ -628,7 +649,9 @@ def get_test_file sleep(2) # Wait before cleanup # Cleanup - client.catalog.object.delete(object_id: create_resp.catalog_object.id) + _delete_resp = client.catalog.object.delete(object_id: create_resp.catalog_object.id) + refute_nil _delete_resp + assert_equal _delete_resp.class, Square::Types::DeleteCatalogObjectResponse end end end \ No newline at end of file diff --git a/test/square/integration/client_tests/test_customers_groups.rb b/test/square/integration/client_tests/test_customers_groups.rb index d9f92d27..f429a61b 100644 --- a/test/square/integration/client_tests/test_customers_groups.rb +++ b/test/square/integration/client_tests/test_customers_groups.rb @@ -4,45 +4,53 @@ describe Square::Customers::Groups::Client do def create_test_customer_group - client.customers.groups.create( + _create_request = Square::Customers::Groups::Types::CreateCustomerGroupRequest.new( idempotency_key: SecureRandom.uuid, group: { name: "Default-#{SecureRandom.uuid}" } ) + _create_resp = client.customers.groups.create(request: _create_request.to_h) + refute_nil _create_resp + assert_equal _create_resp.class, Square::Types::CreateCustomerGroupResponse + refute_nil _create_resp.group end def delete_test_customer_group(group_id) - client.customers.groups.delete(group_id: group_id) + _delete_request = Square::Customers::Groups::Types::DeleteGroupsRequest.new( + group_id: group_id + ) + _delete_resp = client.customers.groups.delete(request: _delete_request.to_h) + refute_nil _delete_resp + assert_equal _delete_resp.class, Square::Types::DeleteCustomerGroupResponse end describe "#create and list" do it "should create and list a customer group" do skip "Skipping for now." # create - _create_request = { + _create_request = Square::Customers::Groups::Types::CreateCustomerGroupRequest.new( idempotency_key: SecureRandom.uuid, group: { name: "Default-#{SecureRandom.uuid}" } - } + ) puts "create_request #{_create_request.to_h}" if verbose? response = create_test_customer_group refute_nil response.group refute_nil response.group.name + assert_equal response.class, Square::Types::CreateCustomerGroupResponse puts "create_response #{response.to_h}" if verbose? # list - _list_request = {} - - puts "list_request #{_list_request.to_h}" if verbose? - list_response = client.customers.groups.list - refute_nil list_response.data - assert list_response.data.length > 0 + refute_nil list_response + assert_equal list_response.class, Square::Types::ListCustomerGroupsResponse + refute_nil list_response.groups + assert list_response.groups.length > 0 puts "list_response #{list_response.to_h}" if verbose? @@ -106,11 +114,7 @@ def delete_test_customer_group(group_id) puts "request #{_request.to_h}" if verbose? - delete_response = delete_test_customer_group(create_response.group.id) - refute_nil delete_response - assert_nil delete_response.errors - - puts "response #{delete_response.to_h}" if verbose? + delete_test_customer_group(create_response.group.id) end end From 1c12830a024e56135fab360c12e5f7b4361c2dd4 Mon Sep 17 00:00:00 2001 From: jsklan Date: Tue, 19 Aug 2025 19:25:20 -0400 Subject: [PATCH 2/2] cleanup --- .../client_tests/test_customers_segments.rb | 22 +++--- .../integration/client_tests/test_devices.rb | 27 ++++--- .../client_tests/test_inventory.rb | 12 ++- .../client_tests/test_locations.rb | 5 +- .../client_tests/test_merchants.rb | 19 ++--- .../integration/client_tests/test_mobile.rb | 8 +- .../integration/client_tests/test_orders.rb | 58 +++++++------- .../integration/client_tests/test_payments.rb | 75 +++++++++++-------- .../integration/client_tests/test_refunds.rb | 72 +++++++++++------- .../client_tests/test_team_members.rb | 37 +++++---- .../integration/client_tests/test_terminal.rb | 33 +++++--- 11 files changed, 217 insertions(+), 151 deletions(-) diff --git a/test/square/integration/client_tests/test_customers_segments.rb b/test/square/integration/client_tests/test_customers_segments.rb index 14e4deb7..84495c29 100644 --- a/test/square/integration/client_tests/test_customers_segments.rb +++ b/test/square/integration/client_tests/test_customers_segments.rb @@ -6,13 +6,11 @@ describe "#list" do it "should list customer segments" do skip "Skipping for now." - _request = {} - - puts "request #{_request.to_h}" if verbose? - + response = client.customers.segments.list - refute_nil response.data - assert response.data.length > 0 + refute_nil response + assert_equal response.class, Square::Types::ListCustomerSegmentsResponse + refute_nil response.segments puts "response #{response.to_h}" if verbose? end @@ -22,13 +20,15 @@ it "should retrieve a customer segment" do skip "Skipping for now." list_response = client.customers.segments.list - segment_id = list_response.data.first.id - - _request = { segment_id: segment_id } + segment_id = list_response.segments.first.id - puts "request #{_request.to_h}" if verbose? + _request = Square::Customers::Segments::Types::GetCustomerSegmentRequest.new( + segment_id: segment_id + ) - response = client.customers.segments.get(segment_id: segment_id) + response = client.customers.segments.get(request: _request.to_h) + refute_nil response + assert_equal response.class, Square::Types::GetCustomerSegmentResponse refute_nil response.segment refute_nil response.segment.name diff --git a/test/square/integration/client_tests/test_devices.rb b/test/square/integration/client_tests/test_devices.rb index 985a60de..07702e6c 100644 --- a/test/square/integration/client_tests/test_devices.rb +++ b/test/square/integration/client_tests/test_devices.rb @@ -5,26 +5,25 @@ describe Square::Devices::Codes::Client do before do skip "Skipping for now." - create_response = client.devices.codes.create( + _create_request = Square::Devices::Codes::Types::CreateDeviceCodeRequest.new( idempotency_key: SecureRandom.uuid, device_code: Square::Devices::Types::DeviceCode.new( product_type: "TERMINAL_API" ) ) + create_response = client.devices.codes.create(request: _create_request.to_h) @device_code_id = create_response.device_code.id end describe "#list" do it "should list device codes" do skip "Skipping for now." - _request = {} - - puts "request #{_request.to_h}" if verbose? response = client.devices.codes.list refute_nil response - refute_nil response.data - assert response.data.length > 0 + assert_equal response.class, Square::Types::ListDeviceCodesResponse + refute_nil response.device_codes + assert response.device_codes.length > 0 puts "response #{response.to_h}" if verbose? end @@ -33,16 +32,18 @@ describe "#create" do it "should create device code" do skip "Skipping for now." - _request = { + _request = Square::Devices::Codes::Types::CreateDeviceCodeRequest.new( idempotency_key: SecureRandom.uuid, device_code: Square::Devices::Types::DeviceCode.new( product_type: "TERMINAL_API" ) - } + ) puts "request #{_request.to_h}" if verbose? response = client.devices.codes.create(request: _request.to_h) + refute_nil response + assert_equal response.class, Square::Types::CreateDeviceCodeResponse refute_nil response.device_code assert_equal "TERMINAL_API", response.device_code.product_type @@ -53,11 +54,13 @@ describe "#get" do it "should get device code" do skip "Skipping for now." - _request = { id: @device_code_id } - - puts "request #{_request.to_h}" if verbose? + _request = Square::Devices::Codes::Types::GetDeviceCodeRequest.new( + id: @device_code_id + ) - response = client.devices.codes.get(id: @device_code_id) + response = client.devices.codes.get(request: _request.to_h) + refute_nil response + assert_equal response.class, Square::Types::GetDeviceCodeResponse refute_nil response.device_code assert_equal @device_code_id, response.device_code.id assert_equal "TERMINAL_API", response.device_code.product_type diff --git a/test/square/integration/client_tests/test_inventory.rb b/test/square/integration/client_tests/test_inventory.rb index d86c9144..f9c319c0 100644 --- a/test/square/integration/client_tests/test_inventory.rb +++ b/test/square/integration/client_tests/test_inventory.rb @@ -6,16 +6,24 @@ describe "#batch_get_changes" do it "gets inventory changes" do skip "Skipping for now." + _time_yesterday = (Time.now.utc - 1.day).iso8601 + _time_now = Time.now.utc.iso8601 + _request = Square::Types::BatchRetrieveInventoryChangesRequest.new( catalog_object_ids: ["W62UWFY35CWMYGVWK6TWJDNI"], - location_ids: ["C6W5YS5QM06F5"] + location_ids: ["C6W5YS5QM06F5"], + types: [Square::Types::InventoryChangeType::PHYSICAL_COUNT], + states: [Square::Types::InventoryState::IN_STOCK], + updated_after: _time_yesterday, + updated_before: _time_now, ) puts "request #{_request.to_h}" if verbose? response = client.inventory.batch_get_changes(request: _request.to_h) refute_nil response - + assert_equal response.class, Square::Types::BatchGetInventoryChangesResponse + refute_nil response.changes puts "response #{response.to_h}" if verbose? end end diff --git a/test/square/integration/client_tests/test_locations.rb b/test/square/integration/client_tests/test_locations.rb index 854366bb..ac9e8669 100644 --- a/test/square/integration/client_tests/test_locations.rb +++ b/test/square/integration/client_tests/test_locations.rb @@ -6,11 +6,10 @@ describe "#list" do it "should list locations" do skip "Skipping for now." - _request = {} - - puts "request #{_request.to_h}" if verbose? response = client.locations.list + refute_nil response + assert_equal response.class, Square::Types::ListLocationsResponse refute_nil response.locations assert response.locations.length > 0 diff --git a/test/square/integration/client_tests/test_merchants.rb b/test/square/integration/client_tests/test_merchants.rb index 278274b5..89fe6485 100644 --- a/test/square/integration/client_tests/test_merchants.rb +++ b/test/square/integration/client_tests/test_merchants.rb @@ -13,13 +13,12 @@ describe "#list" do it "should list merchants" do skip "Skipping for now." - _request = {} - - puts "request #{_request.to_h}" if verbose? response = client.merchants.list - refute_nil response.data - assert response.data.length > 0 + refute_nil response + assert_equal response.class, Square::Types::ListMerchantsResponse + refute_nil response.merchant + assert response.merchant.length > 0 puts "response #{response.to_h}" if verbose? end @@ -28,11 +27,13 @@ describe "#get" do it "should retrieve merchant" do skip "Skipping for now." - _request = { merchant_id: @merchant_id } - - puts "request #{_request.to_h}" if verbose? + _request = Square::Merchants::Types::GetMerchantRequest.new( + merchant_id: @merchant_id + ) - response = client.merchants.get(merchant_id: @merchant_id) + response = client.merchants.get(request: _request.to_h) + refute_nil response + assert_equal response.class, Square::Types::GetMerchantResponse refute_nil response.merchant assert_equal @merchant_id, response.merchant.id diff --git a/test/square/integration/client_tests/test_mobile.rb b/test/square/integration/client_tests/test_mobile.rb index ea942108..3dd24bf3 100644 --- a/test/square/integration/client_tests/test_mobile.rb +++ b/test/square/integration/client_tests/test_mobile.rb @@ -6,11 +6,13 @@ describe "#authorization_code" do it "should create mobile authorization code" do skip "Skipping for now." - _request = { location_id: client.locations.list.locations.first.id } - - puts "request #{_request.to_h}" if verbose? + _request = Square::Mobile::Types::AuthorizationCodeRequest.new( + location_id: client.locations.list.locations.first.id + ) response = client.mobile.authorization_code(request: _request.to_h) + refute_nil response + assert_equal response.class, Square::Types::AuthorizationCodeResponse refute_nil response.authorization_code refute_nil response.expires_at diff --git a/test/square/integration/client_tests/test_orders.rb b/test/square/integration/client_tests/test_orders.rb index 27365223..802b05bb 100644 --- a/test/square/integration/client_tests/test_orders.rb +++ b/test/square/integration/client_tests/test_orders.rb @@ -7,8 +7,7 @@ skip "Skipping for now." @location_id = client.locations.list.locations.first.id - # Create initial order for testing - order_response = client.orders.create( + _create_request = Square::Orders::Types::CreateOrderRequest.new( idempotency_key: SecureRandom.uuid, order: Square::Orders::Types::Order.new( location_id: @location_id, @@ -24,6 +23,14 @@ ] ) ) + # Create initial order for testing + order_response = client.orders.create(request: _create_request.to_h) + refute_nil order_response + assert_equal order_response.class, Square::Types::CreateOrderResponse + refute_nil order_response.order + assert_equal @location_id, order_response.order.location_id + assert_equal "New Item", order_response.order.line_items.first.name + @order_id = order_response.order.id @line_item_uid = order_response.order.line_items.first.uid end @@ -31,7 +38,7 @@ describe "#create" do it "should create order" do skip "Skipping for now." - _request = { + _request = Square::Orders::Types::CreateOrderRequest.new( idempotency_key: SecureRandom.uuid, order: Square::Orders::Types::Order.new( location_id: @location_id, @@ -46,12 +53,13 @@ ) ] ) - } + ) puts "request #{_request.to_h}" if verbose? response = client.orders.create(request: _request.to_h) refute_nil response.order + assert_equal response.class, Square::Types::CreateOrderResponse assert_equal @location_id, response.order.location_id assert_equal "New Item", response.order.line_items.first.name @@ -62,11 +70,13 @@ describe "#batch_get" do it "should batch retrieve orders" do skip "Skipping for now." - _request = { order_ids: [@order_id] } - - puts "request #{_request.to_h}" if verbose? + _request = Square::Orders::Types::BatchGetOrdersRequest.new( + order_ids: [@order_id] + ) - response = client.orders.batch_get(order_ids: [@order_id]) + response = client.orders.batch_get(request: _request.to_h) + refute_nil response + assert_equal response.class, Square::Types::BatchGetOrdersResponse refute_nil response.orders assert_equal @order_id, response.orders.first.id @@ -77,17 +87,14 @@ describe "#search" do it "should search orders" do skip "Skipping for now." - _request = { - limit: 1, - location_ids: [@location_id] - } - - puts "request #{_request.to_h}" if verbose? - - response = client.orders.search( + _request = Square::Orders::Types::SearchOrdersRequest.new( limit: 1, location_ids: [@location_id] ) + + response = client.orders.search(request: _request.to_h) + refute_nil response + assert_equal response.class, Square::Types::SearchOrdersResponse refute_nil response.orders assert response.orders.length > 0 @@ -98,7 +105,7 @@ describe "#update" do it "should update order" do skip "Skipping for now." - _request = { + _request = Square::Orders::Types::UpdateOrderRequest.new( order_id: @order_id, idempotency_key: SecureRandom.uuid, order: Square::Orders::Types::Order.new( @@ -117,9 +124,7 @@ ] ), fields_to_clear: ["line_items[#{@line_item_uid}]"] - } - - puts "request #{_request.to_h}" if verbose? + ) response = client.orders.update(request: _request.to_h) refute_nil response.order @@ -133,14 +138,12 @@ describe "#pay" do it "should pay order" do skip "Skipping for now." - _request = { + _request = Square::Orders::Types::PayOrderRequest.new( order_id: @order_id, idempotency_key: SecureRandom.uuid, order_version: 2, payment_ids: [] - } - - puts "request #{_request.to_h}" if verbose? + ) response = client.orders.pay(request: _request.to_h) refute_nil response.order @@ -153,7 +156,7 @@ describe "#calculate" do it "should calculate order" do skip "Skipping for now." - _request = { + _request = Square::Orders::Types::CalculateOrderRequest.new( order: Square::Orders::Types::Order.new( location_id: @location_id, line_items: [ @@ -167,13 +170,12 @@ ) ] ) - } - - puts "request #{_request.to_h}" if verbose? + ) response = client.orders.calculate(request: _request.to_h) refute_nil response.order refute_nil response.order.total_money + assert_equal response.class, Square::Types::CalculateOrderResponse puts "response #{response.to_h}" if verbose? end diff --git a/test/square/integration/client_tests/test_payments.rb b/test/square/integration/client_tests/test_payments.rb index 79aa7c21..3a28a2f0 100644 --- a/test/square/integration/client_tests/test_payments.rb +++ b/test/square/integration/client_tests/test_payments.rb @@ -6,32 +6,35 @@ before do skip "Skipping for now." # Create initial payment for testing - payment_response = client.payments.create( + _create_request = Square::Payments::Types::CreatePaymentRequest.new( source_id: "cnon:card-nonce-ok", idempotency_key: SecureRandom.uuid, amount_money: Square::Payments::Types::Money.new( amount: 200, currency: "USD" ), - app_fee_money: Square::Payments::Types::Money.new( - amount: 10, - currency: "USD" - ), - autocomplete: false ) + payment_response = client.payments.create(request: _create_request.to_h) + refute_nil payment_response + assert_equal payment_response.class, Square::Types::CreatePaymentResponse + refute_nil payment_response.payment + assert_equal "cnon:card-nonce-ok", payment_response.payment.source_id + assert_equal 200, payment_response.payment.amount_money.amount + assert_equal "USD", payment_response.payment.amount_money.currency + assert_equal 10, payment_response.payment.app_fee_money.amount + assert_equal "USD", payment_response.payment.app_fee_money.currency @payment_id = payment_response.payment.id end describe "#list" do it "should list payments" do skip "Skipping for now." - _request = {} - - puts "request #{_request.to_h}" if verbose? response = client.payments.list - refute_nil response.data - assert response.data.length > 0 + refute_nil response + assert_equal response.class, Square::Types::ListPaymentsResponse + refute_nil response.payments + assert response.payments.length > 0 puts "response #{response.to_h}" if verbose? end @@ -40,7 +43,7 @@ describe "#create" do it "should create payment" do skip "Skipping for now." - _request = { + _request = Square::Payments::Types::CreatePaymentRequest.new( source_id: "cnon:card-nonce-ok", idempotency_key: SecureRandom.uuid, amount_money: Square::Payments::Types::Money.new( @@ -52,11 +55,11 @@ currency: "USD" ), autocomplete: true - } - - puts "request #{_request.to_h}" if verbose? + ) response = client.payments.create(request: _request.to_h) + refute_nil response + assert_equal response.class, Square::Types::CreatePaymentResponse refute_nil response.payment assert_equal 10, response.payment.app_fee_money.amount assert_equal "USD", response.payment.app_fee_money.currency @@ -70,11 +73,13 @@ describe "#get" do it "should get payment" do skip "Skipping for now." - _request = { payment_id: @payment_id } - - puts "request #{_request.to_h}" if verbose? + _request = Square::Payments::Types::GetPaymentRequest.new( + payment_id: @payment_id + ) - response = client.payments.get(payment_id: @payment_id) + response = client.payments.get(request: _request.to_h) + refute_nil response + assert_equal response.class, Square::Types::GetPaymentResponse refute_nil response.payment assert_equal @payment_id, response.payment.id @@ -85,11 +90,13 @@ describe "#cancel" do it "should cancel payment" do skip "Skipping for now." - _request = { payment_id: @payment_id } - - puts "request #{_request.to_h}" if verbose? + _request = Square::Payments::Types::CancelPaymentRequest.new( + payment_id: @payment_id + ) - response = client.payments.cancel(payment_id: @payment_id) + response = client.payments.cancel(request: _request.to_h) + refute_nil response + assert_equal response.class, Square::Types::CancelPaymentResponse refute_nil response.payment assert_equal @payment_id, response.payment.id @@ -101,8 +108,14 @@ it "should cancel payment by idempotency key" do skip "Skipping for now." idempotency_key = SecureRandom.uuid - - # Create payment to cancel + _create_request = Square::Payments::Types::CreatePaymentRequest.new( + source_id: "cnon:card-nonce-ok", + idempotency_key: idempotency_key, + amount_money: Square::Payments::Types::Money.new( + amount: 200, + currency: "USD" + ), + ) client.payments.create( source_id: "cnon:card-nonce-ok", idempotency_key: idempotency_key, @@ -123,6 +136,7 @@ response = client.payments.cancel_by_idempotency_key(idempotency_key: idempotency_key) refute_nil response + assert_equal response.class, Square::Types::CancelPaymentByIdempotencyKeyResponse puts "response #{response.to_h}" if verbose? end @@ -132,7 +146,7 @@ it "should complete payment" do skip "Skipping for now." # Create payment to complete - create_response = client.payments.create( + _create_request = Square::Payments::Types::CreatePaymentRequest.new( source_id: "cnon:card-nonce-ok", idempotency_key: SecureRandom.uuid, amount_money: Square::Payments::Types::Money.new( @@ -145,12 +159,13 @@ ), autocomplete: false ) + create_response = client.payments.create(request: _create_request.to_h) - _request = { payment_id: create_response.payment.id } - - puts "request #{_request.to_h}" if verbose? + _request = Square::Payments::Types::CompletePaymentRequest.new( + payment_id: create_response.payment.id + ) - response = client.payments.complete(payment_id: create_response.payment.id) + response = client.payments.complete(request: _request.to_h) refute_nil response.payment assert_equal "COMPLETED", response.payment.status diff --git a/test/square/integration/client_tests/test_refunds.rb b/test/square/integration/client_tests/test_refunds.rb index 9d003d2e..837c3d87 100644 --- a/test/square/integration/client_tests/test_refunds.rb +++ b/test/square/integration/client_tests/test_refunds.rb @@ -6,30 +6,31 @@ before do skip "Skipping for now." # Create payment for testing refunds - payment_response = client.payments.create( + _create_request = Square::Payments::Types::CreatePaymentRequest.new( source_id: "cnon:card-nonce-ok", idempotency_key: SecureRandom.uuid, amount_money: Square::Payments::Types::Money.new( amount: 200, currency: "USD" - ), - app_fee_money: Square::Payments::Types::Money.new( - amount: 10, - currency: "USD" - ), - autocomplete: true + ) ) + payment_response = client.payments.create(request: _create_request.to_h) + refute_nil payment_response + assert_equal payment_response.class, Square::Types::CreatePaymentResponse + refute_nil payment_response.payment + assert_equal "cnon:card-nonce-ok", payment_response.payment.source_id + assert_equal 200, payment_response.payment.amount_money.amount + assert_equal "USD", payment_response.payment.amount_money.currency @payment_id = payment_response.payment.id # Create initial refund for testing - refund_response = client.refunds.refund_payment( - idempotency_key: SecureRandom.uuid, - payment_id: @payment_id, - amount_money: Square::Refunds::Types::Money.new( - amount: 200, - currency: "USD" - ) - ) + refund_response = client.refunds.refund_payment(request: _refund_request.to_h) + refute_nil refund_response + assert_equal refund_response.class, Square::Types::RefundPaymentResponse + refute_nil refund_response.refund + assert_equal @payment_id, refund_response.refund.payment_id + assert_equal 200, refund_response.refund.amount_money.amount + assert_equal "USD", refund_response.refund.amount_money.currency @refund_id = refund_response.refund.id end @@ -52,10 +53,10 @@ it "should refund payment" do skip "Skipping for now." # Create new payment to refund - payment_response = client.payments.create( + _create_request = Square::Payments::Types::CreatePaymentRequest.new( source_id: "cnon:card-nonce-ok", idempotency_key: SecureRandom.uuid, - amount_money: Square::Payments::Types::Money.new( + amount_money: Square::Refunds::Types::Money.new( amount: 200, currency: "USD" ), @@ -65,21 +66,31 @@ ), autocomplete: true ) - - _request = { + payment_response = client.payments.create(request: _create_request.to_h) + refute_nil payment_response + assert_equal payment_response.class, Square::Types::CreatePaymentResponse + refute_nil payment_response.payment + assert_equal "cnon:card-nonce-ok", payment_response.payment.source_id + assert_equal 200, payment_response.payment.amount_money.amount + assert_equal "USD", payment_response.payment.amount_money.currency + @payment_id = payment_response.payment.id + + _refund_request = Square::Refunds::Types::RefundPaymentRequest.new( idempotency_key: SecureRandom.uuid, payment_id: payment_response.payment.id, amount_money: Square::Refunds::Types::Money.new( amount: 200, currency: "USD" ) - } - - puts "request #{_request.to_h}" if verbose? + ) - response = client.refunds.refund_payment(request: _request.to_h) + response = client.refunds.refund_payment(request: _refund_request.to_h) + refute_nil response + assert_equal response.class, Square::Types::RefundPaymentResponse refute_nil response.refund - assert_equal payment_response.payment.id, response.refund.payment_id + assert_equal @payment_id, response.refund.payment_id + assert_equal 200, response.refund.amount_money.amount + assert_equal "USD", response.refund.amount_money.currency puts "response #{response.to_h}" if verbose? end @@ -88,12 +99,15 @@ describe "#get" do it "should get payment refund" do skip "Skipping for now." - _request = { refund_id: @refund_id } + _request = Square::Refunds::Types::GetRefundsRequest.new( + refund_id: @refund_id + ) puts "request #{_request.to_h}" if verbose? - response = client.refunds.get(refund_id: @refund_id) + response = client.refunds.get(request: _request.to_h) refute_nil response.refund + assert_equal response.class, Square::Types::GetRefundResponse assert_equal @refund_id, response.refund.id assert_equal @payment_id, response.refund.payment_id @@ -104,12 +118,14 @@ describe "#get with invalid id" do it "should handle invalid refund id" do skip "Skipping for now." - _request = { refund_id: "invalid-id" } + _request = Square::Refunds::Types::GetRefundsRequest.new( + refund_id: "invalid-id" + ) puts "request #{_request.to_h}" if verbose? assert_raises(Square::SquareError) do - client.refunds.get(refund_id: "invalid-id") + client.refunds.get(request: _request.to_h) end end end diff --git a/test/square/integration/client_tests/test_team_members.rb b/test/square/integration/client_tests/test_team_members.rb index 61a3ee6e..760e2f53 100644 --- a/test/square/integration/client_tests/test_team_members.rb +++ b/test/square/integration/client_tests/test_team_members.rb @@ -19,28 +19,31 @@ def create_test_team_member(location_ids) skip "Skipping for now." # Get default location ID locations_response = client.locations.list + refute_nil locations_response + assert_equal locations_response.class, Square::Types::ListLocationsResponse location_id = locations_response.locations.first.id refute_nil location_id # SETUP: Create 3 team members (should always be successful) - _create_request = { + _create_request = Square::TeamMembers::Types::BatchCreateTeamMembersRequest.new( team_members: { - SecureRandom.uuid => { + SecureRandom.uuid => Square::TeamMembers::Types::CreateTeamMemberRequest.new( team_member: create_test_team_member([location_id]) - }, - SecureRandom.uuid => { + ), + SecureRandom.uuid => Square::TeamMembers::Types::CreateTeamMemberRequest.new( team_member: create_test_team_member([location_id]) - }, - SecureRandom.uuid => { + ), + SecureRandom.uuid => Square::TeamMembers::Types::CreateTeamMemberRequest.new( team_member: create_test_team_member([location_id]) - } + ) } - } + ) puts "create_request #{_create_request.to_h}" if verbose? create_members_resp = client.team_members.batch_create(request: _create_request.to_h) refute_nil create_members_resp.team_members + assert_equal create_members_resp.class, Square::Types::BatchCreateTeamMembersResponse created_member_ids = [] create_members_resp.team_members.values.each do |response| @@ -55,23 +58,25 @@ def create_test_team_member(location_ids) # Update 3 team members in a bulk request, with 2 successful updates and 1 # invalid update (location ID is invalid). This should result in a 200 # response, with 2 nested success responses and 1 nested error response. - _update_request = { + _update_request = Square::TeamMembers::Types::BatchUpdateTeamMembersRequest.new( team_members: { - created_member_ids[0] => { + created_member_ids[0] => Square::TeamMembers::Types::UpdateTeamMemberRequest.new( team_member: create_test_team_member([location_id]) - }, - created_member_ids[1] => { + ), + created_member_ids[1] => Square::TeamMembers::Types::UpdateTeamMemberRequest.new( team_member: create_test_team_member([location_id]) - }, - created_member_ids[2] => { + ), + created_member_ids[2] => Square::TeamMembers::Types::UpdateTeamMemberRequest.new( team_member: create_test_team_member(["INVALID_LocationID"]) - } + ) } - } + ) puts "update_request #{_update_request.to_h}" if verbose? update_team_members_resp = client.team_members.batch_update(request: _update_request.to_h) + refute_nil update_team_members_resp + assert_equal update_team_members_resp.class, Square::Types::BatchUpdateTeamMembersResponse team_members = update_team_members_resp.team_members assert_equal 3, team_members.keys.length diff --git a/test/square/integration/client_tests/test_terminal.rb b/test/square/integration/client_tests/test_terminal.rb index a6a54992..43e60ab6 100644 --- a/test/square/integration/client_tests/test_terminal.rb +++ b/test/square/integration/client_tests/test_terminal.rb @@ -8,7 +8,7 @@ @sandbox_device_id = "da40d603-c2ea-4a65-8cfd-f42e36dab0c7" # Create terminal checkout for testing - checkout_response = client.terminal.checkouts.create( + _create_response = Square::Terminal::Checkouts::Types::CreateTerminalCheckoutRequest.new( idempotency_key: SecureRandom.uuid, checkout: Square::Terminal::Types::TerminalCheckout.new( device_options: Square::Terminal::Types::DeviceCheckoutOptions.new( @@ -20,13 +20,16 @@ ) ) ) + checkout_response = client.terminal.checkouts.create(request: _create_response.to_h) + refute_nil checkout_response + assert_equal checkout_response.class, Square::Types::CreateTerminalCheckoutResponse @checkout_id = checkout_response.checkout.id end describe "#create" do it "should create terminal checkout" do skip "Skipping for now." - _request = { + _request = Square::Terminal::Checkouts::Types::CreateTerminalCheckoutRequest.new( idempotency_key: SecureRandom.uuid, checkout: Square::Terminal::Types::TerminalCheckout.new( device_options: Square::Terminal::Types::DeviceCheckoutOptions.new( @@ -37,7 +40,7 @@ currency: "USD" ) ) - } + ) puts "request #{_request.to_h}" if verbose? @@ -53,11 +56,15 @@ describe "#search" do it "should search terminal checkouts" do skip "Skipping for now." - _request = { limit: 1 } + _request = Square::Terminal::Checkouts::Types::SearchTerminalCheckoutsRequest.new( + limit: 1 + ) puts "request #{_request.to_h}" if verbose? - response = client.terminal.checkouts.search(limit: 1) + response = client.terminal.checkouts.search(request: _request.to_h) + refute_nil response + assert_equal response.class, Square::Types::SearchTerminalCheckoutsResponse refute_nil response.checkouts assert response.checkouts.length > 0 @@ -68,11 +75,15 @@ describe "#get" do it "should get terminal checkout" do skip "Skipping for now." - _request = { checkout_id: @checkout_id } + _request = Square::Terminal::Checkouts::Types::GetTerminalCheckoutRequest.new( + checkout_id: @checkout_id + ) puts "request #{_request.to_h}" if verbose? - response = client.terminal.checkouts.get(checkout_id: @checkout_id) + response = client.terminal.checkouts.get(request: _request.to_h) + refute_nil response + assert_equal response.class, Square::Types::GetTerminalCheckoutResponse refute_nil response.checkout assert_equal @checkout_id, response.checkout.id @@ -83,11 +94,15 @@ describe "#cancel" do it "should cancel terminal checkout" do skip "Skipping for now." - _request = { checkout_id: @checkout_id } + _request = Square::Terminal::Checkouts::Types::CancelTerminalCheckoutRequest.new( + checkout_id: @checkout_id + ) puts "request #{_request.to_h}" if verbose? - response = client.terminal.checkouts.cancel(checkout_id: @checkout_id) + response = client.terminal.checkouts.cancel(request: _request.to_h) + refute_nil response + assert_equal response.class, Square::Types::CancelTerminalCheckoutResponse refute_nil response.checkout assert_equal "CANCELED", response.checkout.status