2019-04-11 08:17:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-10-26 17:21:50 -04:00
|
|
|
require 'spec_helper.rb'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe Issues::BuildService do
|
2017-03-27 17:14:01 -04:00
|
|
|
let(:project) { create(:project, :repository) }
|
2016-10-26 17:21:50 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(user)
|
2016-10-26 17:21:50 -04:00
|
|
|
end
|
|
|
|
|
2019-01-14 05:46:39 -05:00
|
|
|
def build_issue(issue_params = {})
|
|
|
|
described_class.new(project, user, issue_params).execute
|
|
|
|
end
|
|
|
|
|
2016-12-22 07:31:12 -05:00
|
|
|
context 'for a single discussion' do
|
|
|
|
describe '#execute' do
|
2017-02-27 04:23:36 -05:00
|
|
|
let(:merge_request) { create(:merge_request, title: "Hello world", source_project: project) }
|
2017-03-17 15:25:52 -04:00
|
|
|
let(:discussion) { create(:diff_note_on_merge_request, project: project, noteable: merge_request, note: "Almost done").to_discussion }
|
2016-12-22 07:31:12 -05:00
|
|
|
|
2019-01-14 05:46:39 -05:00
|
|
|
subject { build_issue(merge_request_to_resolve_discussions_of: merge_request.iid, discussion_to_resolve: discussion.id) }
|
2016-12-22 07:31:12 -05:00
|
|
|
|
2019-01-14 05:46:39 -05:00
|
|
|
it 'references the noteable title in the issue title' do
|
|
|
|
expect(subject.title).to include('Hello world')
|
2016-12-22 07:31:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds the note content to the description' do
|
2019-01-14 05:46:39 -05:00
|
|
|
expect(subject.description).to include('Almost done')
|
2016-12-22 07:31:12 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-10-26 17:21:50 -04:00
|
|
|
context 'for discussions in a merge request' do
|
|
|
|
let(:merge_request) { create(:merge_request_with_diff_notes, source_project: project) }
|
|
|
|
|
|
|
|
describe '#items_for_discussions' do
|
|
|
|
it 'has an item for each discussion' do
|
2016-12-22 07:31:12 -05:00
|
|
|
create(:diff_note_on_merge_request, noteable: merge_request, project: merge_request.source_project, line_number: 13)
|
2017-03-10 03:19:12 -05:00
|
|
|
service = described_class.new(project, user, merge_request_to_resolve_discussions_of: merge_request.iid)
|
2016-10-26 17:21:50 -04:00
|
|
|
|
|
|
|
service.execute
|
|
|
|
|
|
|
|
expect(service.items_for_discussions.size).to eq(2)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#item_for_discussion' do
|
2017-03-10 03:19:12 -05:00
|
|
|
let(:service) { described_class.new(project, user, merge_request_to_resolve_discussions_of: merge_request.iid) }
|
2016-10-26 17:21:50 -04:00
|
|
|
|
|
|
|
it 'mentions the author of the note' do
|
2017-03-17 15:25:52 -04:00
|
|
|
discussion = create(:diff_note_on_merge_request, author: create(:user, username: 'author')).to_discussion
|
2016-10-26 17:21:50 -04:00
|
|
|
expect(service.item_for_discussion(discussion)).to include('@author')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'wraps the note in a blockquote' do
|
|
|
|
note_text = "This is a string\n"\
|
|
|
|
">>>\n"\
|
|
|
|
"with a blockquote\n"\
|
|
|
|
"> That has a quote\n"\
|
|
|
|
">>>\n"
|
2017-03-07 18:55:50 -05:00
|
|
|
note_result = " > This is a string\n"\
|
2019-04-03 09:42:23 -04:00
|
|
|
" > \n"\
|
2017-03-07 18:55:50 -05:00
|
|
|
" > > with a blockquote\n"\
|
2019-04-03 09:42:23 -04:00
|
|
|
" > > > That has a quote\n"\
|
|
|
|
" > \n"
|
2017-03-17 15:25:52 -04:00
|
|
|
discussion = create(:diff_note_on_merge_request, note: note_text).to_discussion
|
2017-03-07 18:55:50 -05:00
|
|
|
expect(service.item_for_discussion(discussion)).to include(note_result)
|
2016-10-26 17:21:50 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#execute' do
|
2019-01-14 05:46:39 -05:00
|
|
|
let(:base_params) { { merge_request_to_resolve_discussions_of: merge_request.iid } }
|
2016-10-26 17:21:50 -04:00
|
|
|
|
2019-01-14 05:46:39 -05:00
|
|
|
context 'without additional params' do
|
|
|
|
subject { build_issue(base_params) }
|
|
|
|
|
|
|
|
it 'has the merge request reference in the title' do
|
|
|
|
expect(subject.title).to include(merge_request.title)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the reference of the merge request in the description' do
|
|
|
|
expect(subject.description).to include(merge_request.to_reference)
|
|
|
|
end
|
2016-10-26 17:21:50 -04:00
|
|
|
end
|
|
|
|
|
2019-01-14 05:46:39 -05:00
|
|
|
it 'uses provided title if title param given' do
|
|
|
|
issue = build_issue(base_params.merge(title: 'What an issue'))
|
2016-10-26 17:21:50 -04:00
|
|
|
|
|
|
|
expect(issue.title).to eq('What an issue')
|
|
|
|
end
|
|
|
|
|
2019-01-14 05:46:39 -05:00
|
|
|
it 'uses provided description if description param given' do
|
|
|
|
issue = build_issue(base_params.merge(description: 'Fix at your earliest convenience'))
|
2016-10-26 17:21:50 -04:00
|
|
|
|
2019-01-14 05:46:39 -05:00
|
|
|
expect(issue.description).to eq('Fix at your earliest convenience')
|
2016-10-26 17:21:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with multiple discussions' do
|
2017-03-31 17:52:38 -04:00
|
|
|
let!(:diff_note) { create(:diff_note_on_merge_request, noteable: merge_request, project: merge_request.target_project, line_number: 15) }
|
2016-10-26 17:21:50 -04:00
|
|
|
|
|
|
|
it 'mentions all the authors in the description' do
|
2017-03-09 20:29:11 -05:00
|
|
|
authors = merge_request.resolvable_discussions.map(&:author)
|
2016-10-26 17:21:50 -04:00
|
|
|
|
2019-01-14 05:46:39 -05:00
|
|
|
expect(build_issue(base_params).description).to include(*authors.map(&:to_reference))
|
2016-10-26 17:21:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'has a link for each unresolved discussion in the description' do
|
2017-03-09 20:29:11 -05:00
|
|
|
notes = merge_request.resolvable_discussions.map(&:first_note)
|
2016-10-26 17:21:50 -04:00
|
|
|
links = notes.map { |note| Gitlab::UrlBuilder.build(note) }
|
|
|
|
|
2019-01-14 05:46:39 -05:00
|
|
|
expect(build_issue(base_params).description).to include(*links)
|
2016-10-26 17:21:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'mentions additional notes' do
|
2017-03-31 17:52:38 -04:00
|
|
|
create_list(:diff_note_on_merge_request, 2, noteable: merge_request, project: merge_request.target_project, in_reply_to: diff_note)
|
2016-10-26 17:21:50 -04:00
|
|
|
|
2019-01-14 05:46:39 -05:00
|
|
|
expect(build_issue(base_params).description).to include('(+2 comments)')
|
2016-10-26 17:21:50 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'For a merge request without discussions' do
|
|
|
|
let(:merge_request) { create(:merge_request, source_project: project) }
|
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
it 'mentions the merge request in the description' do
|
2019-01-14 05:46:39 -05:00
|
|
|
issue = build_issue(merge_request_to_resolve_discussions_of: merge_request.iid)
|
2016-10-26 17:21:50 -04:00
|
|
|
|
|
|
|
expect(issue.description).to include("Review the conversation in #{merge_request.to_reference}")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
it 'builds a new issues with given params' do
|
2019-01-14 05:46:39 -05:00
|
|
|
milestone = create(:milestone, project: project)
|
|
|
|
issue = build_issue(milestone_id: milestone.id)
|
|
|
|
|
2017-01-28 19:14:56 -05:00
|
|
|
expect(issue.milestone).to eq(milestone)
|
2016-10-26 17:21:50 -04:00
|
|
|
end
|
2019-01-14 05:46:39 -05:00
|
|
|
|
|
|
|
it 'sets milestone to nil if it is not available for the project' do
|
|
|
|
milestone = create(:milestone, project: create(:project))
|
|
|
|
issue = build_issue(milestone_id: milestone.id)
|
|
|
|
|
|
|
|
expect(issue.milestone).to be_nil
|
|
|
|
end
|
2016-10-26 17:21:50 -04:00
|
|
|
end
|
|
|
|
end
|