debian-mirror-gitlab/spec/controllers/projects/discussions_controller_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

220 lines
6.2 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
require 'spec_helper'
2020-06-23 00:09:42 +05:30
RSpec.describe Projects::DiscussionsController do
2017-08-17 22:00:37 +05:30
let(:user) { create(:user) }
let(:merge_request) { create(:merge_request) }
let(:project) { merge_request.source_project }
let(:note) { create(:discussion_note_on_merge_request, noteable: merge_request, project: project) }
2016-09-13 17:45:13 +05:30
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
2018-05-09 12:01:36 +05:30
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
2019-02-15 15:39:39 +05:30
get :show, params: request_params, session: { format: :json }
2018-05-09 12:01:36 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2018-05-09 12:01:36 +05:30
end
end
context 'when user is authorized to read the MR' do
before do
project.add_reporter(user)
end
it 'returns status 200' do
2019-02-15 15:39:39 +05:30
get :show, params: request_params, session: { format: :json }
2018-05-09 12:01:36 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:ok)
2018-05-09 12:01:36 +05:30
end
it 'returns status 404 if MR does not exists' do
merge_request.destroy!
2019-02-15 15:39:39 +05:30
get :show, params: request_params, session: { format: :json }
2018-05-09 12:01:36 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2018-05-09 12:01:36 +05:30
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
2019-02-15 15:39:39 +05:30
get :show, params: request_params, session: { format: :json }
2018-05-09 12:01:36 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:ok)
2018-05-09 12:01:36 +05:30
end
end
end
2016-09-13 17:45:13 +05:30
describe 'POST resolve' do
before do
sign_in user
end
2016-09-29 09:46:39 +05:30
context "when the user is not authorized to resolve the discussion" do
2016-09-13 17:45:13 +05:30
it "returns status 404" do
2019-02-15 15:39:39 +05:30
post :resolve, params: request_params
2016-09-13 17:45:13 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2016-09-13 17:45:13 +05:30
end
end
context "when the user is authorized to resolve the discussion" do
before do
2018-03-17 18:26:18 +05:30
project.add_developer(user)
2016-09-13 17:45:13 +05:30
end
context "when the discussion is not resolvable" do
before do
2021-04-29 21:17:54 +05:30
note.update!(system: true)
2016-09-13 17:45:13 +05:30
end
it "returns status 404" do
2019-02-15 15:39:39 +05:30
post :resolve, params: request_params
2016-09-13 17:45:13 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2016-09-13 17:45:13 +05:30
end
end
context "when the discussion is resolvable" do
it "resolves the discussion" do
2019-02-15 15:39:39 +05:30
post :resolve, params: request_params
2016-09-13 17:45:13 +05:30
expect(note.reload.discussion.resolved?).to be true
expect(note.reload.discussion.resolved_by).to eq(user)
end
it "sends notifications if all discussions are resolved" do
2019-12-26 22:10:19 +05:30
expect_next_instance_of(MergeRequests::ResolvedDiscussionNotificationService) do |instance|
expect(instance).to receive(:execute).with(merge_request)
end
2016-09-13 17:45:13 +05:30
2019-02-15 15:39:39 +05:30
post :resolve, params: request_params
2016-09-13 17:45:13 +05:30
end
it "returns the name of the resolving user" do
2019-02-15 15:39:39 +05:30
post :resolve, params: request_params
2016-09-13 17:45:13 +05:30
2019-09-30 21:07:59 +05:30
expect(json_response['resolved_by']['name']).to eq(user.name)
2016-09-13 17:45:13 +05:30
end
it "returns status 200" do
2019-02-15 15:39:39 +05:30
post :resolve, params: request_params
2016-09-13 17:45:13 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:ok)
2016-09-13 17:45:13 +05:30
end
2018-03-27 19:54:05 +05:30
2018-11-08 19:23:39 +05:30
it "renders discussion with serializer" do
2019-12-26 22:10:19 +05:30
expect_next_instance_of(DiscussionSerializer) do |instance|
expect(instance).to receive(:represent)
.with(instance_of(Discussion), { context: instance_of(described_class), render_truncated_diff_lines: true })
end
2018-03-27 19:54:05 +05:30
2019-02-15 15:39:39 +05:30
post :resolve, params: request_params
2018-11-08 19:23:39 +05:30
end
2018-03-27 19:54:05 +05:30
2018-11-08 19:23:39 +05:30
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
2019-02-15 15:39:39 +05:30
post :resolve, params: request_params
2018-11-08 19:23:39 +05:30
2019-09-30 21:07:59 +05:30
expect(json_response['truncated_diff_lines']).to be_present
2018-03-27 19:54:05 +05:30
end
end
2016-09-13 17:45:13 +05:30
end
end
end
describe 'DELETE unresolve' do
before do
sign_in user
note.discussion.resolve!(user)
end
context "when the user is not authorized to resolve the discussion" do
it "returns status 404" do
2019-02-15 15:39:39 +05:30
delete :unresolve, params: request_params
2016-09-13 17:45:13 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2016-09-13 17:45:13 +05:30
end
end
context "when the user is authorized to resolve the discussion" do
before do
2018-03-17 18:26:18 +05:30
project.add_developer(user)
2016-09-13 17:45:13 +05:30
end
context "when the discussion is not resolvable" do
before do
2021-04-29 21:17:54 +05:30
note.update!(system: true)
2016-09-13 17:45:13 +05:30
end
it "returns status 404" do
2019-02-15 15:39:39 +05:30
delete :unresolve, params: request_params
2016-09-13 17:45:13 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2016-09-13 17:45:13 +05:30
end
end
context "when the discussion is resolvable" do
it "unresolves the discussion" do
2019-02-15 15:39:39 +05:30
delete :unresolve, params: request_params
2016-09-13 17:45:13 +05:30
2020-07-28 23:09:34 +05:30
# discussion is memoized and reload doesn't clear the memoization
expect(Note.find(note.id).discussion.resolved?).to be false
2016-09-13 17:45:13 +05:30
end
2021-03-11 19:13:27 +05:30
it "tracks thread unresolve usage data" do
expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter)
.to receive(:track_unresolve_thread_action).with(user: user)
delete :unresolve, params: request_params
end
2016-09-13 17:45:13 +05:30
it "returns status 200" do
2019-02-15 15:39:39 +05:30
delete :unresolve, params: request_params
2016-09-13 17:45:13 +05:30
2020-03-13 15:44:24 +05:30
expect(response).to have_gitlab_http_status(:ok)
2016-09-13 17:45:13 +05:30
end
2018-03-27 19:54:05 +05:30
context "when vue_mr_discussions cookie is present" do
before do
2019-12-21 20:55:43 +05:30
cookies[:vue_mr_discussions] = 'true'
2018-03-27 19:54:05 +05:30
end
it "renders discussion with serializer" do
2019-12-26 22:10:19 +05:30
expect_next_instance_of(DiscussionSerializer) do |instance|
expect(instance).to receive(:represent)
.with(instance_of(Discussion), { context: instance_of(described_class), render_truncated_diff_lines: true })
end
2018-03-27 19:54:05 +05:30
2019-02-15 15:39:39 +05:30
delete :unresolve, params: request_params
2018-03-27 19:54:05 +05:30
end
end
2016-09-13 17:45:13 +05:30
end
end
end
end