diff --git a/web/app/controllers/products_controller.rb b/web/app/controllers/products_controller.rb index ea03630..47f6287 100644 --- a/web/app/controllers/products_controller.rb +++ b/web/app/controllers/products_controller.rb @@ -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 diff --git a/web/app/services/application_service.rb b/web/app/services/application_service.rb index 79ed695..1e34e5d 100644 --- a/web/app/services/application_service.rb +++ b/web/app/services/application_service.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ApplicationService def self.call(*args, **kwargs, &block) new(*args, **kwargs, &block).call diff --git a/web/app/services/product_creator.rb b/web/app/services/product_creator.rb index 86bee86..cb7841e 100644 --- a/web/app/services/product_creator.rb +++ b/web/app/services/product_creator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class ProductCreator < ApplicationService attr_reader :count @@ -12,6 +14,7 @@ class ProductCreator < ApplicationService QUERY def initialize(count:, session: ShopifyAPI::Context.active_session) + super() @count = count @session = session end @@ -19,14 +22,14 @@ def initialize(count:, session: ShopifyAPI::Context.active_session) 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 diff --git a/web/test/controllers/products_controller_test.rb b/web/test/controllers/products_controller_test.rb index 8b3d6f1..295e890 100644 --- a/web/test/controllers/products_controller_test.rb +++ b/web/test/controllers/products_controller_test.rb @@ -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({})) @@ -43,15 +43,15 @@ 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", @@ -59,7 +59,7 @@ class ProductsControllerTestTest < ActionDispatch::IntegrationTest 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