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

Commit 445851c

Browse files
author
Cecy Correa
authored
Merge pull request #1255 from Shopify/hotfix/argo-admin-beta-flags
fix: improved check for argo_admin_beta when running argo_serve
2 parents 8eebb5d + ce0e404 commit 445851c

File tree

7 files changed

+126
-14
lines changed

7 files changed

+126
-14
lines changed

lib/project_types/extension/features/argo_runtime.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class ArgoRuntime
1212

1313
property! :renderer, accepts: Models::NpmPackage
1414
property! :cli, accepts: Models::NpmPackage
15+
property :beta_access, accepts: Array, default: -> { [] }
1516

1617
def accepts_port?
1718
case cli
@@ -49,6 +50,26 @@ def accepts_argo_version?
4950
end
5051
end
5152

53+
def accepts_shop?
54+
return false unless beta_access.include?(:argo_admin_beta)
55+
case cli
56+
when admin?
57+
cli >= ARGO_ADMIN_CLI_0_11_0
58+
else
59+
false
60+
end
61+
end
62+
63+
def accepts_api_key?
64+
return false unless beta_access.include?(:argo_admin_beta)
65+
case cli
66+
when admin?
67+
cli >= ARGO_ADMIN_CLI_0_11_0
68+
else
69+
false
70+
end
71+
end
72+
5273
private
5374

5475
def admin?

lib/project_types/extension/features/argo_serve.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class ArgoServe
88
property! :context, accepts: ShopifyCli::Context
99
property! :port, accepts: Integer, default: 39351
1010
property :tunnel_url, accepts: String, default: ""
11+
property :beta_access, accepts: Array, default: -> { [] }
1112

1213
def call
1314
validate_env!
@@ -58,10 +59,10 @@ def npm_serve_command
5859
def validate_env!
5960
ExtensionProject.reload
6061

61-
ShopifyCli::Shopifolk.check && ShopifyCli::Feature.enabled?(:argo_admin_beta)
62-
6362
return if required_fields.none?
6463

64+
return unless beta_access.include?(:argo_admin_beta)
65+
6566
ShopifyCli::Tasks::EnsureEnv.call(context, required: required_fields)
6667
ShopifyCli::Tasks::EnsureDevStore.call(context) if required_fields.include?(:shop)
6768

lib/project_types/extension/features/argo_serve_options.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ def npm_serve_command
2525

2626
def options
2727
project = ExtensionProject.current
28+
api_key = project.env.api_key
2829

2930
@serve_options ||= [].tap do |options|
3031
options << "--port=#{port}" if argo_runtime.accepts_port?
31-
options << "--shop=#{project.env.shop}" if required_fields.include?(:shop)
32-
options << "--apiKey=#{project.env.api_key}" if required_fields.include?(:api_key)
32+
options << "--shop=#{project.env.shop}" if required_fields.include?(:shop) && argo_runtime.accepts_shop?
33+
options << "--apiKey=#{api_key}" if required_fields.include?(:api_key) && argo_runtime.accepts_api_key?
3334
options << "--argoVersion=#{renderer_package.version}" if argo_runtime.accepts_argo_version?
3435
options << "--uuid=#{project.registration_uuid}" if argo_runtime.accepts_uuid?
3536
options << "--publicUrl=#{public_url}" if argo_runtime.accepts_tunnel_url?

lib/project_types/extension/models/specification_handlers/default.rb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,14 @@ def establish_tunnel?(context)
5151
end
5252

5353
def serve(context:, port:, tunnel_url:)
54-
Features::ArgoServe.new(specification_handler: self, argo_runtime: argo_runtime(context),
55-
context: context, port: port, tunnel_url: tunnel_url).call
54+
Features::ArgoServe.new(
55+
specification_handler: self,
56+
argo_runtime: argo_runtime(context),
57+
context: context,
58+
port: port,
59+
tunnel_url: tunnel_url,
60+
beta_access: beta_access
61+
).call
5662
end
5763

5864
def renderer_package(context)
@@ -62,10 +68,19 @@ def renderer_package(context)
6268
def argo_runtime(context)
6369
@argo_runtime ||= Features::ArgoRuntime.new(
6470
renderer: renderer_package(context),
65-
cli: cli_package(context)
71+
cli: cli_package(context),
72+
beta_access: beta_access
6673
)
6774
end
6875

76+
def beta_access
77+
argo_admin_beta? ? [:argo_admin_beta] : []
78+
end
79+
80+
def argo_admin_beta?
81+
ShopifyCli::Shopifolk.check && ShopifyCli::Feature.enabled?(:argo_admin_beta)
82+
end
83+
6984
def cli_package(context)
7085
cli_package_name = specification.features.argo&.cli_package_name
7186
return unless cli_package_name

test/project_types/extension/features/argo_runtime_test.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,36 @@ def test_accepts_argo_version
6363
end
6464
end
6565

66+
def test_accepts_api_key
67+
runtimes = {
68+
checkout_runtime_0_3_8 => does_not_support_feature,
69+
checkout_runtime_0_4_0 => does_not_support_feature,
70+
admin_runtime_0_11_0 => does_not_support_feature,
71+
admin_runtime_0_11_0_with_beta_access => supports_feature,
72+
admin_runtime_0_9_3 => does_not_support_feature,
73+
admin_runtime_0_9_2 => does_not_support_feature,
74+
}
75+
76+
runtimes.each do |runtime, accepts_argo_version|
77+
assert_equal accepts_argo_version, runtime.accepts_api_key?
78+
end
79+
end
80+
81+
def test_accepts_shop
82+
runtimes = {
83+
checkout_runtime_0_3_8 => does_not_support_feature,
84+
checkout_runtime_0_4_0 => does_not_support_feature,
85+
admin_runtime_0_11_0 => does_not_support_feature,
86+
admin_runtime_0_11_0_with_beta_access => supports_feature,
87+
admin_runtime_0_9_3 => does_not_support_feature,
88+
admin_runtime_0_9_2 => does_not_support_feature,
89+
}
90+
91+
runtimes.each do |runtime, accepts_argo_version|
92+
assert_equal accepts_argo_version, runtime.accepts_shop?
93+
end
94+
end
95+
6696
private
6797

