Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/notes/quick_actions_service_spec.rb')
-rw-r--r--spec/services/notes/quick_actions_service_spec.rb141
1 files changed, 121 insertions, 20 deletions
diff --git a/spec/services/notes/quick_actions_service_spec.rb b/spec/services/notes/quick_actions_service_spec.rb
index e9decd44730..64aa845841b 100644
--- a/spec/services/notes/quick_actions_service_spec.rb
+++ b/spec/services/notes/quick_actions_service_spec.rb
@@ -4,9 +4,9 @@ require 'spec_helper'
RSpec.describe Notes::QuickActionsService do
shared_context 'note on noteable' do
- let(:project) { create(:project, :repository) }
- let(:maintainer) { create(:user).tap { |u| project.add_maintainer(u) } }
- let(:assignee) { create(:user) }
+ let_it_be(:project) { create(:project, :repository) }
+ let_it_be(:maintainer) { create(:user).tap { |u| project.add_maintainer(u) } }
+ let_it_be(:assignee) { create(:user) }
before do
project.add_maintainer(assignee)
@@ -30,10 +30,9 @@ RSpec.describe Notes::QuickActionsService do
end
it 'closes noteable, sets labels, assigns, and sets milestone to noteable, and leave no note' do
- content, update_params = service.execute(note)
- service.apply_updates(update_params, note)
+ content = execute(note)
- expect(content).to eq ''
+ expect(content).to be_empty
expect(note.noteable).to be_closed
expect(note.noteable.labels).to match_array(labels)
expect(note.noteable.assignees).to eq([assignee])
@@ -41,6 +40,30 @@ RSpec.describe Notes::QuickActionsService do
end
end
+ context '/relate' do
+ let_it_be(:issue) { create(:issue, project: project) }
+ let_it_be(:other_issue) { create(:issue, project: project) }
+ let(:note_text) { "/relate #{other_issue.to_reference}" }
+ let(:note) { create(:note_on_issue, noteable: issue, project: project, note: note_text) }
+
+ context 'user cannot relate issues' do
+ before do
+ project.team.find_member(maintainer.id).destroy!
+ project.update!(visibility: Gitlab::VisibilityLevel::PUBLIC)
+ end
+
+ it 'does not create issue relation' do
+ expect { execute(note) }.not_to change { IssueLink.count }
+ end
+ end
+
+ context 'user is allowed to relate issues' do
+ it 'creates issue relation' do
+ expect { execute(note) }.to change { IssueLink.count }.by(1)
+ end
+ end
+ end
+
describe '/reopen' do
before do
note.noteable.close!
@@ -49,10 +72,9 @@ RSpec.describe Notes::QuickActionsService do
let(:note_text) { '/reopen' }
it 'opens the noteable, and leave no note' do
- content, update_params = service.execute(note)
- service.apply_updates(update_params, note)
+ content = execute(note)
- expect(content).to eq ''
+ expect(content).to be_empty
expect(note.noteable).to be_open
end
end
@@ -62,10 +84,9 @@ RSpec.describe Notes::QuickActionsService do
let(:note_text) { '/spend 1h' }
it 'adds time to noteable, adds timelog with nil note_id and has no content' do
- content, update_params = service.execute(note)
- service.apply_updates(update_params, note)
+ content = execute(note)
- expect(content).to eq ''
+ expect(content).to be_empty
expect(note.noteable.time_spent).to eq(3600)
expect(Timelog.last.note_id).to be_nil
end
@@ -92,8 +113,7 @@ RSpec.describe Notes::QuickActionsService do
end
it 'closes noteable, sets labels, assigns, and sets milestone to noteable' do
- content, update_params = service.execute(note)
- service.apply_updates(update_params, note)
+ content = execute(note)
expect(content).to eq "HELLO\nWORLD"
expect(note.noteable).to be_closed
@@ -111,14 +131,87 @@ RSpec.describe Notes::QuickActionsService do
let(:note_text) { "HELLO\n/reopen\nWORLD" }
it 'opens the noteable' do
- content, update_params = service.execute(note)
- service.apply_updates(update_params, note)
+ content = execute(note)
expect(content).to eq "HELLO\nWORLD"
expect(note.noteable).to be_open
end
end
end
+
+ describe '/milestone' do
+ let(:issue) { create(:issue, project: project) }
+ let(:note_text) { %(/milestone %"#{milestone.name}") }
+ let(:note) { create(:note_on_issue, noteable: issue, project: project, note: note_text) }
+
+ context 'on an incident' do
+ before do
+ issue.update!(issue_type: :incident)
+ end
+
+ it 'leaves the note empty' do
+ expect(execute(note)).to be_empty
+ end
+
+ it 'does not assign the milestone' do
+ expect { execute(note) }.not_to change { issue.reload.milestone }
+ end
+ end
+
+ context 'on a merge request' do
+ let(:note_mr) { create(:note_on_merge_request, project: project, note: note_text) }
+
+ it 'leaves the note empty' do
+ expect(execute(note_mr)).to be_empty
+ end
+
+ it 'assigns the milestone' do
+ expect { execute(note) }.to change { issue.reload.milestone }.from(nil).to(milestone)
+ end
+ end
+ end
+
+ describe '/remove_milestone' do
+ let(:issue) { create(:issue, project: project, milestone: milestone) }
+ let(:note_text) { '/remove_milestone' }
+ let(:note) { create(:note_on_issue, noteable: issue, project: project, note: note_text) }
+
+ context 'on an issue' do
+ it 'leaves the note empty' do
+ expect(execute(note)).to be_empty
+ end
+
+ it 'removes the milestone' do
+ expect { execute(note) }.to change { issue.reload.milestone }.from(milestone).to(nil)
+ end
+ end
+
+ context 'on an incident' do
+ before do
+ issue.update!(issue_type: :incident)
+ end
+
+ it 'leaves the note empty' do
+ expect(execute(note)).to be_empty
+ end
+
+ it 'does not remove the milestone' do
+ expect { execute(note) }.not_to change { issue.reload.milestone }
+ end
+ end
+
+ context 'on a merge request' do
+ let(:note_mr) { create(:note_on_merge_request, project: project, note: note_text) }
+
+ it 'leaves the note empty' do
+ expect(execute(note_mr)).to be_empty
+ end
+
+ it 'removes the milestone' do
+ expect { execute(note) }.to change { issue.reload.milestone }.from(milestone).to(nil)
+ end
+ end
+ end
end
describe '.noteable_update_service' do
@@ -180,11 +273,13 @@ RSpec.describe Notes::QuickActionsService do
let(:service) { described_class.new(project, maintainer) }
it_behaves_like 'note on noteable that supports quick actions' do
- let(:note) { build(:note_on_issue, project: project) }
+ let_it_be(:issue, reload: true) { create(:issue, project: project) }
+ let(:note) { build(:note_on_issue, project: project, noteable: issue) }
end
it_behaves_like 'note on noteable that supports quick actions' do
- let(:note) { build(:note_on_merge_request, project: project) }
+ let(:merge_request) { create(:merge_request, source_project: project) }
+ let(:note) { build(:note_on_merge_request, project: project, noteable: merge_request) }
end
end
@@ -207,11 +302,17 @@ RSpec.describe Notes::QuickActionsService do
end
it 'adds only one assignee from the list' do
- _, update_params = service.execute(note)
- service.apply_updates(update_params, note)
+ execute(note)
expect(note.noteable.assignees.count).to eq(1)
end
end
end
+
+ def execute(note)
+ content, update_params = service.execute(note)
+ service.apply_updates(update_params, note)
+
+ content
+ end
end