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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
# frozen_string_literal: true
require 'spec_helper'
RSpec
.describe(
Projects::MergeRequestsController,
'(JavaScript fixtures)',
type: :controller,
feature_category: :code_review_workflow
) do
include JavaScriptFixturesHelpers
let(:namespace) { create(:namespace, name: 'frontend-fixtures') }
let(:project) { create(:project, :repository, namespace: namespace, path: 'merge-requests-project') }
let(:user) { project.first_owner }
# rubocop: disable Layout/TrailingWhitespace
let(:description) do
<<~MARKDOWN.strip_heredoc
- [ ] Task List Item
- [ ]
- [ ] Task List Item 2
MARKDOWN
end
# rubocop: enable Layout/TrailingWhitespace
let(:merge_request) do
create(
:merge_request,
source_project: project,
target_project: project,
description: description
)
end
let(:merged_merge_request) { create(:merge_request, :merged, source_project: project, target_project: project) }
let(:pipeline) do
create(
:ci_pipeline,
project: merge_request.source_project,
ref: merge_request.source_branch,
sha: merge_request.diff_head_sha
)
end
let(:path) { "files/ruby/popen.rb" }
let(:position) do
build(:text_diff_position, :added,
file: path,
new_line: 14,
diff_refs: merge_request.diff_refs
)
end
render_views
before do
sign_in(user)
allow(Discussion).to receive(:build_discussion_id).and_return(['discussionid:ceterumcenseo'])
end
after do
remove_repository(project)
end
it 'merge_requests/merge_request_with_single_assignee_feature.html' do
stub_licensed_features(multiple_merge_request_assignees: false)
render_merge_request(merge_request)
end
it 'merge_requests/merge_request_of_current_user.html' do
merge_request.update!(author: user)
render_merge_request(merge_request)
end
it 'merge_requests/merge_request_with_task_list.html' do
create(:ci_build, :pending, pipeline: pipeline)
render_merge_request(merge_request)
end
it 'merge_requests/diff_comment.html' do
create(:diff_note_on_merge_request, project: project, author: user, position: position, noteable: merge_request)
create(:note_on_merge_request, author: user, project: project, noteable: merge_request)
render_merge_request(merge_request)
end
it 'merge_requests/diff_discussion.json' do
create(:diff_note_on_merge_request, project: project, author: user, position: position, noteable: merge_request)
render_discussions_json(merge_request)
end
it 'merge_requests/resolved_diff_discussion.json' do
note = create(:discussion_note_on_merge_request, :resolved, project: project, author: user, position: position, noteable: merge_request)
create(:system_note, project: project, author: user, noteable: merge_request, discussion_id: note.discussion.id)
render_discussions_json(merge_request)
end
context 'with image diff' do
let(:merge_request2) { create(:merge_request_with_diffs, :with_image_diffs, source_project: project, title: "Added images") }
let(:image_path) { "files/images/ee_repo_logo.png" }
let(:image_position) do
build(:image_diff_position,
file: image_path,
diff_refs: merge_request2.diff_refs
)
end
it 'merge_requests/image_diff_discussion.json' do
create(:diff_note_on_merge_request, project: project, noteable: merge_request2, position: image_position)
render_discussions_json(merge_request2)
end
end
context 'with mentions' do
let(:group) { create(:group) }
let(:description) { "@#{group.full_path} @all @#{user.username}" }
before do
stub_feature_flags(disable_all_mention: false)
end
it 'merge_requests/merge_request_with_mentions.html' do
render_merge_request(merge_request)
end
end
it 'merge_requests/merge_request_list.html' do
create(:merge_request, source_project: project, target_project: project)
get :index, params: {
namespace_id: project.namespace.to_param,
project_id: project
}
expect(response).to be_successful
end
describe GraphQL::Query, type: :request do
include ApiHelpers
include GraphqlHelpers
context 'merge request in state readyToMerge query' do
base_input_path = 'vue_merge_request_widget/queries/states/'
base_output_path = 'graphql/merge_requests/states/'
query_name = 'ready_to_merge.query.graphql'
it "#{base_output_path}#{query_name}.json" do
query = get_graphql_query_as_string("#{base_input_path}#{query_name}", ee: Gitlab.ee?)
post_graphql(query, current_user: user, variables: { projectPath: project.full_path, iid: merge_request.iid.to_s })
expect_graphql_errors_to_be_empty
end
end
context 'merge request with no approvals' do
base_input_path = 'vue_merge_request_widget/components/approvals/queries/'
base_output_path = 'graphql/merge_requests/approvals/'
query_name = 'approvals.query.graphql'
it "#{base_output_path}#{query_name}_no_approvals.json" do
query = get_graphql_query_as_string("#{base_input_path}#{query_name}", ee: Gitlab.ee?)
post_graphql(query, current_user: user, variables: { projectPath: project.full_path, iid: merge_request.iid.to_s })
expect_graphql_errors_to_be_empty
end
end
context 'merge request approved by current user' do
base_input_path = 'vue_merge_request_widget/components/approvals/queries/'
base_output_path = 'graphql/merge_requests/approvals/'
query_name = 'approvals.query.graphql'
it "#{base_output_path}#{query_name}.json" do
merge_request.approved_by_users << user
query = get_graphql_query_as_string("#{base_input_path}#{query_name}", ee: Gitlab.ee?)
post_graphql(query, current_user: user, variables: { projectPath: project.full_path, iid: merge_request.iid.to_s })
expect_graphql_errors_to_be_empty
end
end
context 'merge request approved by multiple users' do
base_input_path = 'vue_merge_request_widget/components/approvals/queries/'
base_output_path = 'graphql/merge_requests/approvals/'
query_name = 'approvals.query.graphql'
it "#{base_output_path}#{query_name}_multiple_users.json" do
merge_request.approved_by_users << user
merge_request.approved_by_users << create(:user)
query = get_graphql_query_as_string("#{base_input_path}#{query_name}", ee: Gitlab.ee?)
post_graphql(query, current_user: user, variables: { projectPath: project.full_path, iid: merge_request.iid.to_s })
expect_graphql_errors_to_be_empty
end
end
context 'merge request in state getState query' do
base_input_path = 'vue_merge_request_widget/queries/'
base_output_path = 'graphql/merge_requests/'
query_name = 'get_state.query.graphql'
it "#{base_output_path}#{query_name}.json" do
query = get_graphql_query_as_string("#{base_input_path}#{query_name}")
post_graphql(query, current_user: user, variables: { projectPath: project.full_path, iid: merge_request.iid.to_s })
expect_graphql_errors_to_be_empty
end
end
end
private
def render_discussions_json(merge_request)
get :discussions, params: {
namespace_id: project.namespace.to_param,
project_id: project,
id: merge_request.to_param
}, format: :json
end
def render_merge_request(merge_request)
get :show, params: {
namespace_id: project.namespace.to_param,
project_id: project,
id: merge_request.to_param
}, format: :html
expect(response).to be_successful
end
end
|