diff --git a/test/rest/2022_10/customer_address_test.rb b/test/rest/2022_10/customer_address_test.rb index 43eac9318..ee87b0103 100644 --- a/test/rest/2022_10/customer_address_test.rb +++ b/test/rest/2022_10/customer_address_test.rb @@ -46,20 +46,6 @@ def test_1() ) assert_requested(:get, "https://test-shop.myshopify.io/admin/api/2022-10/customers/207119551/addresses.json?limit=1") - - response = response.first if response.respond_to?(:first) - - # Assert attributes are correctly typed preventing Sorbet errors downstream - if response.respond_to?(:original_state) - response&.original_state&.each do |key, value| - begin - response.send(key) - rescue TypeError => error - fail TypeError.new("#{self.class}##{key} is mistyped: #{error.message}") - end - response.send(key) - end - end end sig do @@ -78,20 +64,6 @@ def test_2() ) assert_requested(:get, "https://test-shop.myshopify.io/admin/api/2022-10/customers/207119551/addresses.json") - - response = response.first if response.respond_to?(:first) - - # Assert attributes are correctly typed preventing Sorbet errors downstream - if response.respond_to?(:original_state) - response&.original_state&.each do |key, value| - begin - response.send(key) - rescue TypeError => error - fail TypeError.new("#{self.class}##{key} is mistyped: #{error.message}") - end - response.send(key) - end - end end sig do @@ -200,7 +172,7 @@ def test_5() void end def test_6() - stub_request(:delete, "https://test-shop.myshopify.io/admin/api/2022-10/customers/207119551/addresses/1053317289.json") + stub_request(:delete, "https://test-shop.myshopify.io/admin/api/2022-10/customers/207119551/addresses/1053317286.json") .with( headers: {"X-Shopify-Access-Token"=>"this_is_a_test_token", "Accept"=>"application/json"}, body: {} @@ -209,10 +181,10 @@ def test_6() response = ShopifyAPI::CustomerAddress.delete( customer_id: 207119551, - id: 1053317289, + id: 1053317286, ) - assert_requested(:delete, "https://test-shop.myshopify.io/admin/api/2022-10/customers/207119551/addresses/1053317289.json") + assert_requested(:delete, "https://test-shop.myshopify.io/admin/api/2022-10/customers/207119551/addresses/1053317286.json") response = response.first if response.respond_to?(:first) @@ -233,12 +205,45 @@ def test_6() void end def test_7() + stub_request(:delete, "https://test-shop.myshopify.io/admin/api/2022-10/customers/207119551/addresses/207119551.json") + .with( + headers: {"X-Shopify-Access-Token"=>"this_is_a_test_token", "Accept"=>"application/json"}, + body: {} + ) + .to_return(status: 200, body: JSON.generate({"errors" => {"base" => ["Cannot delete the customer\u2019s default address"]}}), headers: {}) + + response = ShopifyAPI::CustomerAddress.delete( + customer_id: 207119551, + id: 207119551, + ) + + assert_requested(:delete, "https://test-shop.myshopify.io/admin/api/2022-10/customers/207119551/addresses/207119551.json") + + response = response.first if response.respond_to?(:first) + + # Assert attributes are correctly typed preventing Sorbet errors downstream + if response.respond_to?(:original_state) + response&.original_state&.each do |key, value| + begin + response.send(key) + rescue TypeError => error + fail TypeError.new("#{self.class}##{key} is mistyped: #{error.message}") + end + response.send(key) + end + end + end + + sig do + void + end + def test_8() stub_request(:post, "https://test-shop.myshopify.io/admin/api/2022-10/customers/207119551/addresses.json") .with( headers: {"X-Shopify-Access-Token"=>"this_is_a_test_token", "Accept"=>"application/json", "Content-Type"=>"application/json"}, body: { "address" => hash_including({"address1" => "1 Rue des Carrieres", "address2" => "Suite 1234", "city" => "Montreal", "company" => "Fancy Co.", "first_name" => "Samuel", "last_name" => "de Champlain", "phone" => "819-555-5555", "province" => "Quebec", "country" => "Canada", "zip" => "G1R 4P5", "name" => "Samuel de Champlain", "province_code" => "QC", "country_code" => "CA", "country_name" => "Canada"}) } ) - .to_return(status: 200, body: JSON.generate({"customer_address" => {"id" => 1053317288, "customer_id" => 207119551, "first_name" => "Samuel", "last_name" => "de Champlain", "company" => "Fancy Co.", "address1" => "1 Rue des Carrieres", "address2" => "Suite 1234", "city" => "Montreal", "province" => "Quebec", "country" => "Canada", "zip" => "G1R 4P5", "phone" => "819-555-5555", "name" => "Samuel de Champlain", "province_code" => "QC", "country_code" => "CA", "country_name" => "Canada", "default" => false}}), headers: {}) + .to_return(status: 200, body: JSON.generate({"customer_address" => {"id" => 1053317287, "customer_id" => 207119551, "first_name" => "Samuel", "last_name" => "de Champlain", "company" => "Fancy Co.", "address1" => "1 Rue des Carrieres", "address2" => "Suite 1234", "city" => "Montreal", "province" => "Quebec", "country" => "Canada", "zip" => "G1R 4P5", "phone" => "819-555-5555", "name" => "Samuel de Champlain", "province_code" => "QC", "country_code" => "CA", "country_name" => "Canada", "default" => false}}), headers: {}) response = customer_address = ShopifyAPI::CustomerAddress.new customer_address.customer_id = 207119551 @@ -278,8 +283,8 @@ def test_7() sig do void end - def test_8() - stub_request(:put, "https://test-shop.myshopify.io/admin/api/2022-10/customers/207119551/addresses/set.json?address_ids%5B%5D=1053317287&operation=destroy") + def test_9() + stub_request(:put, "https://test-shop.myshopify.io/admin/api/2022-10/customers/207119551/addresses/set.json?address_ids%5B%5D=1053317288&operation=destroy") .with( headers: {"X-Shopify-Access-Token"=>"this_is_a_test_token", "Accept"=>"application/json", "Content-Type"=>"application/json"}, body: {} @@ -289,11 +294,11 @@ def test_8() response = customer_address = ShopifyAPI::CustomerAddress.new customer_address.customer_id = 207119551 customer_address.set( - address_ids: ["1053317287"], + address_ids: ["1053317288"], operation: "destroy", ) - assert_requested(:put, "https://test-shop.myshopify.io/admin/api/2022-10/customers/207119551/addresses/set.json?address_ids%5B%5D=1053317287&operation=destroy") + assert_requested(:put, "https://test-shop.myshopify.io/admin/api/2022-10/customers/207119551/addresses/set.json?address_ids%5B%5D=1053317288&operation=destroy") response = response.first if response.respond_to?(:first) @@ -313,20 +318,20 @@ def test_8() sig do void end - def test_9() - stub_request(:put, "https://test-shop.myshopify.io/admin/api/2022-10/customers/207119551/addresses/1053317286/default.json") + def test_10() + stub_request(:put, "https://test-shop.myshopify.io/admin/api/2022-10/customers/207119551/addresses/1053317289/default.json") .with( headers: {"X-Shopify-Access-Token"=>"this_is_a_test_token", "Accept"=>"application/json", "Content-Type"=>"application/json"}, body: {} ) - .to_return(status: 200, body: JSON.generate({"customer_address" => {"id" => 1053317286, "customer_id" => 207119551, "first_name" => "Bob", "last_name" => "Norman", "company" => nil, "address1" => "Chestnut Street 92", "address2" => "", "city" => "Louisville", "province" => "Kentucky", "country" => "United States", "zip" => "40202", "phone" => "555-625-1199", "name" => "Bob Norman", "province_code" => "KY", "country_code" => "US", "country_name" => "United States", "default" => true}}), headers: {}) + .to_return(status: 200, body: JSON.generate({"customer_address" => {"id" => 1053317289, "customer_id" => 207119551, "first_name" => "Bob", "last_name" => "Norman", "company" => nil, "address1" => "Chestnut Street 92", "address2" => "", "city" => "Louisville", "province" => "Kentucky", "country" => "United States", "zip" => "40202", "phone" => "555-625-1199", "name" => "Bob Norman", "province_code" => "KY", "country_code" => "US", "country_name" => "United States", "default" => true}}), headers: {}) response = customer_address = ShopifyAPI::CustomerAddress.new customer_address.customer_id = 207119551 - customer_address.id = 1053317286 + customer_address.id = 1053317289 customer_address.default - assert_requested(:put, "https://test-shop.myshopify.io/admin/api/2022-10/customers/207119551/addresses/1053317286/default.json") + assert_requested(:put, "https://test-shop.myshopify.io/admin/api/2022-10/customers/207119551/addresses/1053317289/default.json") response = response.first if response.respond_to?(:first) diff --git a/test/rest/2023_01/customer_address_test.rb b/test/rest/2023_01/customer_address_test.rb index d6808fe3c..b2c975f1b 100644 --- a/test/rest/2023_01/customer_address_test.rb +++ b/test/rest/2023_01/customer_address_test.rb @@ -46,20 +46,6 @@ def test_1() ) assert_requested(:get, "https://test-shop.myshopify.io/admin/api/2023-01/customers/207119551/addresses.json?limit=1") - - response = response.first if response.respond_to?(:first) - - # Assert attributes are correctly typed preventing Sorbet errors downstream - if response.respond_to?(:original_state) - response&.original_state&.each do |key, value| - begin - response.send(key) - rescue TypeError => error - fail TypeError.new("#{self.class}##{key} is mistyped: #{error.message}") - end - response.send(key) - end - end end sig do @@ -78,20 +64,6 @@ def test_2() ) assert_requested(:get, "https://test-shop.myshopify.io/admin/api/2023-01/customers/207119551/addresses.json") - - response = response.first if response.respond_to?(:first) - - # Assert attributes are correctly typed preventing Sorbet errors downstream - if response.respond_to?(:original_state) - response&.original_state&.each do |key, value| - begin - response.send(key) - rescue TypeError => error - fail TypeError.new("#{self.class}##{key} is mistyped: #{error.message}") - end - response.send(key) - end - end end sig do @@ -200,7 +172,7 @@ def test_5() void end def test_6() - stub_request(:delete, "https://test-shop.myshopify.io/admin/api/2023-01/customers/207119551/addresses/1053317289.json") + stub_request(:delete, "https://test-shop.myshopify.io/admin/api/2023-01/customers/207119551/addresses/1053317286.json") .with( headers: {"X-Shopify-Access-Token"=>"this_is_a_test_token", "Accept"=>"application/json"}, body: {} @@ -209,10 +181,10 @@ def test_6() response = ShopifyAPI::CustomerAddress.delete( customer_id: 207119551, - id: 1053317289, + id: 1053317286, ) - assert_requested(:delete, "https://test-shop.myshopify.io/admin/api/2023-01/customers/207119551/addresses/1053317289.json") + assert_requested(:delete, "https://test-shop.myshopify.io/admin/api/2023-01/customers/207119551/addresses/1053317286.json") response = response.first if response.respond_to?(:first) @@ -233,12 +205,45 @@ def test_6() void end def test_7() + stub_request(:delete, "https://test-shop.myshopify.io/admin/api/2023-01/customers/207119551/addresses/207119551.json") + .with( + headers: {"X-Shopify-Access-Token"=>"this_is_a_test_token", "Accept"=>"application/json"}, + body: {} + ) + .to_return(status: 200, body: JSON.generate({"errors" => {"base" => ["Cannot delete the customer\u2019s default address"]}}), headers: {}) + + response = ShopifyAPI::CustomerAddress.delete( + customer_id: 207119551, + id: 207119551, + ) + + assert_requested(:delete, "https://test-shop.myshopify.io/admin/api/2023-01/customers/207119551/addresses/207119551.json") + + response = response.first if response.respond_to?(:first) + + # Assert attributes are correctly typed preventing Sorbet errors downstream + if response.respond_to?(:original_state) + response&.original_state&.each do |key, value| + begin + response.send(key) + rescue TypeError => error + fail TypeError.new("#{self.class}##{key} is mistyped: #{error.message}") + end + response.send(key) + end + end + end + + sig do + void + end + def test_8() stub_request(:post, "https://test-shop.myshopify.io/admin/api/2023-01/customers/207119551/addresses.json") .with( headers: {"X-Shopify-Access-Token"=>"this_is_a_test_token", "Accept"=>"application/json", "Content-Type"=>"application/json"}, body: { "address" => hash_including({"address1" => "1 Rue des Carrieres", "address2" => "Suite 1234", "city" => "Montreal", "company" => "Fancy Co.", "first_name" => "Samuel", "last_name" => "de Champlain", "phone" => "819-555-5555", "province" => "Quebec", "country" => "Canada", "zip" => "G1R 4P5", "name" => "Samuel de Champlain", "province_code" => "QC", "country_code" => "CA", "country_name" => "Canada"}) } ) - .to_return(status: 200, body: JSON.generate({"customer_address" => {"id" => 1053317288, "customer_id" => 207119551, "first_name" => "Samuel", "last_name" => "de Champlain", "company" => "Fancy Co.", "address1" => "1 Rue des Carrieres", "address2" => "Suite 1234", "city" => "Montreal", "province" => "Quebec", "country" => "Canada", "zip" => "G1R 4P5", "phone" => "819-555-5555", "name" => "Samuel de Champlain", "province_code" => "QC", "country_code" => "CA", "country_name" => "Canada", "default" => false}}), headers: {}) + .to_return(status: 200, body: JSON.generate({"customer_address" => {"id" => 1053317287, "customer_id" => 207119551, "first_name" => "Samuel", "last_name" => "de Champlain", "company" => "Fancy Co.", "address1" => "1 Rue des Carrieres", "address2" => "Suite 1234", "city" => "Montreal", "province" => "Quebec", "country" => "Canada", "zip" => "G1R 4P5", "phone" => "819-555-5555", "name" => "Samuel de Champlain", "province_code" => "QC", "country_code" => "CA", "country_name" => "Canada", "default" => false}}), headers: {}) response = customer_address = ShopifyAPI::CustomerAddress.new customer_address.customer_id = 207119551 @@ -278,8 +283,8 @@ def test_7() sig do void end - def test_8() - stub_request(:put, "https://test-shop.myshopify.io/admin/api/2023-01/customers/207119551/addresses/set.json?address_ids%5B%5D=1053317287&operation=destroy") + def test_9() + stub_request(:put, "https://test-shop.myshopify.io/admin/api/2023-01/customers/207119551/addresses/set.json?address_ids%5B%5D=1053317288&operation=destroy") .with( headers: {"X-Shopify-Access-Token"=>"this_is_a_test_token", "Accept"=>"application/json", "Content-Type"=>"application/json"}, body: {} @@ -289,11 +294,11 @@ def test_8() response = customer_address = ShopifyAPI::CustomerAddress.new customer_address.customer_id = 207119551 customer_address.set( - address_ids: ["1053317287"], + address_ids: ["1053317288"], operation: "destroy", ) - assert_requested(:put, "https://test-shop.myshopify.io/admin/api/2023-01/customers/207119551/addresses/set.json?address_ids%5B%5D=1053317287&operation=destroy") + assert_requested(:put, "https://test-shop.myshopify.io/admin/api/2023-01/customers/207119551/addresses/set.json?address_ids%5B%5D=1053317288&operation=destroy") response = response.first if response.respond_to?(:first) @@ -313,20 +318,20 @@ def test_8() sig do void end - def test_9() - stub_request(:put, "https://test-shop.myshopify.io/admin/api/2023-01/customers/207119551/addresses/1053317286/default.json") + def test_10() + stub_request(:put, "https://test-shop.myshopify.io/admin/api/2023-01/customers/207119551/addresses/1053317289/default.json") .with( headers: {"X-Shopify-Access-Token"=>"this_is_a_test_token", "Accept"=>"application/json", "Content-Type"=>"application/json"}, body: {} ) - .to_return(status: 200, body: JSON.generate({"customer_address" => {"id" => 1053317286, "customer_id" => 207119551, "first_name" => "Bob", "last_name" => "Norman", "company" => nil, "address1" => "Chestnut Street 92", "address2" => "", "city" => "Louisville", "province" => "Kentucky", "country" => "United States", "zip" => "40202", "phone" => "555-625-1199", "name" => "Bob Norman", "province_code" => "KY", "country_code" => "US", "country_name" => "United States", "default" => true}}), headers: {}) + .to_return(status: 200, body: JSON.generate({"customer_address" => {"id" => 1053317289, "customer_id" => 207119551, "first_name" => "Bob", "last_name" => "Norman", "company" => nil, "address1" => "Chestnut Street 92", "address2" => "", "city" => "Louisville", "province" => "Kentucky", "country" => "United States", "zip" => "40202", "phone" => "555-625-1199", "name" => "Bob Norman", "province_code" => "KY", "country_code" => "US", "country_name" => "United States", "default" => true}}), headers: {}) response = customer_address = ShopifyAPI::CustomerAddress.new customer_address.customer_id = 207119551 - customer_address.id = 1053317286 + customer_address.id = 1053317289 customer_address.default - assert_requested(:put, "https://test-shop.myshopify.io/admin/api/2023-01/customers/207119551/addresses/1053317286/default.json") + assert_requested(:put, "https://test-shop.myshopify.io/admin/api/2023-01/customers/207119551/addresses/1053317289/default.json") response = response.first if response.respond_to?(:first) diff --git a/test/rest/2023_04/customer_address_test.rb b/test/rest/2023_04/customer_address_test.rb index d7b6c389a..dccf48a08 100644 --- a/test/rest/2023_04/customer_address_test.rb +++ b/test/rest/2023_04/customer_address_test.rb @@ -46,20 +46,6 @@ def test_1() ) assert_requested(:get, "https://test-shop.myshopify.io/admin/api/2023-04/customers/207119551/addresses.json?limit=1") - - response = response.first if response.respond_to?(:first) - - # Assert attributes are correctly typed preventing Sorbet errors downstream - if response.respond_to?(:original_state) - response&.original_state&.each do |key, value| - begin - response.send(key) - rescue TypeError => error - fail TypeError.new("#{self.class}##{key} is mistyped: #{error.message}") - end - response.send(key) - end - end end sig do @@ -78,20 +64,6 @@ def test_2() ) assert_requested(:get, "https://test-shop.myshopify.io/admin/api/2023-04/customers/207119551/addresses.json") - - response = response.first if response.respond_to?(:first) - - # Assert attributes are correctly typed preventing Sorbet errors downstream - if response.respond_to?(:original_state) - response&.original_state&.each do |key, value| - begin - response.send(key) - rescue TypeError => error - fail TypeError.new("#{self.class}##{key} is mistyped: #{error.message}") - end - response.send(key) - end - end end sig do @@ -200,7 +172,7 @@ def test_5() void end def test_6() - stub_request(:delete, "https://test-shop.myshopify.io/admin/api/2023-04/customers/207119551/addresses/1053317289.json") + stub_request(:delete, "https://test-shop.myshopify.io/admin/api/2023-04/customers/207119551/addresses/1053317286.json") .with( headers: {"X-Shopify-Access-Token"=>"this_is_a_test_token", "Accept"=>"application/json"}, body: {} @@ -209,10 +181,10 @@ def test_6() response = ShopifyAPI::CustomerAddress.delete( customer_id: 207119551, - id: 1053317289, + id: 1053317286, ) - assert_requested(:delete, "https://test-shop.myshopify.io/admin/api/2023-04/customers/207119551/addresses/1053317289.json") + assert_requested(:delete, "https://test-shop.myshopify.io/admin/api/2023-04/customers/207119551/addresses/1053317286.json") response = response.first if response.respond_to?(:first) @@ -233,12 +205,45 @@ def test_6() void end def test_7() + stub_request(:delete, "https://test-shop.myshopify.io/admin/api/2023-04/customers/207119551/addresses/207119551.json") + .with( + headers: {"X-Shopify-Access-Token"=>"this_is_a_test_token", "Accept"=>"application/json"}, + body: {} + ) + .to_return(status: 200, body: JSON.generate({"errors" => {"base" => ["Cannot delete the customer\u2019s default address"]}}), headers: {}) + + response = ShopifyAPI::CustomerAddress.delete( + customer_id: 207119551, + id: 207119551, + ) + + assert_requested(:delete, "https://test-shop.myshopify.io/admin/api/2023-04/customers/207119551/addresses/207119551.json") + + response = response.first if response.respond_to?(:first) + + # Assert attributes are correctly typed preventing Sorbet errors downstream + if response.respond_to?(:original_state) + response&.original_state&.each do |key, value| + begin + response.send(key) + rescue TypeError => error + fail TypeError.new("#{self.class}##{key} is mistyped: #{error.message}") + end + response.send(key) + end + end + end + + sig do + void + end + def test_8() stub_request(:post, "https://test-shop.myshopify.io/admin/api/2023-04/customers/207119551/addresses.json") .with( headers: {"X-Shopify-Access-Token"=>"this_is_a_test_token", "Accept"=>"application/json", "Content-Type"=>"application/json"}, body: { "address" => hash_including({"address1" => "1 Rue des Carrieres", "address2" => "Suite 1234", "city" => "Montreal", "company" => "Fancy Co.", "first_name" => "Samuel", "last_name" => "de Champlain", "phone" => "819-555-5555", "province" => "Quebec", "country" => "Canada", "zip" => "G1R 4P5", "name" => "Samuel de Champlain", "province_code" => "QC", "country_code" => "CA", "country_name" => "Canada"}) } ) - .to_return(status: 200, body: JSON.generate({"customer_address" => {"id" => 1053317288, "customer_id" => 207119551, "first_name" => "Samuel", "last_name" => "de Champlain", "company" => "Fancy Co.", "address1" => "1 Rue des Carrieres", "address2" => "Suite 1234", "city" => "Montreal", "province" => "Quebec", "country" => "Canada", "zip" => "G1R 4P5", "phone" => "819-555-5555", "name" => "Samuel de Champlain", "province_code" => "QC", "country_code" => "CA", "country_name" => "Canada", "default" => false}}), headers: {}) + .to_return(status: 200, body: JSON.generate({"customer_address" => {"id" => 1053317287, "customer_id" => 207119551, "first_name" => "Samuel", "last_name" => "de Champlain", "company" => "Fancy Co.", "address1" => "1 Rue des Carrieres", "address2" => "Suite 1234", "city" => "Montreal", "province" => "Quebec", "country" => "Canada", "zip" => "G1R 4P5", "phone" => "819-555-5555", "name" => "Samuel de Champlain", "province_code" => "QC", "country_code" => "CA", "country_name" => "Canada", "default" => false}}), headers: {}) response = customer_address = ShopifyAPI::CustomerAddress.new customer_address.customer_id = 207119551 @@ -278,8 +283,8 @@ def test_7() sig do void end - def test_8() - stub_request(:put, "https://test-shop.myshopify.io/admin/api/2023-04/customers/207119551/addresses/set.json?address_ids%5B%5D=1053317287&operation=destroy") + def test_9() + stub_request(:put, "https://test-shop.myshopify.io/admin/api/2023-04/customers/207119551/addresses/set.json?address_ids%5B%5D=1053317288&operation=destroy") .with( headers: {"X-Shopify-Access-Token"=>"this_is_a_test_token", "Accept"=>"application/json", "Content-Type"=>"application/json"}, body: {} @@ -289,11 +294,11 @@ def test_8() response = customer_address = ShopifyAPI::CustomerAddress.new customer_address.customer_id = 207119551 customer_address.set( - address_ids: ["1053317287"], + address_ids: ["1053317288"], operation: "destroy", ) - assert_requested(:put, "https://test-shop.myshopify.io/admin/api/2023-04/customers/207119551/addresses/set.json?address_ids%5B%5D=1053317287&operation=destroy") + assert_requested(:put, "https://test-shop.myshopify.io/admin/api/2023-04/customers/207119551/addresses/set.json?address_ids%5B%5D=1053317288&operation=destroy") response = response.first if response.respond_to?(:first) @@ -313,20 +318,20 @@ def test_8() sig do void end - def test_9() - stub_request(:put, "https://test-shop.myshopify.io/admin/api/2023-04/customers/207119551/addresses/1053317286/default.json") + def test_10() + stub_request(:put, "https://test-shop.myshopify.io/admin/api/2023-04/customers/207119551/addresses/1053317289/default.json") .with( headers: {"X-Shopify-Access-Token"=>"this_is_a_test_token", "Accept"=>"application/json", "Content-Type"=>"application/json"}, body: {} ) - .to_return(status: 200, body: JSON.generate({"customer_address" => {"id" => 1053317286, "customer_id" => 207119551, "first_name" => "Bob", "last_name" => "Norman", "company" => nil, "address1" => "Chestnut Street 92", "address2" => "", "city" => "Louisville", "province" => "Kentucky", "country" => "United States", "zip" => "40202", "phone" => "555-625-1199", "name" => "Bob Norman", "province_code" => "KY", "country_code" => "US", "country_name" => "United States", "default" => true}}), headers: {}) + .to_return(status: 200, body: JSON.generate({"customer_address" => {"id" => 1053317289, "customer_id" => 207119551, "first_name" => "Bob", "last_name" => "Norman", "company" => nil, "address1" => "Chestnut Street 92", "address2" => "", "city" => "Louisville", "province" => "Kentucky", "country" => "United States", "zip" => "40202", "phone" => "555-625-1199", "name" => "Bob Norman", "province_code" => "KY", "country_code" => "US", "country_name" => "United States", "default" => true}}), headers: {}) response = customer_address = ShopifyAPI::CustomerAddress.new customer_address.customer_id = 207119551 - customer_address.id = 1053317286 + customer_address.id = 1053317289 customer_address.default - assert_requested(:put, "https://test-shop.myshopify.io/admin/api/2023-04/customers/207119551/addresses/1053317286/default.json") + assert_requested(:put, "https://test-shop.myshopify.io/admin/api/2023-04/customers/207119551/addresses/1053317289/default.json") response = response.first if response.respond_to?(:first) diff --git a/test/rest/2023_07/customer_address_test.rb b/test/rest/2023_07/customer_address_test.rb index c2eb4c5f5..7628b6238 100644 --- a/test/rest/2023_07/customer_address_test.rb +++ b/test/rest/2023_07/customer_address_test.rb @@ -46,20 +46,6 @@ def test_1() ) assert_requested(:get, "https://test-shop.myshopify.io/admin/api/2023-07/customers/207119551/addresses.json?limit=1") - - response = response.first if response.respond_to?(:first) - - # Assert attributes are correctly typed preventing Sorbet errors downstream - if response.respond_to?(:original_state) - response&.original_state&.each do |key, value| - begin - response.send(key) - rescue TypeError => error - fail TypeError.new("#{self.class}##{key} is mistyped: #{error.message}") - end - response.send(key) - end - end end sig do @@ -78,20 +64,6 @@ def test_2() ) assert_requested(:get, "https://test-shop.myshopify.io/admin/api/2023-07/customers/207119551/addresses.json") - - response = response.first if response.respond_to?(:first) - - # Assert attributes are correctly typed preventing Sorbet errors downstream - if response.respond_to?(:original_state) - response&.original_state&.each do |key, value| - begin - response.send(key) - rescue TypeError => error - fail TypeError.new("#{self.class}##{key} is mistyped: #{error.message}") - end - response.send(key) - end - end end sig do @@ -200,7 +172,7 @@ def test_5() void end def test_6() - stub_request(:delete, "https://test-shop.myshopify.io/admin/api/2023-07/customers/207119551/addresses/1053317289.json") + stub_request(:delete, "https://test-shop.myshopify.io/admin/api/2023-07/customers/207119551/addresses/1053317286.json") .with( headers: {"X-Shopify-Access-Token"=>"this_is_a_test_token", "Accept"=>"application/json"}, body: {} @@ -209,10 +181,10 @@ def test_6() response = ShopifyAPI::CustomerAddress.delete( customer_id: 207119551, - id: 1053317289, + id: 1053317286, ) - assert_requested(:delete, "https://test-shop.myshopify.io/admin/api/2023-07/customers/207119551/addresses/1053317289.json") + assert_requested(:delete, "https://test-shop.myshopify.io/admin/api/2023-07/customers/207119551/addresses/1053317286.json") response = response.first if response.respond_to?(:first) @@ -233,12 +205,45 @@ def test_6() void end def test_7() + stub_request(:delete, "https://test-shop.myshopify.io/admin/api/2023-07/customers/207119551/addresses/207119551.json") + .with( + headers: {"X-Shopify-Access-Token"=>"this_is_a_test_token", "Accept"=>"application/json"}, + body: {} + ) + .to_return(status: 200, body: JSON.generate({"errors" => {"base" => ["Cannot delete the customer\u2019s default address"]}}), headers: {}) + + response = ShopifyAPI::CustomerAddress.delete( + customer_id: 207119551, + id: 207119551, + ) + + assert_requested(:delete, "https://test-shop.myshopify.io/admin/api/2023-07/customers/207119551/addresses/207119551.json") + + response = response.first if response.respond_to?(:first) + + # Assert attributes are correctly typed preventing Sorbet errors downstream + if response.respond_to?(:original_state) + response&.original_state&.each do |key, value| + begin + response.send(key) + rescue TypeError => error + fail TypeError.new("#{self.class}##{key} is mistyped: #{error.message}") + end + response.send(key) + end + end + end + + sig do + void + end + def test_8() stub_request(:post, "https://test-shop.myshopify.io/admin/api/2023-07/customers/207119551/addresses.json") .with( headers: {"X-Shopify-Access-Token"=>"this_is_a_test_token", "Accept"=>"application/json", "Content-Type"=>"application/json"}, body: { "address" => hash_including({"address1" => "1 Rue des Carrieres", "address2" => "Suite 1234", "city" => "Montreal", "company" => "Fancy Co.", "first_name" => "Samuel", "last_name" => "de Champlain", "phone" => "819-555-5555", "province" => "Quebec", "country" => "Canada", "zip" => "G1R 4P5", "name" => "Samuel de Champlain", "province_code" => "QC", "country_code" => "CA", "country_name" => "Canada"}) } ) - .to_return(status: 200, body: JSON.generate({"customer_address" => {"id" => 1053317288, "customer_id" => 207119551, "first_name" => "Samuel", "last_name" => "de Champlain", "company" => "Fancy Co.", "address1" => "1 Rue des Carrieres", "address2" => "Suite 1234", "city" => "Montreal", "province" => "Quebec", "country" => "Canada", "zip" => "G1R 4P5", "phone" => "819-555-5555", "name" => "Samuel de Champlain", "province_code" => "QC", "country_code" => "CA", "country_name" => "Canada", "default" => false}}), headers: {}) + .to_return(status: 200, body: JSON.generate({"customer_address" => {"id" => 1053317287, "customer_id" => 207119551, "first_name" => "Samuel", "last_name" => "de Champlain", "company" => "Fancy Co.", "address1" => "1 Rue des Carrieres", "address2" => "Suite 1234", "city" => "Montreal", "province" => "Quebec", "country" => "Canada", "zip" => "G1R 4P5", "phone" => "819-555-5555", "name" => "Samuel de Champlain", "province_code" => "QC", "country_code" => "CA", "country_name" => "Canada", "default" => false}}), headers: {}) response = customer_address = ShopifyAPI::CustomerAddress.new customer_address.customer_id = 207119551 @@ -278,8 +283,8 @@ def test_7() sig do void end - def test_8() - stub_request(:put, "https://test-shop.myshopify.io/admin/api/2023-07/customers/207119551/addresses/set.json?address_ids%5B%5D=1053317287&operation=destroy") + def test_9() + stub_request(:put, "https://test-shop.myshopify.io/admin/api/2023-07/customers/207119551/addresses/set.json?address_ids%5B%5D=1053317288&operation=destroy") .with( headers: {"X-Shopify-Access-Token"=>"this_is_a_test_token", "Accept"=>"application/json", "Content-Type"=>"application/json"}, body: {} @@ -289,11 +294,11 @@ def test_8() response = customer_address = ShopifyAPI::CustomerAddress.new customer_address.customer_id = 207119551 customer_address.set( - address_ids: ["1053317287"], + address_ids: ["1053317288"], operation: "destroy", ) - assert_requested(:put, "https://test-shop.myshopify.io/admin/api/2023-07/customers/207119551/addresses/set.json?address_ids%5B%5D=1053317287&operation=destroy") + assert_requested(:put, "https://test-shop.myshopify.io/admin/api/2023-07/customers/207119551/addresses/set.json?address_ids%5B%5D=1053317288&operation=destroy") response = response.first if response.respond_to?(:first) @@ -313,20 +318,20 @@ def test_8() sig do void end - def test_9() - stub_request(:put, "https://test-shop.myshopify.io/admin/api/2023-07/customers/207119551/addresses/1053317286/default.json") + def test_10() + stub_request(:put, "https://test-shop.myshopify.io/admin/api/2023-07/customers/207119551/addresses/1053317289/default.json") .with( headers: {"X-Shopify-Access-Token"=>"this_is_a_test_token", "Accept"=>"application/json", "Content-Type"=>"application/json"}, body: {} ) - .to_return(status: 200, body: JSON.generate({"customer_address" => {"id" => 1053317286, "customer_id" => 207119551, "first_name" => "Bob", "last_name" => "Norman", "company" => nil, "address1" => "Chestnut Street 92", "address2" => "", "city" => "Louisville", "province" => "Kentucky", "country" => "United States", "zip" => "40202", "phone" => "555-625-1199", "name" => "Bob Norman", "province_code" => "KY", "country_code" => "US", "country_name" => "United States", "default" => true}}), headers: {}) + .to_return(status: 200, body: JSON.generate({"customer_address" => {"id" => 1053317289, "customer_id" => 207119551, "first_name" => "Bob", "last_name" => "Norman", "company" => nil, "address1" => "Chestnut Street 92", "address2" => "", "city" => "Louisville", "province" => "Kentucky", "country" => "United States", "zip" => "40202", "phone" => "555-625-1199", "name" => "Bob Norman", "province_code" => "KY", "country_code" => "US", "country_name" => "United States", "default" => true}}), headers: {}) response = customer_address = ShopifyAPI::CustomerAddress.new customer_address.customer_id = 207119551 - customer_address.id = 1053317286 + customer_address.id = 1053317289 customer_address.default - assert_requested(:put, "https://test-shop.myshopify.io/admin/api/2023-07/customers/207119551/addresses/1053317286/default.json") + assert_requested(:put, "https://test-shop.myshopify.io/admin/api/2023-07/customers/207119551/addresses/1053317289/default.json") response = response.first if response.respond_to?(:first)