2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper.rb'
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
describe Issues::ResolveDiscussions do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
2020-05-24 23:13:21 +05:30
|
|
|
stub_const('DummyService', Class.new(Issues::BaseService))
|
|
|
|
DummyService.class_eval do
|
|
|
|
include ::Issues::ResolveDiscussions
|
|
|
|
|
|
|
|
def initialize(*args)
|
|
|
|
super
|
|
|
|
filter_resolve_discussion_params
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
project.add_developer(user)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe "for resolving discussions" do
|
|
|
|
let(:discussion) { create(:diff_note_on_merge_request, project: project, note: "Almost done").to_discussion }
|
|
|
|
let(:merge_request) { discussion.noteable }
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:other_merge_request) { create(:merge_request, source_project: project, source_branch: "fix") }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
describe "#merge_request_for_resolving_discussion" do
|
|
|
|
let(:service) { DummyService.new(project, user, merge_request_to_resolve_discussions_of: merge_request.iid) }
|
|
|
|
|
|
|
|
it "finds the merge request" do
|
|
|
|
expect(service.merge_request_to_resolve_discussions_of).to eq(merge_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "only queries for the merge request once" do
|
|
|
|
fake_finder = double
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
expect(fake_finder).to receive(:find_by).exactly(1)
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(MergeRequestsFinder).to receive(:new).and_return(fake_finder).exactly(1)
|
|
|
|
|
|
|
|
2.times { service.merge_request_to_resolve_discussions_of }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#discussions_to_resolve" do
|
|
|
|
it "contains a single discussion when matching merge request and discussion are passed" do
|
|
|
|
service = DummyService.new(
|
|
|
|
project,
|
|
|
|
user,
|
|
|
|
discussion_to_resolve: discussion.id,
|
|
|
|
merge_request_to_resolve_discussions_of: merge_request.iid
|
|
|
|
)
|
|
|
|
# We need to compare discussion id's because the Discussion-objects are rebuilt
|
|
|
|
# which causes the object-id's not to be different.
|
|
|
|
discussion_ids = service.discussions_to_resolve.map(&:id)
|
|
|
|
|
|
|
|
expect(discussion_ids).to contain_exactly(discussion.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "contains all discussions when only a merge request is passed" do
|
|
|
|
second_discussion = Discussion.new([create(:diff_note_on_merge_request,
|
|
|
|
noteable: merge_request,
|
|
|
|
project: merge_request.target_project,
|
|
|
|
line_number: 15)])
|
|
|
|
service = DummyService.new(
|
|
|
|
project,
|
|
|
|
user,
|
|
|
|
merge_request_to_resolve_discussions_of: merge_request.iid
|
|
|
|
)
|
|
|
|
# We need to compare discussion id's because the Discussion-objects are rebuilt
|
|
|
|
# which causes the object-id's not to be different.
|
|
|
|
discussion_ids = service.discussions_to_resolve.map(&:id)
|
|
|
|
|
|
|
|
expect(discussion_ids).to contain_exactly(discussion.id, second_discussion.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "contains only unresolved discussions" do
|
|
|
|
_second_discussion = Discussion.new([create(:diff_note_on_merge_request, :resolved,
|
|
|
|
noteable: merge_request,
|
|
|
|
project: merge_request.target_project,
|
2017-09-10 17:25:29 +05:30
|
|
|
line_number: 15
|
2017-08-17 22:00:37 +05:30
|
|
|
)])
|
|
|
|
service = DummyService.new(
|
|
|
|
project,
|
|
|
|
user,
|
|
|
|
merge_request_to_resolve_discussions_of: merge_request.iid
|
|
|
|
)
|
|
|
|
# We need to compare discussion id's because the Discussion-objects are rebuilt
|
|
|
|
# which causes the object-id's not to be different.
|
|
|
|
discussion_ids = service.discussions_to_resolve.map(&:id)
|
|
|
|
|
|
|
|
expect(discussion_ids).to contain_exactly(discussion.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "is empty when a discussion and another merge request are passed" do
|
|
|
|
service = DummyService.new(
|
|
|
|
project,
|
|
|
|
user,
|
|
|
|
discussion_to_resolve: discussion.id,
|
|
|
|
merge_request_to_resolve_discussions_of: other_merge_request.iid
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(service.discussions_to_resolve).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|