2019-04-11 08:17:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-12-22 07:31:12 -05:00
|
|
|
require 'spec_helper.rb'
|
|
|
|
|
2020-06-24 11:08:50 -04:00
|
|
|
RSpec.describe Issues::ResolveDiscussions do
|
2017-03-27 17:14:01 -04:00
|
|
|
let(:project) { create(:project, :repository) }
|
2016-12-22 07:31:12 -05:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
2020-05-19 11:08:04 -04:00
|
|
|
stub_const('DummyService', Class.new(Issues::BaseService))
|
|
|
|
DummyService.class_eval do
|
|
|
|
include ::Issues::ResolveDiscussions
|
|
|
|
|
|
|
|
def initialize(*args)
|
|
|
|
super
|
|
|
|
filter_resolve_discussion_params
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(user)
|
2016-12-22 07:31:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "for resolving discussions" do
|
2017-03-17 15:25:52 -04:00
|
|
|
let(:discussion) { create(:diff_note_on_merge_request, project: project, note: "Almost done").to_discussion }
|
2016-12-22 07:31:12 -05:00
|
|
|
let(:merge_request) { discussion.noteable }
|
2017-08-09 09:41:45 -04:00
|
|
|
let(:other_merge_request) { create(:merge_request, source_project: project, source_branch: "fix") }
|
2016-12-22 07:31:12 -05:00
|
|
|
|
2017-03-09 05:38:53 -05:00
|
|
|
describe "#merge_request_for_resolving_discussion" do
|
2017-04-25 08:28:55 -04:00
|
|
|
let(:service) { DummyService.new(project, user, merge_request_to_resolve_discussions_of: merge_request.iid) }
|
2017-03-09 05:38:53 -05:00
|
|
|
|
|
|
|
it "finds the merge request" do
|
2017-03-10 03:19:12 -05:00
|
|
|
expect(service.merge_request_to_resolve_discussions_of).to eq(merge_request)
|
2017-03-09 05:38:53 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "only queries for the merge request once" do
|
|
|
|
fake_finder = double
|
|
|
|
|
2018-06-18 04:31:41 -04:00
|
|
|
expect(fake_finder).to receive(:find_by).exactly(1)
|
2017-03-09 05:38:53 -05:00
|
|
|
expect(MergeRequestsFinder).to receive(:new).and_return(fake_finder).exactly(1)
|
|
|
|
|
2017-03-10 03:19:12 -05:00
|
|
|
2.times { service.merge_request_to_resolve_discussions_of }
|
2017-03-09 05:38:53 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-12-22 07:31:12 -05:00
|
|
|
describe "#discussions_to_resolve" do
|
2017-02-27 04:23:36 -05:00
|
|
|
it "contains a single discussion when matching merge request and discussion are passed" do
|
2017-04-25 08:28:55 -04:00
|
|
|
service = DummyService.new(
|
2016-12-22 07:31:12 -05:00
|
|
|
project,
|
|
|
|
user,
|
2017-02-27 04:23:36 -05:00
|
|
|
discussion_to_resolve: discussion.id,
|
2017-03-10 03:19:12 -05:00
|
|
|
merge_request_to_resolve_discussions_of: merge_request.iid
|
2016-12-22 07:31:12 -05:00
|
|
|
)
|
2017-02-27 04:23:36 -05:00
|
|
|
# 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)
|
2016-12-22 07:31:12 -05:00
|
|
|
|
2017-02-27 04:23:36 -05:00
|
|
|
expect(discussion_ids).to contain_exactly(discussion.id)
|
2016-12-22 07:31:12 -05:00
|
|
|
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)])
|
2017-04-25 08:28:55 -04:00
|
|
|
service = DummyService.new(
|
2016-12-22 07:31:12 -05:00
|
|
|
project,
|
|
|
|
user,
|
2017-03-10 03:19:12 -05:00
|
|
|
merge_request_to_resolve_discussions_of: merge_request.iid
|
2016-12-22 07:31:12 -05:00
|
|
|
)
|
|
|
|
# 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
|
|
|
|
|
2017-02-27 04:23:36 -05:00
|
|
|
it "contains only unresolved discussions" do
|
2017-02-27 12:12:52 -05:00
|
|
|
_second_discussion = Discussion.new([create(:diff_note_on_merge_request, :resolved,
|
2017-02-27 04:23:36 -05:00
|
|
|
noteable: merge_request,
|
|
|
|
project: merge_request.target_project,
|
2017-05-03 07:27:17 -04:00
|
|
|
line_number: 15
|
2020-09-02 08:10:35 -04:00
|
|
|
)])
|
2017-04-25 08:28:55 -04:00
|
|
|
service = DummyService.new(
|
2017-02-27 04:23:36 -05:00
|
|
|
project,
|
|
|
|
user,
|
2017-03-10 03:19:12 -05:00
|
|
|
merge_request_to_resolve_discussions_of: merge_request.iid
|
2017-02-27 04:23:36 -05:00
|
|
|
)
|
|
|
|
# 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
|
|
|
|
|
2016-12-22 07:31:12 -05:00
|
|
|
it "is empty when a discussion and another merge request are passed" do
|
2017-04-25 08:28:55 -04:00
|
|
|
service = DummyService.new(
|
2016-12-22 07:31:12 -05:00
|
|
|
project,
|
|
|
|
user,
|
2017-02-27 04:23:36 -05:00
|
|
|
discussion_to_resolve: discussion.id,
|
2017-03-10 03:19:12 -05:00
|
|
|
merge_request_to_resolve_discussions_of: other_merge_request.iid
|
2016-12-22 07:31:12 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
expect(service.discussions_to_resolve).to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|