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 #1696 from Shopify/acceptance-test-node-create
Browse files Browse the repository at this point in the history
add acceptance test for `node create`
  • Loading branch information
hannachen committed Nov 10, 2021
2 parents 991ae13 + 6bee860 commit e89cb4c
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 13 deletions.
10 changes: 9 additions & 1 deletion features/app.feature
Expand Up @@ -4,4 +4,12 @@ Feature: The app command
Given I have a VM with the CLI and a working directory
When I create a rails app named MyRailsApp in the VM
Then the app has an environment file with SHOPIFY_API_KEY set to public_api_key
Then the app has an environment file with SHOPIFY_API_SECRET set to api_secret_key
Then the app has an environment file with SHOPIFY_API_SECRET set to api_secret_key
Then the app has a yaml file to specify a node project type

Scenario: The user wants to create a node app
Given I have a VM with the CLI and a working directory
When I create a node app named MyNodeApp in the VM
Then the app has an environment file with SHOPIFY_API_KEY set to public_api_key
Then the app has an environment file with SHOPIFY_API_SECRET set to api_secret_key
Then the app has a yaml file to specify a node project type
17 changes: 17 additions & 0 deletions features/step_definitions/commands/app.rb
Expand Up @@ -9,6 +9,14 @@
)
end

When(/I create a node app named (.+) in the VM/) do |app_name|
@app_name = app_name
@container.exec_shopify(
"app", "create", "node",
"--name", app_name,
)
end

Then(/the app has an environment file with (.+) set to (.+)/) do |key, value|
generated_env_file_path = File.join(@app_name, ".env")

Expand All @@ -17,3 +25,12 @@

assert env_value[key], value
end

Then(/the app has a yaml file to specify a (.+) project type/) do |project_type|
generated_yaml_file_path = File.join(@app_name, ".shopify-cli.yml")

yaml_file_content = @container.capture("cat", generated_yaml_file_path).chomp
project_config = YAML.load(yaml_file_content)

assert project_config["project_type"], project_type
end
4 changes: 3 additions & 1 deletion lib/shopify_cli/commands/app/create/node.rb
Expand Up @@ -3,7 +3,9 @@ module Commands
class App
class Create
class Node < ShopifyCLI::Command::AppSubCommand
prerequisite_task :ensure_authenticated
unless ShopifyCLI::Environment.acceptance_test?
prerequisite_task :ensure_authenticated
end

options do |parser, flags|
parser.on("--name=NAME") { |t| flags[:name] = t }
Expand Down
6 changes: 5 additions & 1 deletion lib/shopify_cli/project.rb
Expand Up @@ -81,7 +81,11 @@ def current_project_type
#
# #### Example
#
# type = ShopifyCLI::Project.current_project_type
# ShopifyCLI::Project.write(
# @ctx,
# project_type: "node",
# organization_id: form_data.organization_id,
# )
#
def write(ctx, project_type:, organization_id:, **identifiers)
require "yaml" # takes 20ms, so deferred as late as possible.
Expand Down
38 changes: 31 additions & 7 deletions lib/shopify_cli/services/app/create/node_service.rb
Expand Up @@ -18,7 +18,7 @@ def initialize(name:, organization_id:, store_domain:, type:, verbose:, context:
end

def call
form = ::Node::Forms::Create.ask(context, [], {
form = form_data({
name: name,
organization_id: organization_id,
shop_domain: store_domain,
Expand All @@ -36,12 +36,23 @@ def call
organization_id: form.organization_id,
)

api_client = ShopifyCLI::Tasks::CreateApiClient.call(
context,
org_id: form.organization_id,
title: form.name,
type: form.type,
)
api_client = if ShopifyCLI::Environment.acceptance_test?
{
"apiKey" => "public_api_key",
"apiSecretKeys" => [
{
"secret" => "api_secret_key",
},
],
}
else
ShopifyCLI::Tasks::CreateApiClient.call(
context,
org_id: form.organization_id,
title: form.name,
type: form.type,
)
end

ShopifyCLI::Resources::EnvFile.new(
api_key: api_client["apiKey"],
Expand All @@ -61,6 +72,19 @@ def call

private

def form_data(form_options)
if ShopifyCLI::Environment.acceptance_test?
Struct.new(:name, :organization_id, :type, :shop_domain, keyword_init: true).new(
name: form_options[:name],
organization_id: form_options[:organization_id] || "123",
shop_domain: form_options[:shop_domain] || "test.shopify.io",
type: form_options[:type] || "public",
)
else
Node::Forms::Create.ask(context, [], form_options)
end
end

def check_node
cmd_path = context.which("node")
context.abort(context.message("core.app.create.node.error.node_required")) if cmd_path.nil?
Expand Down
13 changes: 10 additions & 3 deletions utilities/docker/container.rb
Expand Up @@ -79,12 +79,19 @@ def exec(*args, relative_dir: nil)
if ARGV.include?("--verbose")
stat = Open3.popen3(*command) do |stdin, stdout, stderr, wait_thread|
Thread.new do
stdout.each { |l| STDOUT.puts("#{docker_prefix.colorize(:cyan).bold} #{l}") }
stderr.each { |l| STDERR.puts("#{docker_prefix.colorize(:red).bold} #{l}") }
stdout.each { |l| STDOUT.puts("#{docker_prefix.colorize(:cyan).bold} #{l}") } unless stdout&.nil?
end
Thread.new do
stderr.each { |l| STDERR.puts("#{docker_prefix.colorize(:red).bold} #{l}") } unless stderr&.nil?
end
stdin.close

wait_thread.value
status = wait_thread.value

stdout.close
stderr.close

status
end
raise StandardError, "The command #{args.first} failed" unless stat.success?
else
Expand Down

0 comments on commit e89cb4c

Please sign in to comment.