diff options
Diffstat (limited to 'spec/services/quick_actions/interpret_service_spec.rb')
-rw-r--r-- | spec/services/quick_actions/interpret_service_spec.rb | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/spec/services/quick_actions/interpret_service_spec.rb b/spec/services/quick_actions/interpret_service_spec.rb index 5e7fb8397e3..2c34d6a59be 100644 --- a/spec/services/quick_actions/interpret_service_spec.rb +++ b/spec/services/quick_actions/interpret_service_spec.rb @@ -2478,6 +2478,26 @@ RSpec.describe QuickActions::InterpretService, feature_category: :team_planning end it_behaves_like 'quick actions that change work item type' + + context '/set_parent command' do + let_it_be(:parent) { create(:work_item, :issue, project: project) } + let_it_be(:work_item) { create(:work_item, :task, project: project) } + let_it_be(:parent_ref) { parent.to_reference(project) } + + let(:content) { "/set_parent #{parent_ref}" } + + it 'returns success message' do + _, _, message = service.execute(content, work_item) + + expect(message).to eq('Work item parent set successfully') + end + + it 'sets correct update params' do + _, updates, _ = service.execute(content, work_item) + + expect(updates).to eq(set_parent: parent) + end + end end describe '#explain' do @@ -3022,6 +3042,104 @@ RSpec.describe QuickActions::InterpretService, feature_category: :team_planning end end end + + describe '/set_parent command' do + let_it_be(:parent) { create(:work_item, :issue, project: project) } + let_it_be(:work_item) { create(:work_item, :task, project: project) } + let_it_be(:parent_ref) { parent.to_reference(project) } + + let(:command) { "/set_parent #{parent_ref}" } + + shared_examples 'command is available' do + it 'explanation contains correct message' do + _, explanations = service.explain(command, work_item) + + expect(explanations) + .to contain_exactly("Change work item's parent to #{parent_ref}.") + end + + it 'contains command' do + expect(service.available_commands(work_item)).to include(a_hash_including(name: :set_parent)) + end + end + + shared_examples 'command is not available' do + it 'explanation is empty' do + _, explanations = service.explain(command, work_item) + + expect(explanations).to eq([]) + end + + it 'does not contain command' do + expect(service.available_commands(work_item)).not_to include(a_hash_including(name: :set_parent)) + end + end + + context 'when user can admin link' do + it_behaves_like 'command is available' + + context 'when work item type does not support a parent' do + let_it_be(:work_item) { build(:work_item, :incident, project: project) } + + it_behaves_like 'command is not available' + end + end + + context 'when user cannot admin link' do + subject(:service) { described_class.new(project, create(:user)) } + + it_behaves_like 'command is not available' + end + end + + describe '/add_child command' do + let_it_be(:child) { create(:work_item, :issue, project: project) } + let_it_be(:work_item) { create(:work_item, :objective, project: project) } + let_it_be(:child_ref) { child.to_reference(project) } + + let(:command) { "/add_child #{child_ref}" } + + shared_examples 'command is available' do + it 'explanation contains correct message' do + _, explanations = service.explain(command, work_item) + + expect(explanations) + .to contain_exactly("Add #{child_ref} to this work item as child(ren).") + end + + it 'contains command' do + expect(service.available_commands(work_item)).to include(a_hash_including(name: :add_child)) + end + end + + shared_examples 'command is not available' do + it 'explanation is empty' do + _, explanations = service.explain(command, work_item) + + expect(explanations).to eq([]) + end + + it 'does not contain command' do + expect(service.available_commands(work_item)).not_to include(a_hash_including(name: :add_child)) + end + end + + context 'when user can admin link' do + it_behaves_like 'command is available' + + context 'when work item type does not support children' do + let_it_be(:work_item) { build(:work_item, :key_result, project: project) } + + it_behaves_like 'command is not available' + end + end + + context 'when user cannot admin link' do + subject(:service) { described_class.new(project, create(:user)) } + + it_behaves_like 'command is not available' + end + end end describe '#available_commands' do |