1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::DiscussionsController do
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) }
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
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
get :show, params: request_params, session: { format: :json }
expect(response).to have_gitlab_http_status(:not_found)
end
end
context 'when user is authorized to read the MR' do
before do
project.add_reporter(user)
end
it 'returns status 200' do
get :show, params: request_params, session: { format: :json }
expect(response).to have_gitlab_http_status(:ok)
end
it 'returns status 404 if MR does not exists' do
merge_request.destroy!
get :show, params: request_params, session: { format: :json }
expect(response).to have_gitlab_http_status(:not_found)
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
get :show, params: request_params, session: { format: :json }
expect(response).to have_gitlab_http_status(:ok)
end
end
end
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
post :resolve, params: request_params
expect(response).to have_gitlab_http_status(:not_found)
end
end
context "when the user is authorized to resolve the discussion" do
before do
project.add_developer(user)
end
context "when the discussion is not resolvable" do
before do
note.update(system: true)
end
it "returns status 404" do
post :resolve, params: request_params
expect(response).to have_gitlab_http_status(:not_found)
end
end
context "when the discussion is resolvable" do
it "resolves the discussion" do
post :resolve, params: request_params
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
expect_next_instance_of(MergeRequests::ResolvedDiscussionNotificationService) do |instance|
expect(instance).to receive(:execute).with(merge_request)
end
post :resolve, params: request_params
end
it "returns the name of the resolving user" do
post :resolve, params: request_params
expect(json_response['resolved_by']['name']).to eq(user.name)
end
it "returns status 200" do
post :resolve, params: request_params
expect(response).to have_gitlab_http_status(:ok)
end
it "renders discussion with serializer" do
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
post :resolve, params: request_params
end
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
post :resolve, params: request_params
expect(json_response['truncated_diff_lines']).to be_present
end
end
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
delete :unresolve, params: request_params
expect(response).to have_gitlab_http_status(:not_found)
end
end
context "when the user is authorized to resolve the discussion" do
before do
project.add_developer(user)
end
context "when the discussion is not resolvable" do
before do
note.update(system: true)
end
it "returns status 404" do
delete :unresolve, params: request_params
expect(response).to have_gitlab_http_status(:not_found)
end
end
context "when the discussion is resolvable" do
it "unresolves the discussion" do
delete :unresolve, params: request_params
expect(note.reload.discussion.resolved?).to be false
end
it "returns status 200" do
delete :unresolve, params: request_params
expect(response).to have_gitlab_http_status(:ok)
end
context "when vue_mr_discussions cookie is present" do
before do
cookies[:vue_mr_discussions] = 'true'
end
it "renders discussion with serializer" do
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
delete :unresolve, params: request_params
end
end
end
end
end
end
|