Skip to content

Commit

Permalink
Fixing rubocop issues
Browse files Browse the repository at this point in the history
  • Loading branch information
paulomarg committed Jul 7, 2022
1 parent 468fd8c commit 33322d9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
13 changes: 7 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Release history

1.0.1 (June 20, 2022)
----------
## Unreleased

* (Allow Ngrok v3 URLs)[https://github.com/Shopify/shopify-app-template-ruby/pull/18]
- ⚠️ [Breaking] Use offline access tokens to interact with the Admin API, remove GraphQL proxy since it doesn't work with offline tokens. ([#24](https://github.com/Shopify/shopify-app-template-ruby/pull/24))

## 1.0.1 (June 20, 2022)

1.0.0 (June 20, 2022)
----------
- (Allow Ngrok v3 URLs)[https://github.com/Shopify/shopify-app-template-ruby/pull/18]

* New Shopify App Template for Ruby/Rails, with React frontend, for use with CLI 3
## 1.0.0 (June 20, 2022)

- New Shopify App Template for Ruby/Rails, with React frontend, for use with CLI 3
2 changes: 1 addition & 1 deletion web/app/controllers/products_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ def create

logger.info("Failed to create products: #{error}")
ensure
render(json: {success: success, error: error}, status: status_code)
render(json: { success: success, error: error }, status: status_code)
end
end
2 changes: 2 additions & 0 deletions web/app/services/application_service.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ApplicationService
def self.call(*args, **kwargs, &block)
new(*args, **kwargs, &block).call
Expand Down
7 changes: 5 additions & 2 deletions web/app/services/product_creator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ProductCreator < ApplicationService
attr_reader :count

Expand All @@ -12,21 +14,22 @@ class ProductCreator < ApplicationService
QUERY

def initialize(count:, session: ShopifyAPI::Context.active_session)
super()
@count = count
@session = session
end

def call
client = ShopifyAPI::Clients::Graphql::Admin.new(session: @session)

for i in 1..count
(1..count).each do |_i|
client.query(
query: CREATE_PRODUCTS_MUTATION,
variables: {
input: {
title: random_title,
variants: [{ price: random_price }],
}
},
}
)
end
Expand Down
10 changes: 5 additions & 5 deletions web/test/controllers/products_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ProductsControllerTestTest < ActionDispatch::IntegrationTest

test "handles creating products" do
token = JWT.encode(JWT_PAYLOAD, ShopifyAPI::Context.api_secret_key, "HS256")
stub = stub_request(:post, "https://regular-shop.myshopify.com/admin/api/2022-04/graphql.json")
stub_request(:post, "https://regular-shop.myshopify.com/admin/api/2022-04/graphql.json")
.with(headers: { "X-Shopify-Access-Token" => "access-token" })
.to_return(status: 200, body: JSON.dump({}))

Expand All @@ -43,23 +43,23 @@ class ProductsControllerTestTest < ActionDispatch::IntegrationTest
headers: { "HTTP_AUTHORIZATION": "Bearer #{token}" }

assert_response :success
assert_equal({"success" => true, "error" => nil}, JSON.parse(@response.body))
assert_equal({ "success" => true, "error" => nil }, JSON.parse(@response.body))
end
end

test "handles product creation errors" do
token = JWT.encode(JWT_PAYLOAD, ShopifyAPI::Context.api_secret_key, "HS256")
stub = stub_request(:post, "https://regular-shop.myshopify.com/admin/api/2022-04/graphql.json")
stub_request(:post, "https://regular-shop.myshopify.com/admin/api/2022-04/graphql.json")
.with(headers: { "X-Shopify-Access-Token" => "access-token" })
.to_return(status: 400, body: JSON.dump({errors: "Something went wrong"}))
.to_return(status: 400, body: JSON.dump({ errors: "Something went wrong" }))

ShopifyAPI::Utils::SessionUtils.stub(:load_current_session, SESSION) do
get "/api/products/create",
xhr: true,
headers: { "HTTP_AUTHORIZATION": "Bearer #{token}" }

assert_response :bad_request
assert_equal({"success" => false, "error" => "Something went wrong"}, JSON.parse(@response.body))
assert_equal({ "success" => false, "error" => "Something went wrong" }, JSON.parse(@response.body))
end
end

Expand Down

0 comments on commit 33322d9

Please sign in to comment.