6898
def checkout_runtime_0_3_8
@@ -93,6 +123,14 @@ def admin_runtime_0_11_0
93123
)
94124
end
95125

126+
def admin_runtime_0_11_0_with_beta_access
127+
ArgoRuntime.new(
128+
cli: Models::NpmPackage.new(name: "@shopify/argo-admin-cli", version: "0.11.0"),
129+
renderer: Models::NpmPackage.new(name: "@shopify/argo-admin", version: "0.9.3"),
130+
beta_access: [:argo_admin_beta]
131+
)
132+
end
133+
96134
def admin_runtime_0_9_2
97135
ArgoRuntime.new(
98136
cli: Models::NpmPackage.new(name: "@shopify/argo-admin-cli", version: "0.9.2"),

test/project_types/extension/features/argo_serve_test.rb

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,45 @@ def setup
1212
super
1313
end
1414

15-
def test_argo_serve_defers_to_js_system
15+
def test_argo_serve_defers_to_js_system_when_shopifolk_check_is_false
1616
cli = Models::NpmPackage.new(name: "@shopify/argo-admin-cli", version: "0.11.0")
1717
renderer = Models::NpmPackage.new(name: "@shopify/argo-admin", version: "0.0.1")
1818
argo_runtime = Features::ArgoRuntime.new(cli: cli, renderer: renderer)
1919
specification_handler = ExtensionTestHelpers.test_specifications["TEST_EXTENSION"]
20-
argo_serve = Features::ArgoServe.new(context: @context, argo_runtime: argo_runtime,
21-
specification_handler: specification_handler)
20+
21+
argo_serve = Features::ArgoServe.new(
22+
context: @context,
23+
argo_runtime: argo_runtime,
24+
specification_handler: specification_handler
25+
)
2226

2327
Tasks::FindNpmPackages.expects(:exactly_one_of).returns(ShopifyCli::Result.success(renderer))
2428
argo_serve.expects(:validate_env!).once
2529
argo_serve.expects(:call_js_system).returns(true).once
2630
argo_serve.call
2731
end
32+
33+
def test_argo_serve_defers_to_js_system_for_argo_admin_beta
34+
cli = Models::NpmPackage.new(name: "@shopify/argo-admin-cli", version: "0.11.0")
35+
renderer = Models::NpmPackage.new(name: "@shopify/argo-admin", version: "0.0.1")
36+
argo_runtime = Features::ArgoRuntime.new(cli: cli, renderer: renderer)
37+
specification_handler = ExtensionTestHelpers.test_specifications["TEST_EXTENSION"]
38+
39+
ShopifyCli::Tasks::EnsureEnv.stubs(:call)
40+
ShopifyCli::Tasks::EnsureDevStore.stubs(:call)
41+
42+
argo_serve = Features::ArgoServe.new(
43+
context: @context,
44+
argo_runtime: argo_runtime,
45+
specification_handler: specification_handler,
46+
beta_access: [:argo_admin_beta]
47+
)
48+
49+
Tasks::FindNpmPackages.expects(:exactly_one_of).returns(ShopifyCli::Result.success(renderer))
50+
51+
argo_serve.expects(:call_js_system).returns(true).once
52+
argo_serve.call
53+
end
2854
end
2955
end
3056
end

test/project_types/extension/tasks/argo_serve_options_test.rb

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ def test_serve_options_include_port_if_port_supported
2121

2222
def test_serve_options_include_api_key_when_required
2323
required_fields = [:api_key]
24-
argo_runtime = setup_argo_runtime(renderer_package: argo_admin, version: "0.1.2-doesnt-matter")
24+
argo_runtime = setup_argo_runtime(
25+
renderer_package: argo_admin,
26+
version: "0.11.0",
27+
beta_access: [:argo_admin_beta]
28+
)
29+
2530
options = Features::ArgoServeOptions.new(argo_runtime: argo_runtime, context: @context,
2631
renderer_package: argo_admin, required_fields: required_fields)
2732

@@ -31,7 +36,12 @@ def test_serve_options_include_api_key_when_required
3136

3237
def test_serve_options_include_shop_when_required
3338
required_fields = [:shop]
34-
argo_runtime = setup_argo_runtime(renderer_package: argo_admin, version: "0.1.2-doesnt-matter")
39+
argo_runtime = setup_argo_runtime(
40+
renderer_package: argo_admin,
41+
version: "0.11.0",
42+
beta_access: [:argo_admin_beta]
43+
)
44+
3545
options = Features::ArgoServeOptions.new(argo_runtime: argo_runtime, context: @context,
3646
renderer_package: argo_admin, required_fields: required_fields)
3747

@@ -84,10 +94,10 @@ def argo_renderer_package(package_name:, version: "0.1.2")
8494
)
8595
end
8696

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

90-
Features::ArgoRuntime.new(renderer: renderer_package, cli: cli)
100+
Features::ArgoRuntime.new(renderer: renderer_package, cli: cli, beta_access: beta_access)
91101
end
92102
end
93103
end

0 commit comments

Comments
 (0)