Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1255 from Shopify/hotfix/argo-admin-beta-flags
Browse files Browse the repository at this point in the history
fix: improved check for argo_admin_beta when running argo_serve
  • Loading branch information
Cecy Correa authored May 28, 2021
2 parents 8eebb5d + ce0e404 commit 445851c
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 14 deletions.
21 changes: 21 additions & 0 deletions lib/project_types/extension/features/argo_runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class ArgoRuntime

property! :renderer, accepts: Models::NpmPackage
property! :cli, accepts: Models::NpmPackage
property :beta_access, accepts: Array, default: -> { [] }

def accepts_port?
case cli
Expand Down Expand Up @@ -49,6 +50,26 @@ def accepts_argo_version?
end
end

def accepts_shop?
return false unless beta_access.include?(:argo_admin_beta)
case cli
when admin?
cli >= ARGO_ADMIN_CLI_0_11_0
else
false
end
end

def accepts_api_key?
return false unless beta_access.include?(:argo_admin_beta)
case cli
when admin?
cli >= ARGO_ADMIN_CLI_0_11_0
else
false
end
end

private

def admin?
Expand Down
5 changes: 3 additions & 2 deletions lib/project_types/extension/features/argo_serve.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ArgoServe
property! :context, accepts: ShopifyCli::Context
property! :port, accepts: Integer, default: 39351
property :tunnel_url, accepts: String, default: ""
property :beta_access, accepts: Array, default: -> { [] }

def call
validate_env!
Expand Down Expand Up @@ -58,10 +59,10 @@ def npm_serve_command
def validate_env!
ExtensionProject.reload

ShopifyCli::Shopifolk.check && ShopifyCli::Feature.enabled?(:argo_admin_beta)

return if required_fields.none?

return unless beta_access.include?(:argo_admin_beta)

ShopifyCli::Tasks::EnsureEnv.call(context, required: required_fields)
ShopifyCli::Tasks::EnsureDevStore.call(context) if required_fields.include?(:shop)

Expand Down
5 changes: 3 additions & 2 deletions lib/project_types/extension/features/argo_serve_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ def npm_serve_command

def options
project = ExtensionProject.current
api_key = project.env.api_key

@serve_options ||= [].tap do |options|
options << "--port=#{port}" if argo_runtime.accepts_port?
options << "--shop=#{project.env.shop}" if required_fields.include?(:shop)
options << "--apiKey=#{project.env.api_key}" if required_fields.include?(:api_key)
options << "--shop=#{project.env.shop}" if required_fields.include?(:shop) && argo_runtime.accepts_shop?
options << "--apiKey=#{api_key}" if required_fields.include?(:api_key) && argo_runtime.accepts_api_key?
options << "--argoVersion=#{renderer_package.version}" if argo_runtime.accepts_argo_version?
options << "--uuid=#{project.registration_uuid}" if argo_runtime.accepts_uuid?
options << "--publicUrl=#{public_url}" if argo_runtime.accepts_tunnel_url?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@ def establish_tunnel?(context)
end

def serve(context:, port:, tunnel_url:)
Features::ArgoServe.new(specification_handler: self, argo_runtime: argo_runtime(context),
context: context, port: port, tunnel_url: tunnel_url).call
Features::ArgoServe.new(
specification_handler: self,
argo_runtime: argo_runtime(context),
context: context,
port: port,
tunnel_url: tunnel_url,
beta_access: beta_access
).call
end

def renderer_package(context)
Expand All @@ -62,10 +68,19 @@ def renderer_package(context)
def argo_runtime(context)
@argo_runtime ||= Features::ArgoRuntime.new(
renderer: renderer_package(context),
cli: cli_package(context)
cli: cli_package(context),
beta_access: beta_access
)
end

def beta_access
argo_admin_beta? ? [:argo_admin_beta] : []
end

def argo_admin_beta?
ShopifyCli::Shopifolk.check && ShopifyCli::Feature.enabled?(:argo_admin_beta)
end

def cli_package(context)
cli_package_name = specification.features.argo&.cli_package_name
return unless cli_package_name
Expand Down
38 changes: 38 additions & 0 deletions test/project_types/extension/features/argo_runtime_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,36 @@ def test_accepts_argo_version
end
end

def test_accepts_api_key
runtimes = {
checkout_runtime_0_3_8 => does_not_support_feature,
checkout_runtime_0_4_0 => does_not_support_feature,
admin_runtime_0_11_0 => does_not_support_feature,
admin_runtime_0_11_0_with_beta_access => supports_feature,
admin_runtime_0_9_3 => does_not_support_feature,
admin_runtime_0_9_2 => does_not_support_feature,
}

runtimes.each do |runtime, accepts_argo_version|
assert_equal accepts_argo_version, runtime.accepts_api_key?
end
end

def test_accepts_shop
runtimes = {
checkout_runtime_0_3_8 => does_not_support_feature,
checkout_runtime_0_4_0 => does_not_support_feature,
admin_runtime_0_11_0 => does_not_support_feature,
admin_runtime_0_11_0_with_beta_access => supports_feature,
admin_runtime_0_9_3 => does_not_support_feature,
admin_runtime_0_9_2 => does_not_support_feature,
}

