2019-12-04 20:38:33 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::QuickActions::Dsl do
|
2016-09-13 17:45:13 +05:30
|
|
|
before :all do
|
|
|
|
DummyClass = Struct.new(:project) do
|
2020-03-13 15:44:24 +05:30
|
|
|
include Gitlab::QuickActions::Dsl
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
desc 'A command with no args'
|
|
|
|
command :no_args, :none do
|
|
|
|
"Hello World!"
|
|
|
|
end
|
|
|
|
|
|
|
|
params 'The first argument'
|
2017-08-17 22:00:37 +05:30
|
|
|
explanation 'Static explanation'
|
2019-02-15 15:39:39 +05:30
|
|
|
warning 'Possible problem!'
|
2017-08-17 22:00:37 +05:30
|
|
|
command :explanation_with_aliases, :once, :first do |arg|
|
|
|
|
arg
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
desc do
|
|
|
|
"A dynamic description for #{noteable.upcase}"
|
|
|
|
end
|
2019-10-12 21:52:04 +05:30
|
|
|
execution_message do |arg|
|
|
|
|
"A dynamic execution message for #{noteable.upcase} passing #{arg}"
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
params 'The first argument', 'The second argument'
|
2017-08-17 22:00:37 +05:30
|
|
|
command :dynamic_description do |args|
|
|
|
|
args.split
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
command :cc
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
explanation do |arg|
|
|
|
|
"Action does something with #{arg}"
|
|
|
|
end
|
2019-10-12 21:52:04 +05:30
|
|
|
execution_message 'Command applied correctly'
|
2016-09-13 17:45:13 +05:30
|
|
|
condition do
|
|
|
|
project == 'foo'
|
|
|
|
end
|
|
|
|
command :cond_action do |arg|
|
|
|
|
arg
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
parse_params do |raw_arg|
|
|
|
|
raw_arg.strip
|
|
|
|
end
|
|
|
|
command :with_params_parsing do |parsed|
|
|
|
|
parsed
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
params '<Comment>'
|
|
|
|
substitution :something do |text|
|
|
|
|
"#{text} Some complicated thing you want in here"
|
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
desc 'A command with types'
|
|
|
|
types Issue, Commit
|
|
|
|
command :has_types do
|
|
|
|
"Has Issue and Commit types"
|
|
|
|
end
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.command_definitions' do
|
|
|
|
it 'returns an array with commands definitions' do
|
2017-08-17 22:00:37 +05:30
|
|
|
no_args_def, explanation_with_aliases_def, dynamic_description_def,
|
2019-07-07 11:18:12 +05:30
|
|
|
cc_def, cond_action_def, with_params_parsing_def, substitution_def, has_types =
|
2017-08-17 22:00:37 +05:30
|
|
|
DummyClass.command_definitions
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
expect(no_args_def.name).to eq(:no_args)
|
|
|
|
expect(no_args_def.aliases).to eq([:none])
|
|
|
|
expect(no_args_def.description).to eq('A command with no args')
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(no_args_def.explanation).to eq('')
|
2019-10-12 21:52:04 +05:30
|
|
|
expect(no_args_def.execution_message).to eq('')
|
2016-09-13 17:45:13 +05:30
|
|
|
expect(no_args_def.params).to eq([])
|
|
|
|
expect(no_args_def.condition_block).to be_nil
|
2019-07-07 11:18:12 +05:30
|
|
|
expect(no_args_def.types).to eq([])
|
2016-09-13 17:45:13 +05:30
|
|
|
expect(no_args_def.action_block).to be_a_kind_of(Proc)
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(no_args_def.parse_params_block).to be_nil
|
2019-02-15 15:39:39 +05:30
|
|
|
expect(no_args_def.warning).to eq('')
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(explanation_with_aliases_def.name).to eq(:explanation_with_aliases)
|
|
|
|
expect(explanation_with_aliases_def.aliases).to eq([:once, :first])
|
|
|
|
expect(explanation_with_aliases_def.description).to eq('')
|
|
|
|
expect(explanation_with_aliases_def.explanation).to eq('Static explanation')
|
2019-10-12 21:52:04 +05:30
|
|
|
expect(explanation_with_aliases_def.execution_message).to eq('')
|
|
|
|
expect(no_args_def.params).to eq([])
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(explanation_with_aliases_def.params).to eq(['The first argument'])
|
|
|
|
expect(explanation_with_aliases_def.condition_block).to be_nil
|
2019-07-07 11:18:12 +05:30
|
|
|
expect(explanation_with_aliases_def.types).to eq([])
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(explanation_with_aliases_def.action_block).to be_a_kind_of(Proc)
|
|
|
|
expect(explanation_with_aliases_def.parse_params_block).to be_nil
|
2019-02-15 15:39:39 +05:30
|
|
|
expect(explanation_with_aliases_def.warning).to eq('Possible problem!')
|
2016-09-13 17:45:13 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(dynamic_description_def.name).to eq(:dynamic_description)
|
|
|
|
expect(dynamic_description_def.aliases).to eq([])
|
2018-03-27 19:54:05 +05:30
|
|
|
expect(dynamic_description_def.to_h(OpenStruct.new(noteable: 'issue'))[:description]).to eq('A dynamic description for ISSUE')
|
2019-10-12 21:52:04 +05:30
|
|
|
expect(dynamic_description_def.execute_message(OpenStruct.new(noteable: 'issue'), 'arg')).to eq('A dynamic execution message for ISSUE passing arg')
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(dynamic_description_def.params).to eq(['The first argument', 'The second argument'])
|
|
|
|
expect(dynamic_description_def.condition_block).to be_nil
|
2019-07-07 11:18:12 +05:30
|
|
|
expect(dynamic_description_def.types).to eq([])
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(dynamic_description_def.action_block).to be_a_kind_of(Proc)
|
|
|
|
expect(dynamic_description_def.parse_params_block).to be_nil
|
2019-02-15 15:39:39 +05:30
|
|
|
expect(dynamic_description_def.warning).to eq('')
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
expect(cc_def.name).to eq(:cc)
|
|
|
|
expect(cc_def.aliases).to eq([])
|
|
|
|
expect(cc_def.description).to eq('')
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(cc_def.explanation).to eq('')
|
2019-10-12 21:52:04 +05:30
|
|
|
expect(cc_def.execution_message).to eq('')
|
2016-09-13 17:45:13 +05:30
|
|
|
expect(cc_def.params).to eq([])
|
|
|
|
expect(cc_def.condition_block).to be_nil
|
2019-07-07 11:18:12 +05:30
|
|
|
expect(cc_def.types).to eq([])
|
2016-09-13 17:45:13 +05:30
|
|
|
expect(cc_def.action_block).to be_nil
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(cc_def.parse_params_block).to be_nil
|
2019-02-15 15:39:39 +05:30
|
|
|
expect(cc_def.warning).to eq('')
|
2016-09-13 17:45:13 +05:30
|
|
|
|
|
|
|
expect(cond_action_def.name).to eq(:cond_action)
|
|
|
|
expect(cond_action_def.aliases).to eq([])
|
|
|
|
expect(cond_action_def.description).to eq('')
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(cond_action_def.explanation).to be_a_kind_of(Proc)
|
2019-10-12 21:52:04 +05:30
|
|
|
expect(cond_action_def.execution_message).to eq('Command applied correctly')
|
2016-09-13 17:45:13 +05:30
|
|
|
expect(cond_action_def.params).to eq([])
|
|
|
|
expect(cond_action_def.condition_block).to be_a_kind_of(Proc)
|
2019-07-07 11:18:12 +05:30
|
|
|
expect(cond_action_def.types).to eq([])
|
2016-09-13 17:45:13 +05:30
|
|
|
expect(cond_action_def.action_block).to be_a_kind_of(Proc)
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(cond_action_def.parse_params_block).to be_nil
|
2019-02-15 15:39:39 +05:30
|
|
|
expect(cond_action_def.warning).to eq('')
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
expect(with_params_parsing_def.name).to eq(:with_params_parsing)
|
|
|
|
expect(with_params_parsing_def.aliases).to eq([])
|
|
|
|
expect(with_params_parsing_def.description).to eq('')
|
|
|
|
expect(with_params_parsing_def.explanation).to eq('')
|
2019-10-12 21:52:04 +05:30
|
|
|
expect(with_params_parsing_def.execution_message).to eq('')
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(with_params_parsing_def.params).to eq([])
|
|
|
|
expect(with_params_parsing_def.condition_block).to be_nil
|
2019-07-07 11:18:12 +05:30
|
|
|
expect(with_params_parsing_def.types).to eq([])
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(with_params_parsing_def.action_block).to be_a_kind_of(Proc)
|
|
|
|
expect(with_params_parsing_def.parse_params_block).to be_a_kind_of(Proc)
|
2019-02-15 15:39:39 +05:30
|
|
|
expect(with_params_parsing_def.warning).to eq('')
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
expect(substitution_def.name).to eq(:something)
|
|
|
|
expect(substitution_def.aliases).to eq([])
|
|
|
|
expect(substitution_def.description).to eq('')
|
|
|
|
expect(substitution_def.explanation).to eq('')
|
2019-10-12 21:52:04 +05:30
|
|
|
expect(substitution_def.execution_message).to eq('')
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(substitution_def.params).to eq(['<Comment>'])
|
|
|
|
expect(substitution_def.condition_block).to be_nil
|
2019-07-07 11:18:12 +05:30
|
|
|
expect(substitution_def.types).to eq([])
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(substitution_def.action_block.call('text')).to eq('text Some complicated thing you want in here')
|
|
|
|
expect(substitution_def.parse_params_block).to be_nil
|
2019-02-15 15:39:39 +05:30
|
|
|
expect(substitution_def.warning).to eq('')
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
expect(has_types.name).to eq(:has_types)
|
|
|
|
expect(has_types.aliases).to eq([])
|
|
|
|
expect(has_types.description).to eq('A command with types')
|
|
|
|
expect(has_types.explanation).to eq('')
|
2019-10-12 21:52:04 +05:30
|
|
|
expect(has_types.execution_message).to eq('')
|
2019-07-07 11:18:12 +05:30
|
|
|
expect(has_types.params).to eq([])
|
|
|
|
expect(has_types.condition_block).to be_nil
|
|
|
|
expect(has_types.types).to eq([Issue, Commit])
|
|
|
|
expect(has_types.action_block).to be_a_kind_of(Proc)
|
|
|
|
expect(has_types.parse_params_block).to be_nil
|
|
|
|
expect(has_types.warning).to eq('')
|
2016-09-13 17:45:13 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|