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

Commit ce0e404

Browse files
author
Cecy Correa
committed
consolidate beta_checks on SpecificationHandler::Default
1 parent 3bb3a62 commit ce0e404

File tree

7 files changed

+106
-48
lines changed

7 files changed

+106
-48
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: 2 additions & 5 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!
@@ -55,16 +56,12 @@ def npm_serve_command
5556
serve_options.npm_serve_command
5657
end
5758

58-
def argo_admin_beta?
59-
ShopifyCli::Shopifolk.check && ShopifyCli::Feature.enabled?(:argo_admin_beta)
60-
end
61-
6259
def validate_env!
6360
ExtensionProject.reload
6461

6562
return if required_fields.none?
6663

67-
return unless argo_admin_beta?
64+
return unless beta_access.include?(:argo_admin_beta)
6865

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

lib/project_types/extension/features/argo_serve_options.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,16 @@ def npm_serve_command
2121
NPM_SERVE_COMMAND + ["--"] + options
2222
end
2323

24-
def argo_admin_beta?
25-
ShopifyCli::Shopifolk.check && ShopifyCli::Feature.enabled?(:argo_admin_beta)
26-
end
27-
2824
private
2925

3026
def options
3127
project = ExtensionProject.current
28+
api_key = project.env.api_key
3229

3330
@serve_options ||= [].tap do |options|
3431
options << "--port=#{port}" if argo_runtime.accepts_port?
35-
options << "--shop=#{project.env.shop}" if required_fields.include?(:shop) && argo_admin_beta?
36-
options << "--apiKey=#{project.env.api_key}" if required_fields.include?(:api_key) && argo_admin_beta?
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?
3734
options << "--argoVersion=#{renderer_package.version}" if argo_runtime.accepts_argo_version?
3835
options << "--uuid=#{project.registration_uuid}" if argo_runtime.accepts_uuid?
3936
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: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ def test_argo_serve_defers_to_js_system_when_shopifolk_check_is_false
1818
argo_runtime = Features::ArgoRuntime.new(cli: cli, renderer: renderer)
1919
specification_handler = ExtensionTestHelpers.test_specifications["TEST_EXTENSION"]
2020

21-
ShopifyCli::Shopifolk.stubs(:check).returns(false)
22-
23-
argo_serve = Features::ArgoServe.new(context: @context, argo_runtime: argo_runtime,
24-
specification_handler: specification_handler)
21+
argo_serve = Features::ArgoServe.new(
22+
context: @context,
23+
argo_runtime: argo_runtime,
24+
specification_handler: specification_handler
25+
)
2526

2627
Tasks::FindNpmPackages.expects(:exactly_one_of).returns(ShopifyCli::Result.success(renderer))
2728
argo_serve.expects(:validate_env!).once
@@ -33,30 +34,17 @@ def test_argo_serve_defers_to_js_system_for_argo_admin_beta
3334
cli = Models::NpmPackage.new(name: "@shopify/argo-admin-cli", version: "0.11.0")
3435
renderer = Models::NpmPackage.new(name: "@shopify/argo-admin", version: "0.0.1")
3536
argo_runtime = Features::ArgoRuntime.new(cli: cli, renderer: renderer)
37+
specification_handler = ExtensionTestHelpers.test_specifications["TEST_EXTENSION"]
3638

37-
specification = Extension::Models::Specification.new(
38-
{
39-
identifier: "test",
40-
features: {
41-
argo: {
42-
surface: "admin",
43-
git_template: "https://github.com/Shopify/argo-admin.git",
44-
renderer_package_name: "@shopify/argo-admin",
45-
required_fields: [:shop, :api_key],
46-
required_shop_beta_flags: [:argo_admin_beta],
47-
},
48-
},
49-
}
50-
)
51-
specification_handler = Extension::Models::SpecificationHandlers::Default.new(specification)
52-
53-
ShopifyCli::Shopifolk.stubs(:check).returns(true)
54-
ShopifyCli::Feature.stubs(:enabled?).with(:argo_admin_beta).returns(true)
5539
ShopifyCli::Tasks::EnsureEnv.stubs(:call)
5640
ShopifyCli::Tasks::EnsureDevStore.stubs(:call)
5741

58-
argo_serve = Features::ArgoServe.new(context: @context, argo_runtime: argo_runtime,
59-
specification_handler: specification_handler)
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+
)
6048

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

test/project_types/extension/tasks/argo_serve_options_test.rb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ 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")
25-
26-
ShopifyCli::Shopifolk.expects(:check).returns(true)
27-
ShopifyCli::Feature.expects(:enabled?).with(:argo_admin_beta).returns(true)
24+
argo_runtime = setup_argo_runtime(
25+
renderer_package: argo_admin,
26+
version: "0.11.0",
27+
beta_access: [:argo_admin_beta]
28+
)
2829

2930
options = Features::ArgoServeOptions.new(argo_runtime: argo_runtime, context: @context,
3031
renderer_package: argo_admin, required_fields: required_fields)
@@ -35,10 +36,11 @@ def test_serve_options_include_api_key_when_required
3536

3637
def test_serve_options_include_shop_when_required
3738
required_fields = [:shop]
38-
argo_runtime = setup_argo_runtime(renderer_package: argo_admin, version: "0.1.2-doesnt-matter")
39-
40-
ShopifyCli::Shopifolk.expects(:check).returns(true)
41-
ShopifyCli::Feature.expects(:enabled?).with(:argo_admin_beta).returns(true)
39+
argo_runtime = setup_argo_runtime(
40+
renderer_package: argo_admin,
41+
version: "0.11.0",
42+
beta_access: [:argo_admin_beta]
43+
)
4244

4345
options = Features::ArgoServeOptions.new(argo_runtime: argo_runtime, context: @context,
4446
renderer_package: argo_admin, required_fields: required_fields)
@@ -92,10 +94,10 @@ def argo_renderer_package(package_name:, version: "0.1.2")
9294
)
9395
end
9496

95-
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: [])
9698
cli = Models::NpmPackage.new(name: cli_package_name, version: version)
9799

98-
Features::ArgoRuntime.new(renderer: renderer_package, cli: cli)
100+
Features::ArgoRuntime.new(renderer: renderer_package, cli: cli, beta_access: beta_access)
99101
end
100102
end
101103
end

0 commit comments

Comments
 (0)