Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes invalid typing of discount code errors #1205

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Note: For changes to the API, see https://shopify.dev/changelog?filter=api
## 14.0.0
- [#1274](https://github.com/Shopify/shopify-api-ruby/pull/1274) ⚠️ [Breaking] Update sorbet and rbi dependencies. Remove support for ruby 2.7. Minimum required Ruby version is 3.0
- [#1282](https://github.com/Shopify/shopify-api-ruby/pull/1282) Fixes a bug where diffing attributes to update not take into account of Array changes and required ids.
- [#1244](https://github.com/Shopify/shopify-api-ruby/pull/1205) Fixes invalid typing of ShopifyAPI::DiscountCode#errors
- [#1254](https://github.com/Shopify/shopify-api-ruby/pull/1254) Introduce token exchange API for fetching access tokens. This feature is currently unstable and cannot be used yet.
- [#1268](https://github.com/Shopify/shopify-api-ruby/pull/1268) Add [new webhook handler interface](https://github.com/Shopify/shopify-api-ruby/blob/main/docs/usage/webhooks.md#create-a-webhook-handler) to provide `webhook_id ` and `api_version` information to webhook handlers.
- [#1275](https://github.com/Shopify/shopify-api-ruby/pull/1275) Allow adding custom headers in REST Resource HTTP calls.
Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,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:

Expand Down
3 changes: 0 additions & 3 deletions lib/shopify_api/rest/resources/2022_04/discount_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def initialize(session: ShopifyAPI::Context.active_session, from_hash: nil)

@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))
Expand Down Expand Up @@ -48,8 +47,6 @@ def initialize(session: ShopifyAPI::Context.active_session, from_hash: nil)
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)) }
Expand Down
3 changes: 0 additions & 3 deletions lib/shopify_api/rest/resources/2022_07/discount_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def initialize(session: ShopifyAPI::Context.active_session, from_hash: nil)

@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))
Expand Down Expand Up @@ -48,8 +47,6 @@ def initialize(session: ShopifyAPI::Context.active_session, from_hash: nil)
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)) }
Expand Down
3 changes: 0 additions & 3 deletions lib/shopify_api/rest/resources/2022_10/discount_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def initialize(session: ShopifyAPI::Context.active_session, from_hash: nil)

@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))
Expand Down Expand Up @@ -48,8 +47,6 @@ def initialize(session: ShopifyAPI::Context.active_session, from_hash: nil)
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)) }
Expand Down
3 changes: 0 additions & 3 deletions lib/shopify_api/rest/resources/2023_01/discount_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def initialize(session: ShopifyAPI::Context.active_session, from_hash: nil)

@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))
Expand Down Expand Up @@ -48,8 +47,6 @@ def initialize(session: ShopifyAPI::Context.active_session, from_hash: nil)
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)) }
Expand Down
3 changes: 0 additions & 3 deletions lib/shopify_api/rest/resources/2023_04/discount_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def initialize(session: ShopifyAPI::Context.active_session, from_hash: nil)

@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))
Expand Down Expand Up @@ -48,8 +47,6 @@ def initialize(session: ShopifyAPI::Context.active_session, from_hash: nil)
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)) }
Expand Down
3 changes: 0 additions & 3 deletions lib/shopify_api/rest/resources/2023_07/discount_code.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def initialize(session: ShopifyAPI::Context.active_session, from_hash: nil)

@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))
Expand Down Expand Up @@ -48,8 +47,6 @@ def initialize(session: ShopifyAPI::Context.active_session, from_hash: nil)
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)) }
Expand Down
22 changes: 22 additions & 0 deletions test/rest/2023_07/discount_code_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,26 @@ def test_9()
end
end

sig do
Copy link
Contributor Author

@garethson garethson Aug 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only put this one test in the latest API version, I doubt this is where this test belongs as it's supposed to be auto-generated. Seems to me that the auto-generation of these tests are missing some error cases.

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
Loading