Skip to content

Commit

Permalink
Update CLI env variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
paulomarg committed May 18, 2023
1 parent 9e3008d commit eb72357
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Note: For changes to the API, see https://shopify.dev/changelog?filter=api

## Unreleased

- [#1161](https://github.com/Shopify/shopify-api-ruby/pull/1161) [Patch] Add support for new CLI env variables.

## 13.0.0

- [#1140](https://github.com/Shopify/shopify-api-ruby/pull/1140) ⚠️ [Breaking] Reformat Http error messages to be JSON parsable.
Expand Down
2 changes: 1 addition & 1 deletion lib/shopify_api/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def setup(
log_level: :info,
logger: ::Logger.new($stdout),
host_name: nil,
host: ENV["HOST"] || "https://#{host_name}",
host: ENV["SHOPIFY_APP_URL"] || ENV["HOST"] || "https://#{host_name}",
private_shop: nil,
user_agent_prefix: nil,
old_api_secret_key: nil
Expand Down
35 changes: 30 additions & 5 deletions test/context_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module ShopifyAPITest
class ContextTest < Minitest::Test
def setup
@reader, writer = IO.pipe
ENV["HOST"] = "http://localhost:3000"
ENV["SHOPIFY_APP_URL"] = "http://localhost:3000"

ShopifyAPI::Context.setup(
api_key: "key",
Expand Down Expand Up @@ -107,10 +107,10 @@ def test_unsupported_api_version
end
end

def test_with_host_name_and_no_host_env
def test_with_host_name_and_no_env_var
clear_context
old_host = ENV["HOST"]
ENV["HOST"] = nil
old_host = ENV["SHOPIFY_APP_URL"]
ENV["SHOPIFY_APP_URL"] = nil

ShopifyAPI::Context.setup(
api_key: "key",
Expand All @@ -128,7 +128,32 @@ def test_with_host_name_and_no_host_env
assert_equal("https", ShopifyAPI::Context.host_scheme)
assert_equal("https://tunnel-o-security.com", ShopifyAPI::Context.host)
assert_equal("tunnel-o-security.com", ShopifyAPI::Context.host_name)
ENV["HOST"] = old_host
ensure
ENV["SHOPIFY_APP_URL"] = old_host
end

def test_with_host_env_var
clear_context
ENV["HOST"] = "http://localhost:3000"

ShopifyAPI::Context.setup(
api_key: "key",
api_secret_key: "secret",
api_version: "unstable",
host_name: "tunnel-o-security.com",
scope: ["scope1", "scope2"],
is_private: true,
is_embedded: true,
private_shop: "privateshop.myshopify.com",
user_agent_prefix: "user_agent_prefix1",
old_api_secret_key: "old_secret",
log_level: :off,
)
assert_equal("http", ShopifyAPI::Context.host_scheme)
assert_equal("http://localhost:3000", ShopifyAPI::Context.host)
assert_equal("localhost", ShopifyAPI::Context.host_name)
ensure
ENV["HOST"] = nil
end

def test_send_a_warning_if_log_level_is_invalid
Expand Down

0 comments on commit eb72357

Please sign in to comment.