2019-04-11 08:17:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-07-20 10:42:33 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 11:08:50 -04:00
|
|
|
RSpec.describe Issues::DuplicateService do
|
2017-07-20 10:42:33 -04:00
|
|
|
let(:user) { create(:user) }
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:canonical_project) { create(:project) }
|
|
|
|
let(:duplicate_project) { create(:project) }
|
2017-07-20 10:42:33 -04:00
|
|
|
|
|
|
|
let(:canonical_issue) { create(:issue, project: canonical_project) }
|
|
|
|
let(:duplicate_issue) { create(:issue, project: duplicate_project) }
|
|
|
|
|
2021-05-11 23:10:21 -04:00
|
|
|
subject { described_class.new(project: duplicate_project, current_user: user) }
|
2017-07-20 10:42:33 -04:00
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
context 'when the issues passed are the same' do
|
|
|
|
it 'does nothing' do
|
|
|
|
expect(subject).not_to receive(:close_service)
|
|
|
|
expect(SystemNoteService).not_to receive(:mark_duplicate_issue)
|
|
|
|
expect(SystemNoteService).not_to receive(:mark_canonical_issue_of_duplicate)
|
|
|
|
|
|
|
|
subject.execute(duplicate_issue, duplicate_issue)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the user cannot update the duplicate issue' do
|
|
|
|
before do
|
|
|
|
canonical_project.add_reporter(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does nothing' do
|
|
|
|
expect(subject).not_to receive(:close_service)
|
|
|
|
expect(SystemNoteService).not_to receive(:mark_duplicate_issue)
|
|
|
|
expect(SystemNoteService).not_to receive(:mark_canonical_issue_of_duplicate)
|
|
|
|
|
|
|
|
subject.execute(duplicate_issue, canonical_issue)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the user cannot comment on the canonical issue' do
|
|
|
|
before do
|
|
|
|
duplicate_project.add_reporter(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does nothing' do
|
|
|
|
expect(subject).not_to receive(:close_service)
|
|
|
|
expect(SystemNoteService).not_to receive(:mark_duplicate_issue)
|
|
|
|
expect(SystemNoteService).not_to receive(:mark_canonical_issue_of_duplicate)
|
|
|
|
|
|
|
|
subject.execute(duplicate_issue, canonical_issue)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the user can mark the issue as a duplicate' do
|
|
|
|
before do
|
|
|
|
canonical_project.add_reporter(user)
|
|
|
|
duplicate_project.add_reporter(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'closes the duplicate issue' do
|
|
|
|
subject.execute(duplicate_issue, canonical_issue)
|
|
|
|
|
|
|
|
expect(duplicate_issue.reload).to be_closed
|
|
|
|
expect(canonical_issue.reload).to be_open
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds a system note to the duplicate issue' do
|
|
|
|
expect(SystemNoteService)
|
|
|
|
.to receive(:mark_duplicate_issue).with(duplicate_issue, duplicate_project, user, canonical_issue)
|
|
|
|
|
|
|
|
subject.execute(duplicate_issue, canonical_issue)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds a system note to the canonical issue' do
|
|
|
|
expect(SystemNoteService)
|
|
|
|
.to receive(:mark_canonical_issue_of_duplicate).with(canonical_issue, canonical_project, user, duplicate_issue)
|
|
|
|
|
|
|
|
subject.execute(duplicate_issue, canonical_issue)
|
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
|
|
|
it 'updates duplicate issue with canonical issue id' do
|
|
|
|
subject.execute(duplicate_issue, canonical_issue)
|
|
|
|
|
|
|
|
expect(duplicate_issue.reload.duplicated_to).to eq(canonical_issue)
|
|
|
|
end
|
2020-08-20 20:10:44 -04:00
|
|
|
|
|
|
|
it 'relates the duplicate issues' do
|
|
|
|
canonical_project.add_reporter(user)
|
|
|
|
duplicate_project.add_reporter(user)
|
|
|
|
|
|
|
|
subject.execute(duplicate_issue, canonical_issue)
|
|
|
|
|
|
|
|
issue_link = IssueLink.last
|
|
|
|
expect(issue_link.source).to eq(duplicate_issue)
|
|
|
|
expect(issue_link.target).to eq(canonical_issue)
|
|
|
|
end
|
2017-07-20 10:42:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|