runtimes.each do |runtime, accepts_argo_version|
assert_equal accepts_argo_version, runtime.accepts_shop?
end
end

private

def checkout_runtime_0_3_8
Expand Down Expand Up @@ -93,6 +123,14 @@ def admin_runtime_0_11_0
)
end

def admin_runtime_0_11_0_with_beta_access
ArgoRuntime.new(
cli: Models::NpmPackage.new(name: "@shopify/argo-admin-cli", version: "0.11.0"),
renderer: Models::NpmPackage.new(name: "@shopify/argo-admin", version: "0.9.3"),
beta_access: [:argo_admin_beta]
)
end

def admin_runtime_0_9_2
ArgoRuntime.new(
cli: Models::NpmPackage.new(name: "@shopify/argo-admin-cli", version: "0.9.2"),
Expand Down
32 changes: 29 additions & 3 deletions test/project_types/extension/features/argo_serve_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,45 @@ def setup
super
end

def test_argo_serve_defers_to_js_system
def test_argo_serve_defers_to_js_system_when_shopifolk_check_is_false
cli = Models::NpmPackage.new(name: "@shopify/argo-admin-cli", version: "0.11.0")
renderer = Models::NpmPackage.new(name: "@shopify/argo-admin", version: "0.0.1")
argo_runtime = Features::ArgoRuntime.new(cli: cli, renderer: renderer)
specification_handler = ExtensionTestHelpers.test_specifications["TEST_EXTENSION"]
argo_serve = Features::ArgoServe.new(context: @context, argo_runtime: argo_runtime,
specification_handler: specification_handler)

argo_serve = Features::ArgoServe.new(
context: @context,
argo_runtime: argo_runtime,
specification_handler: specification_handler
)

Tasks::FindNpmPackages.expects(:exactly_one_of).returns(ShopifyCli::Result.success(renderer))
argo_serve.expects(:validate_env!).once
argo_serve.expects(:call_js_system).returns(true).once
argo_serve.call
end

def test_argo_serve_defers_to_js_system_for_argo_admin_beta
cli = Models::NpmPackage.new(name: "@shopify/argo-admin-cli", version: "0.11.0")
renderer = Models::NpmPackage.new(name: "@shopify/argo-admin", version: "0.0.1")
argo_runtime = Features::ArgoRuntime.new(cli: cli, renderer: renderer)
specification_handler = ExtensionTestHelpers.test_specifications["TEST_EXTENSION"]

ShopifyCli::Tasks::EnsureEnv.stubs(:call)
ShopifyCli::Tasks::EnsureDevStore.stubs(:call)

argo_serve = Features::ArgoServe.new(
context: @context,
argo_runtime: argo_runtime,
specification_handler: specification_handler,
beta_access: [:argo_admin_beta]
)

Tasks::FindNpmPackages.expects(:exactly_one_of).returns(ShopifyCli::Result.success(renderer))

argo_serve.expects(:call_js_system).returns(true).once
argo_serve.call
end
end
end
end
18 changes: 14 additions & 4 deletions test/project_types/extension/tasks/argo_serve_options_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ def test_serve_options_include_port_if_port_supported

def test_serve_options_include_api_key_when_required
required_fields = [:api_key]
argo_runtime = setup_argo_runtime(renderer_package: argo_admin, version: "0.1.2-doesnt-matter")
argo_runtime = setup_argo_runtime(
renderer_package: argo_admin,
version: "0.11.0",
beta_access: [:argo_admin_beta]
)

options = Features::ArgoServeOptions.new(argo_runtime: argo_runtime, context: @context,
renderer_package: argo_admin, required_fields: required_fields)

Expand All @@ -31,7 +36,12 @@ def test_serve_options_include_api_key_when_required

def test_serve_options_include_shop_when_required
required_fields = [:shop]
argo_runtime = setup_argo_runtime(renderer_package: argo_admin, version: "0.1.2-doesnt-matter")
argo_runtime = setup_argo_runtime(
renderer_package: argo_admin,
version: "0.11.0",
beta_access: [:argo_admin_beta]
)

options = Features::ArgoServeOptions.new(argo_runtime: argo_runtime, context: @context,
renderer_package: argo_admin, required_fields: required_fields)

Expand Down Expand Up @@ -84,10 +94,10 @@ def argo_renderer_package(package_name:, version: "0.1.2")
)
end

def setup_argo_runtime(renderer_package:, version:, cli_package_name: "@shopify/argo-admin-cli")
def setup_argo_runtime(renderer_package:, version:, cli_package_name: "@shopify/argo-admin-cli", beta_access: [])
cli = Models::NpmPackage.new(name: cli_package_name, version: version)

Features::ArgoRuntime.new(renderer: renderer_package, cli: cli)
Features::ArgoRuntime.new(renderer: renderer_package, cli: cli, beta_access: beta_access)
end
end
end
Expand Down

0 comments on commit 445851c

Please sign in to comment.