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

Commit

Permalink
Add beta setting for Employee authentication (#1003)
Browse files Browse the repository at this point in the history
* Add beta feature flag for Employee authentication
  • Loading branch information
andyw8 authored Dec 11, 2020
1 parent a6afa42 commit dc4a608
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 11 deletions.
24 changes: 24 additions & 0 deletions lib/shopify-cli/commands/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Config < ShopifyCli::Command

subcommand :Feature, 'feature'
subcommand :Analytics, 'analytics'
subcommand :ShopifolkBeta, 'shopifolk-beta'

def call(*)
@ctx.puts(self.class.help)
Expand Down Expand Up @@ -71,6 +72,29 @@ def call(_args, _name)
end
end
end

class ShopifolkBeta < ShopifyCli::SubCommand
options do |parser, flags|
parser.on('--enable') { flags[:action] = 'enable' }
parser.on('--disable') { flags[:action] = 'disable' }
parser.on('--status') { flags[:action] = 'status' }
end

def call(_args, _name)
is_enabled = ShopifyCli::Config.get_bool('shopifolk-beta', 'enabled')
if options.flags[:action] == 'disable' && is_enabled
ShopifyCli::Config.set('shopifolk-beta', 'enabled', false)
@ctx.puts(@ctx.message('core.config.shopifolk_beta.disabled'))
elsif options.flags[:action] == 'enable' && !is_enabled
ShopifyCli::Config.set('shopifolk-beta', 'enabled', true)
@ctx.puts(@ctx.message('core.config.shopifolk_beta.enabled'))
elsif is_enabled
@ctx.puts(@ctx.message('core.config.shopifolk_beta.is_enabled'))
else
@ctx.puts(@ctx.message('core.config.shopifolk_beta.is_disabled'))
end
end
end
end
end
end
10 changes: 10 additions & 0 deletions lib/shopify-cli/messages/messages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ module Messages
is_enabled: "{{v}} analytics are currently enabled",
is_disabled: "{{v}} analytics are currently disabled",
},
shopifolk_beta: {
help: <<~HELP,
Opt in/out of shopifolk beta
Usage: {{command:%s config [ analytics ] }}
HELP
enabled: "{{v}} shopifolk-beta has been enabled",
disabled: "{{v}} shopifolk-beta has been disabled",
is_enabled: "{{v}} shopifolk-beta is currently enabled",
is_disabled: "{{v}} shopifolk-beta is currently disabled",
},
},

git: {
Expand Down
3 changes: 3 additions & 0 deletions lib/shopify-cli/shopifolk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class << self
# ShopifyCli::Shopifolk.check
#
def check
return false unless Feature.enabled?('shopifolk-beta')
ShopifyCli::Shopifolk.new.shopifolk?
end

Expand All @@ -50,7 +51,9 @@ def reset
# a valid google cloud config file with email ending in "@shopify.com"
#
def shopifolk?
return false unless Feature.enabled?('shopifolk-beta')
return true if Feature.enabled?(FEATURE_NAME)

if shopifolk_by_gcloud? && shopifolk_by_dev?
ShopifyCli::Feature.enable(FEATURE_NAME)
true
Expand Down
12 changes: 12 additions & 0 deletions test/shopify-cli/commands/config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ def test_will_disable_analytics_that_is_enabled
run_cmd("config analytics --disable")
refute ShopifyCli::Config.get_bool('analytics', 'enabled')
end

def test_will_enable_shopifolk_beta_that_is_disabled
ShopifyCli::Config.set('shopifolk-beta', 'enabled', false)
run_cmd("config shopifolk-beta --enable")
assert ShopifyCli::Config.get_bool('shopifolk-beta', 'enabled')
end

def test_will_disable_shopifolk_beta_that_is_enabled
ShopifyCli::Config.set('shopifolk-beta', 'enabled', true)
run_cmd("config shopifolk-beta --disable")
refute ShopifyCli::Config.get_bool('shopifolk-beta', 'enabled')
end
end
end
end
18 changes: 7 additions & 11 deletions test/shopify-cli/shopifolk_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@ module ShopifyCli
class ShopifolkTest < MiniTest::Test
include TestHelpers::FakeFS

def test_correct_features_is_shopifolk
def setup
super
ShopifyCli::Feature.enable('shopifolk-beta')
ShopifyCli::Feature.disable('shopifolk')
end

def test_correct_features_is_shopifolk
FileUtils.mkdir_p("/opt/dev/bin")
FileUtils.touch("/opt/dev/bin/dev")
FileUtils.touch("/opt/dev/.shopify-build")
Expand All @@ -24,17 +29,14 @@ def test_feature_always_returns_true
end

def test_no_gcloud_config_disables_shopifolk_feature
ShopifyCli::Feature.enable('shopifolk')
ShopifyCli::Feature.stubs(:enabled?).with('shopifolk').returns(false)
refute ShopifyCli::Config.get_bool('features', 'shopifolk')

ShopifyCli::Shopifolk.check

refute ShopifyCli::Config.get_bool('features', 'shopifolk')
end

def test_no_section_in_gcloud_config_disables_shopifolk_feature
ShopifyCli::Feature.enable('shopifolk')
ShopifyCli::Feature.stubs(:enabled?).with('shopifolk').returns(false)
stub_gcloud_ini({ "account" => "[email protected]", "project" => "shopify-dev" })

ShopifyCli::Shopifolk.check
Expand All @@ -43,8 +45,6 @@ def test_no_section_in_gcloud_config_disables_shopifolk_feature
end

def test_no_account_in_gcloud_config_disables_shopifolk_feature
ShopifyCli::Feature.enable('shopifolk')
ShopifyCli::Feature.stubs(:enabled?).with('shopifolk').returns(false)
stub_gcloud_ini({ "[core]" => { "project" => "shopify-dev" } })

ShopifyCli::Shopifolk.check
Expand All @@ -53,8 +53,6 @@ def test_no_account_in_gcloud_config_disables_shopifolk_feature
end

def test_incorrect_email_in_gcloud_config_disables_shopifolk_feature
ShopifyCli::Feature.enable('shopifolk')
ShopifyCli::Feature.stubs(:enabled?).with('shopifolk').returns(false)
stub_gcloud_ini({ "[core]" => { "account" => "[email protected]", "project" => "shopify-dev" } })

ShopifyCli::Shopifolk.check
Expand All @@ -63,8 +61,6 @@ def test_incorrect_email_in_gcloud_config_disables_shopifolk_feature
end

def test_incorrect_dev_path_disables_dev_shopifolk_feature
ShopifyCli::Feature.enable('shopifolk')
ShopifyCli::Feature.stubs(:enabled?).with('shopifolk').returns(false)
stub_gcloud_ini({ "[core]" => { "account" => "[email protected]", "project" => "shopify-dev" } })

ShopifyCli::Shopifolk.check
Expand Down

0 comments on commit dc4a608

Please sign in to comment.