From aacd9510091377cba03e87ff6beac059292a8c4e Mon Sep 17 00:00:00 2001 From: Gareth du Plooy Date: Mon, 28 Aug 2023 15:31:20 -0500 Subject: [PATCH] Fixes invalid typing of ShopifyAPI::DiscountCode#errors --- CHANGELOG.md | 1 + README.md | 8 +++---- .../rest/resources/2022_04/discount_code.rb | 3 --- .../rest/resources/2022_07/discount_code.rb | 3 --- .../rest/resources/2022_10/discount_code.rb | 3 --- .../rest/resources/2023_01/discount_code.rb | 3 --- .../rest/resources/2023_04/discount_code.rb | 3 --- .../rest/resources/2023_07/discount_code.rb | 3 --- test/rest/2023_07/discount_code_test.rb | 22 +++++++++++++++++++ 9 files changed, 26 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 48c54999d..9e6fe7abc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Note: For changes to the API, see https://shopify.dev/changelog?filter=api ## Unreleased +- [#1205](https://github.com/Shopify/shopify-api-ruby/pull/1205) Fixes invalid typing of ShopifyAPI::DiscountCode#errors. - [#1183](https://github.com/Shopify/shopify-api-ruby/pull/1189) Added string array support for fields parameter in Webhook::Registry ## 13.1.0 diff --git a/README.md b/README.md index 453001264..893009580 100644 --- a/README.md +++ b/README.md @@ -124,11 +124,9 @@ After cloning the repository, you can install the dependencies with bundler: bundle install ``` -To run the automated tests: - -```bash -bundle exec rake test -``` +There are two sets of tests + - The "library" tests which test the base functionality of the API code. These tests can be run via `bundle exec rake test` (which is an alias to `bundle exec rake test:library`). + - The "rest_wrappers" tests which test the model-specific wrappers for the Shopify API. These tests can be run via `bundle exec rake test:rest_wrappers`. We use [rubocop](https://rubocop.org) to lint/format the code. You can run it with the following command: diff --git a/lib/shopify_api/rest/resources/2022_04/discount_code.rb b/lib/shopify_api/rest/resources/2022_04/discount_code.rb index 74711042e..5a6487bbd 100644 --- a/lib/shopify_api/rest/resources/2022_04/discount_code.rb +++ b/lib/shopify_api/rest/resources/2022_04/discount_code.rb @@ -18,7 +18,6 @@ def initialize(session: ShopifyAPI::Context.active_session) @code = T.let(nil, T.nilable(String)) @created_at = T.let(nil, T.nilable(String)) - @errors = T.let(nil, T.nilable(T::Hash[T.untyped, T.untyped])) @id = T.let(nil, T.nilable(Integer)) @price_rule_id = T.let(nil, T.nilable(Integer)) @updated_at = T.let(nil, T.nilable(String)) @@ -44,8 +43,6 @@ def initialize(session: ShopifyAPI::Context.active_session) attr_reader :code sig { returns(T.nilable(String)) } attr_reader :created_at - sig { returns(T.nilable(T::Hash[T.untyped, T.untyped])) } - attr_reader :errors sig { returns(T.nilable(Integer)) } attr_reader :id sig { returns(T.nilable(Integer)) } diff --git a/lib/shopify_api/rest/resources/2022_07/discount_code.rb b/lib/shopify_api/rest/resources/2022_07/discount_code.rb index 74711042e..5a6487bbd 100644 --- a/lib/shopify_api/rest/resources/2022_07/discount_code.rb +++ b/lib/shopify_api/rest/resources/2022_07/discount_code.rb @@ -18,7 +18,6 @@ def initialize(session: ShopifyAPI::Context.active_session) @code = T.let(nil, T.nilable(String)) @created_at = T.let(nil, T.nilable(String)) - @errors = T.let(nil, T.nilable(T::Hash[T.untyped, T.untyped])) @id = T.let(nil, T.nilable(Integer)) @price_rule_id = T.let(nil, T.nilable(Integer)) @updated_at = T.let(nil, T.nilable(String)) @@ -44,8 +43,6 @@ def initialize(session: ShopifyAPI::Context.active_session) attr_reader :code sig { returns(T.nilable(String)) } attr_reader :created_at - sig { returns(T.nilable(T::Hash[T.untyped, T.untyped])) } - attr_reader :errors sig { returns(T.nilable(Integer)) } attr_reader :id sig { returns(T.nilable(Integer)) } diff --git a/lib/shopify_api/rest/resources/2022_10/discount_code.rb b/lib/shopify_api/rest/resources/2022_10/discount_code.rb index 74711042e..5a6487bbd 100644 --- a/lib/shopify_api/rest/resources/2022_10/discount_code.rb +++ b/lib/shopify_api/rest/resources/2022_10/discount_code.rb @@ -18,7 +18,6 @@ def initialize(session: ShopifyAPI::Context.active_session) @code = T.let(nil, T.nilable(String)) @created_at = T.let(nil, T.nilable(String)) - @errors = T.let(nil, T.nilable(T::Hash[T.untyped, T.untyped])) @id = T.let(nil, T.nilable(Integer)) @price_rule_id = T.let(nil, T.nilable(Integer)) @updated_at = T.let(nil, T.nilable(String)) @@ -44,8 +43,6 @@ def initialize(session: ShopifyAPI::Context.active_session) attr_reader :code sig { returns(T.nilable(String)) } attr_reader :created_at - sig { returns(T.nilable(T::Hash[T.untyped, T.untyped])) } - attr_reader :errors sig { returns(T.nilable(Integer)) } attr_reader :id sig { returns(T.nilable(Integer)) } diff --git a/lib/shopify_api/rest/resources/2023_01/discount_code.rb b/lib/shopify_api/rest/resources/2023_01/discount_code.rb index 74711042e..5a6487bbd 100644 --- a/lib/shopify_api/rest/resources/2023_01/discount_code.rb +++ b/lib/shopify_api/rest/resources/2023_01/discount_code.rb @@ -18,7 +18,6 @@ def initialize(session: ShopifyAPI::Context.active_session) @code = T.let(nil, T.nilable(String)) @created_at = T.let(nil, T.nilable(String)) - @errors = T.let(nil, T.nilable(T::Hash[T.untyped, T.untyped])) @id = T.let(nil, T.nilable(Integer)) @price_rule_id = T.let(nil, T.nilable(Integer)) @updated_at = T.let(nil, T.nilable(String)) @@ -44,8 +43,6 @@ def initialize(session: ShopifyAPI::Context.active_session) attr_reader :code sig { returns(T.nilable(String)) } attr_reader :created_at - sig { returns(T.nilable(T::Hash[T.untyped, T.untyped])) } - attr_reader :errors sig { returns(T.nilable(Integer)) } attr_reader :id sig { returns(T.nilable(Integer)) } diff --git a/lib/shopify_api/rest/resources/2023_04/discount_code.rb b/lib/shopify_api/rest/resources/2023_04/discount_code.rb index 74711042e..5a6487bbd 100644 --- a/lib/shopify_api/rest/resources/2023_04/discount_code.rb +++ b/lib/shopify_api/rest/resources/2023_04/discount_code.rb @@ -18,7 +18,6 @@ def initialize(session: ShopifyAPI::Context.active_session) @code = T.let(nil, T.nilable(String)) @created_at = T.let(nil, T.nilable(String)) - @errors = T.let(nil, T.nilable(T::Hash[T.untyped, T.untyped])) @id = T.let(nil, T.nilable(Integer)) @price_rule_id = T.let(nil, T.nilable(Integer)) @updated_at = T.let(nil, T.nilable(String)) @@ -44,8 +43,6 @@ def initialize(session: ShopifyAPI::Context.active_session) attr_reader :code sig { returns(T.nilable(String)) } attr_reader :created_at - sig { returns(T.nilable(T::Hash[T.untyped, T.untyped])) } - attr_reader :errors sig { returns(T.nilable(Integer)) } attr_reader :id sig { returns(T.nilable(Integer)) } diff --git a/lib/shopify_api/rest/resources/2023_07/discount_code.rb b/lib/shopify_api/rest/resources/2023_07/discount_code.rb index 74711042e..5a6487bbd 100644 --- a/lib/shopify_api/rest/resources/2023_07/discount_code.rb +++ b/lib/shopify_api/rest/resources/2023_07/discount_code.rb @@ -18,7 +18,6 @@ def initialize(session: ShopifyAPI::Context.active_session) @code = T.let(nil, T.nilable(String)) @created_at = T.let(nil, T.nilable(String)) - @errors = T.let(nil, T.nilable(T::Hash[T.untyped, T.untyped])) @id = T.let(nil, T.nilable(Integer)) @price_rule_id = T.let(nil, T.nilable(Integer)) @updated_at = T.let(nil, T.nilable(String)) @@ -44,8 +43,6 @@ def initialize(session: ShopifyAPI::Context.active_session) attr_reader :code sig { returns(T.nilable(String)) } attr_reader :created_at - sig { returns(T.nilable(T::Hash[T.untyped, T.untyped])) } - attr_reader :errors sig { returns(T.nilable(Integer)) } attr_reader :id sig { returns(T.nilable(Integer)) } diff --git a/test/rest/2023_07/discount_code_test.rb b/test/rest/2023_07/discount_code_test.rb index 8aec640bf..a2d499063 100644 --- a/test/rest/2023_07/discount_code_test.rb +++ b/test/rest/2023_07/discount_code_test.rb @@ -324,4 +324,26 @@ def test_9() end end + sig do + void + end + def test_11 + stub_request(:put, "https://test-shop.myshopify.io/admin/api/2023-07/price_rules/507328175/discount_codes/507328175.json") + .with( + headers: {"X-Shopify-Access-Token"=>"this_is_a_test_token", "Accept"=>"application/json", "Content-Type"=>"application/json"}, + body: { "discount_code" => hash_including({"code" => "WINTERSALE20OFF"}) } + ) + .to_return(status: 404, body: { errors: "Not Found" }.to_json, headers: {}) + + discount_code = ShopifyAPI::DiscountCode.new + discount_code.price_rule_id = 507328175 + discount_code.id = 507328175 + discount_code.code = "WINTERSALE20OFF" + begin + discount_code.save + rescue ShopifyAPI::Errors::HttpResponseError + end + assert_equal(ShopifyAPI::Rest::BaseErrors, discount_code.errors.class) + assert_equal(404, discount_code.errors.errors[0].code) + end end