Skip to content

Commit

Permalink
Fixes invalid typing of ShopifyAPI::DiscountCode#errors
Browse files Browse the repository at this point in the history
  • Loading branch information
garethson committed Aug 30, 2023
1 parent dc94720 commit aacd951
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

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 @@ -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))
Expand All @@ -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)) }
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 @@ -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))
Expand All @@ -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)) }
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 @@ -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))
Expand All @@ -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)) }
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 @@ -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))
Expand All @@ -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)) }
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 @@ -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))
Expand All @@ -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)) }
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 @@ -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))
Expand All @@ -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)) }
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
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

0 comments on commit aacd951

Please sign in to comment.