From eb723574d390c7daef73a41c667e21ad3c530971 Mon Sep 17 00:00:00 2001 From: Paulo Margarido <64600052+paulomarg@users.noreply.github.com> Date: Thu, 18 May 2023 11:21:53 -0400 Subject: [PATCH] Update CLI env variable names --- CHANGELOG.md | 2 ++ lib/shopify_api/context.rb | 2 +- test/context_test.rb | 35 ++++++++++++++++++++++++++++++----- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e9a82f1e..280a7d613 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/lib/shopify_api/context.rb b/lib/shopify_api/context.rb index 020c13623..fccf450eb 100644 --- a/lib/shopify_api/context.rb +++ b/lib/shopify_api/context.rb @@ -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 diff --git a/test/context_test.rb b/test/context_test.rb index 19d503422..6e0a6c9dc 100644 --- a/test/context_test.rb +++ b/test/context_test.rb @@ -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", @@ -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", @@ -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