2016-08-12 17:24:09 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Projects::DiscussionsController do
|
2017-01-25 16:44:33 -05:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:merge_request) { create(:merge_request) }
|
|
|
|
let(:project) { merge_request.source_project }
|
2017-03-09 20:29:11 -05:00
|
|
|
let(:note) { create(:discussion_note_on_merge_request, noteable: merge_request, project: project) }
|
2016-08-15 19:45:23 -04:00
|
|
|
let(:discussion) { note.discussion }
|
|
|
|
|
|
|
|
let(:request_params) do
|
|
|
|
{
|
|
|
|
namespace_id: project.namespace,
|
|
|
|
project_id: project,
|
|
|
|
merge_request_id: merge_request,
|
|
|
|
id: note.discussion_id
|
|
|
|
}
|
|
|
|
end
|
2016-08-12 17:24:09 -04:00
|
|
|
|
2018-04-05 10:23:57 -04:00
|
|
|
describe 'GET show' do
|
|
|
|
before do
|
|
|
|
sign_in user
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is not authorized to read the MR' do
|
|
|
|
it 'returns 404' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :show, params: request_params, session: { format: :json }
|
2018-04-05 10:23:57 -04:00
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is authorized to read the MR' do
|
|
|
|
before do
|
|
|
|
project.add_reporter(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns status 200' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :show, params: request_params, session: { format: :json }
|
2018-04-05 10:23:57 -04:00
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(200)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns status 404 if MR does not exists' do
|
|
|
|
merge_request.destroy!
|
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
get :show, params: request_params, session: { format: :json }
|
2018-04-05 10:23:57 -04:00
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is authorized but note is LegacyDiffNote' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
note.update!(type: 'LegacyDiffNote')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns status 200' do
|
2018-12-17 17:52:17 -05:00
|
|
|
get :show, params: request_params, session: { format: :json }
|
2018-04-05 10:23:57 -04:00
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(200)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-12 17:24:09 -04:00
|
|
|
describe 'POST resolve' do
|
|
|
|
before do
|
|
|
|
sign_in user
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the user is not authorized to resolve the discussion" do
|
|
|
|
it "returns status 404" do
|
2018-12-17 17:52:17 -05:00
|
|
|
post :resolve, params: request_params
|
2016-08-12 17:24:09 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-08-12 17:24:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the user is authorized to resolve the discussion" do
|
|
|
|
before do
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(user)
|
2016-08-12 17:24:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when the discussion is not resolvable" do
|
|
|
|
before do
|
|
|
|
note.update(system: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns status 404" do
|
2018-12-17 17:52:17 -05:00
|
|
|
post :resolve, params: request_params
|
2016-08-12 17:24:09 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-08-12 17:24:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the discussion is resolvable" do
|
|
|
|
it "resolves the discussion" do
|
2018-12-17 17:52:17 -05:00
|
|
|
post :resolve, params: request_params
|
2016-08-12 17:24:09 -04:00
|
|
|
|
2016-08-15 19:45:23 -04:00
|
|
|
expect(note.reload.discussion.resolved?).to be true
|
|
|
|
expect(note.reload.discussion.resolved_by).to eq(user)
|
2016-08-12 17:24:09 -04:00
|
|
|
end
|
|
|
|
|
2016-08-15 19:45:23 -04:00
|
|
|
it "sends notifications if all discussions are resolved" do
|
|
|
|
expect_any_instance_of(MergeRequests::ResolvedDiscussionNotificationService).to receive(:execute).with(merge_request)
|
2016-08-12 17:24:09 -04:00
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
post :resolve, params: request_params
|
2016-08-12 17:24:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the name of the resolving user" do
|
2018-12-17 17:52:17 -05:00
|
|
|
post :resolve, params: request_params
|
2016-08-12 17:24:09 -04:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
expect(JSON.parse(response.body)['resolved_by']['name']).to eq(user.name)
|
2016-08-12 17:24:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns status 200" do
|
2018-12-17 17:52:17 -05:00
|
|
|
post :resolve, params: request_params
|
2016-08-12 17:24:09 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-08-12 17:24:09 -04:00
|
|
|
end
|
2018-02-27 19:10:43 -05:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
it "renders discussion with serializer" do
|
|
|
|
expect_any_instance_of(DiscussionSerializer).to receive(:represent)
|
|
|
|
.with(instance_of(Discussion), { context: instance_of(described_class), render_truncated_diff_lines: true })
|
2018-02-27 19:10:43 -05:00
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
post :resolve, params: request_params
|
2018-06-21 08:22:40 -04:00
|
|
|
end
|
2018-02-27 19:10:43 -05:00
|
|
|
|
2018-06-21 08:22:40 -04:00
|
|
|
context 'diff discussion' do
|
|
|
|
let(:note) { create(:diff_note_on_merge_request, noteable: merge_request, project: project) }
|
|
|
|
let(:discussion) { note.discussion }
|
|
|
|
|
|
|
|
it "returns truncated diff lines" do
|
2018-12-17 17:52:17 -05:00
|
|
|
post :resolve, params: request_params
|
2018-06-21 08:22:40 -04:00
|
|
|
|
|
|
|
expect(JSON.parse(response.body)['truncated_diff_lines']).to be_present
|
2018-02-27 19:10:43 -05:00
|
|
|
end
|
|
|
|
end
|
2016-08-12 17:24:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'DELETE unresolve' do
|
|
|
|
before do
|
|
|
|
sign_in user
|
2016-08-15 19:45:23 -04:00
|
|
|
|
|
|
|
note.discussion.resolve!(user)
|
2016-08-12 17:24:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when the user is not authorized to resolve the discussion" do
|
|
|
|
it "returns status 404" do
|
2018-12-17 17:52:17 -05:00
|
|
|
delete :unresolve, params: request_params
|
2016-08-12 17:24:09 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-08-12 17:24:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the user is authorized to resolve the discussion" do
|
|
|
|
before do
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(user)
|
2016-08-12 17:24:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when the discussion is not resolvable" do
|
|
|
|
before do
|
|
|
|
note.update(system: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns status 404" do
|
2018-12-17 17:52:17 -05:00
|
|
|
delete :unresolve, params: request_params
|
2016-08-12 17:24:09 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-08-12 17:24:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the discussion is resolvable" do
|
|
|
|
it "unresolves the discussion" do
|
2018-12-17 17:52:17 -05:00
|
|
|
delete :unresolve, params: request_params
|
2016-08-12 17:24:09 -04:00
|
|
|
|
2016-08-15 19:45:23 -04:00
|
|
|
expect(note.reload.discussion.resolved?).to be false
|
2016-08-12 17:24:09 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns status 200" do
|
2018-12-17 17:52:17 -05:00
|
|
|
delete :unresolve, params: request_params
|
2016-08-12 17:24:09 -04:00
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-08-12 17:24:09 -04:00
|
|
|
end
|
2018-02-27 19:10:43 -05:00
|
|
|
|
|
|
|
context "when vue_mr_discussions cookie is present" do
|
|
|
|
before do
|
|
|
|
allow(controller).to receive(:cookies).and_return({ vue_mr_discussions: 'true' })
|
|
|
|
end
|
|
|
|
|
|
|
|
it "renders discussion with serializer" do
|
|
|
|
expect_any_instance_of(DiscussionSerializer).to receive(:represent)
|
2018-06-21 08:22:40 -04:00
|
|
|
.with(instance_of(Discussion), { context: instance_of(described_class), render_truncated_diff_lines: true })
|
2018-02-27 19:10:43 -05:00
|
|
|
|
2018-12-17 17:52:17 -05:00
|
|
|
delete :unresolve, params: request_params
|
2018-02-27 19:10:43 -05:00
|
|
|
end
|
|
|
|
end
|
2016-08-12 17:24:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|