Commit 70d04e11 authored by Robert Speicher's avatar Robert Speicher

Merge branch '200018-refactor-api-merge-reques-specsts' into 'master'

Refactor merge requests/issues API specs

Closes #200018

See merge request gitlab-org/gitlab!25062
parents 9c918f02 af6762f7
...@@ -212,12 +212,6 @@ describe API::MergeRequests do ...@@ -212,12 +212,6 @@ describe API::MergeRequests do
end end
context 'when authenticated' do context 'when authenticated' do
def expect_response_contain_exactly(*items)
expect(response).to have_gitlab_http_status(200)
expect(json_response.map { |element| element['id'] }).to contain_exactly(*items.map(&:id))
expect(json_response.length).to eq(items.size)
end
context 'filter merge requests by assignee ID' do context 'filter merge requests by assignee ID' do
let!(:merge_request2) do let!(:merge_request2) do
create(:merge_request, :simple, assignees: [user2], source_project: project, target_project: project, source_branch: 'other-branch-2') create(:merge_request, :simple, assignees: [user2], source_project: project, target_project: project, source_branch: 'other-branch-2')
...@@ -226,7 +220,7 @@ describe API::MergeRequests do ...@@ -226,7 +220,7 @@ describe API::MergeRequests do
it 'returns merge requests with given assignee ID' do it 'returns merge requests with given assignee ID' do
get api('/merge_requests', user), params: { assignee_id: user2.id } get api('/merge_requests', user), params: { assignee_id: user2.id }
expect_response_contain_exactly(merge_request, merge_request2) expect_paginated_array_response([merge_request2.id, merge_request.id])
end end
end end
...@@ -243,7 +237,7 @@ describe API::MergeRequests do ...@@ -243,7 +237,7 @@ describe API::MergeRequests do
let(:approvers_param) { [merge_request_with_approver.approvers.first.user_id] } let(:approvers_param) { [merge_request_with_approver.approvers.first.user_id] }
it 'returns an array of merge requests which have specified the user as an approver' do it 'returns an array of merge requests which have specified the user as an approver' do
expect_response_contain_exactly(merge_request_with_approver) expect_paginated_array_response([merge_request_with_approver.id])
end end
end end
...@@ -251,7 +245,7 @@ describe API::MergeRequests do ...@@ -251,7 +245,7 @@ describe API::MergeRequests do
let(:approvers_param) { 'None' } let(:approvers_param) { 'None' }
it 'returns an array of merge requests with no approvers' do it 'returns an array of merge requests with no approvers' do
expect_response_contain_exactly(merge_request) expect_paginated_array_response([merge_request.id])
end end
end end
...@@ -259,7 +253,7 @@ describe API::MergeRequests do ...@@ -259,7 +253,7 @@ describe API::MergeRequests do
let(:approvers_param) { 'Any' } let(:approvers_param) { 'Any' }
it 'returns an array of merge requests with any approver' do it 'returns an array of merge requests with any approver' do
expect_response_contain_exactly(merge_request_with_approver) expect_paginated_array_response([merge_request_with_approver.id])
end end
end end
...@@ -288,7 +282,7 @@ describe API::MergeRequests do ...@@ -288,7 +282,7 @@ describe API::MergeRequests do
let(:approvals_param) { [user2.id] } let(:approvals_param) { [user2.id] }
it 'returns an array of merge requests which have specified the user as an approver' do it 'returns an array of merge requests which have specified the user as an approver' do
expect_response_contain_exactly(merge_request_with_approval) expect_paginated_array_response([merge_request_with_approval.id])
end end
end end
...@@ -296,7 +290,7 @@ describe API::MergeRequests do ...@@ -296,7 +290,7 @@ describe API::MergeRequests do
let(:approvals_param) { 'None' } let(:approvals_param) { 'None' }
it 'returns an array of merge requests with no approvers' do it 'returns an array of merge requests with no approvers' do
expect_response_contain_exactly(merge_request) expect_paginated_array_response([merge_request.id])
end end
end end
...@@ -304,7 +298,7 @@ describe API::MergeRequests do ...@@ -304,7 +298,7 @@ describe API::MergeRequests do
let(:approvals_param) { 'Any' } let(:approvals_param) { 'Any' }
it 'returns an array of merge requests with any approver' do it 'returns an array of merge requests with any approver' do
expect_response_contain_exactly(merge_request_with_approval) expect_paginated_array_response([merge_request_with_approval.id])
end end
end end
......
...@@ -795,13 +795,13 @@ describe API::Issues do ...@@ -795,13 +795,13 @@ describe API::Issues do
it 'returns issues from non archived projects only by default' do it 'returns issues from non archived projects only by default' do
get api("/groups/#{group1.id}/issues", user), params: { scope: 'all' } get api("/groups/#{group1.id}/issues", user), params: { scope: 'all' }
expect_response_contain_exactly(issue2, issue1) expect_paginated_array_response([issue2.id, issue1.id])
end end
it 'returns issues from archived and non archived projects when non_archived is false' do it 'returns issues from archived and non archived projects when non_archived is false' do
get api("/groups/#{group1.id}/issues", user), params: { non_archived: false, scope: 'all' } get api("/groups/#{group1.id}/issues", user), params: { non_archived: false, scope: 'all' }
expect_response_contain_exactly(issue1, issue2, issue3) expect_paginated_array_response([issue3.id, issue2.id, issue1.id])
end end
end end
end end
...@@ -888,9 +888,4 @@ describe API::Issues do ...@@ -888,9 +888,4 @@ describe API::Issues do
include_examples 'time tracking endpoints', 'issue' include_examples 'time tracking endpoints', 'issue'
end end
def expect_response_contain_exactly(*items)
expect(json_response.length).to eq(items.size)
expect(json_response.map { |element| element['id'] }).to contain_exactly(*items.map(&:id))
end
end end
...@@ -41,8 +41,7 @@ describe API::MergeRequests do ...@@ -41,8 +41,7 @@ describe API::MergeRequests do
it 'returns merge requests for public projects' do it 'returns merge requests for public projects' do
get api(endpoint_path) get api(endpoint_path)
expect(response).to have_gitlab_http_status(200) expect_successful_response_with_paginated_array
expect(json_response).to be_an Array
end end
end end
...@@ -87,10 +86,11 @@ describe API::MergeRequests do ...@@ -87,10 +86,11 @@ describe API::MergeRequests do
it 'returns an array of all merge_requests' do it 'returns an array of all merge_requests' do
get api(endpoint_path, user) get api(endpoint_path, user)
expect(response).to have_gitlab_http_status(200) expect_paginated_array_response([
expect(response).to include_pagination_headers merge_request_merged.id, merge_request_locked.id,
expect(json_response).to be_an Array merge_request_closed.id, merge_request.id
expect(json_response.length).to eq(4) ])
expect(json_response.last['title']).to eq(merge_request.title) expect(json_response.last['title']).to eq(merge_request.title)
expect(json_response.last).to have_key('web_url') expect(json_response.last).to have_key('web_url')
expect(json_response.last['sha']).to eq(merge_request.diff_head_sha) expect(json_response.last['sha']).to eq(merge_request.diff_head_sha)
...@@ -111,7 +111,7 @@ describe API::MergeRequests do ...@@ -111,7 +111,7 @@ describe API::MergeRequests do
get api(path, user) get api(path, user)
expect(response).to have_gitlab_http_status(200) expect_successful_response_with_paginated_array
expect(json_response.last['labels'].pluck('name')).to eq([label2.title, label.title]) expect(json_response.last['labels'].pluck('name')).to eq([label2.title, label.title])
expect(json_response.last['labels'].first).to match_schema('/public_api/v4/label_basic') expect(json_response.last['labels'].first).to match_schema('/public_api/v4/label_basic')
end end
...@@ -139,11 +139,11 @@ describe API::MergeRequests do ...@@ -139,11 +139,11 @@ describe API::MergeRequests do
get api(path, user) get api(path, user)
expect(response).to have_gitlab_http_status(200) expect_paginated_array_response([
expect(response).to include_pagination_headers merge_request_merged.id, merge_request_locked.id,
merge_request_closed.id, merge_request.id
])
expect(json_response.last.keys).to match_array(%w(id iid title web_url created_at description project_id state updated_at)) expect(json_response.last.keys).to match_array(%w(id iid title web_url created_at description project_id state updated_at))
expect(json_response).to be_an Array
expect(json_response.length).to eq(4)
expect(json_response.last['iid']).to eq(merge_request.iid) expect(json_response.last['iid']).to eq(merge_request.iid)
expect(json_response.last['title']).to eq(merge_request.title) expect(json_response.last['title']).to eq(merge_request.title)
expect(json_response.last).to have_key('web_url') expect(json_response.last).to have_key('web_url')
...@@ -157,10 +157,10 @@ describe API::MergeRequests do ...@@ -157,10 +157,10 @@ describe API::MergeRequests do
get api(path, user) get api(path, user)
expect(response).to have_gitlab_http_status(200) expect_paginated_array_response([
expect(response).to include_pagination_headers merge_request_merged.id, merge_request_locked.id,
expect(json_response).to be_an Array merge_request_closed.id, merge_request.id
expect(json_response.length).to eq(4) ])
expect(json_response.last['title']).to eq(merge_request.title) expect(json_response.last['title']).to eq(merge_request.title)
end end
...@@ -169,10 +169,7 @@ describe API::MergeRequests do ...@@ -169,10 +169,7 @@ describe API::MergeRequests do
get api(path, user) get api(path, user)
expect(response).to have_gitlab_http_status(200) expect_paginated_array_response([merge_request.id])
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.length).to eq(1)
expect(json_response.last['title']).to eq(merge_request.title) expect(json_response.last['title']).to eq(merge_request.title)
end end
...@@ -181,10 +178,7 @@ describe API::MergeRequests do ...@@ -181,10 +178,7 @@ describe API::MergeRequests do
get api(path, user) get api(path, user)
expect(response).to have_gitlab_http_status(200) expect_paginated_array_response([merge_request_closed.id])
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.length).to eq(1)
expect(json_response.first['title']).to eq(merge_request_closed.title) expect(json_response.first['title']).to eq(merge_request_closed.title)
end end
...@@ -193,10 +187,7 @@ describe API::MergeRequests do ...@@ -193,10 +187,7 @@ describe API::MergeRequests do
get api(path, user) get api(path, user)
expect(response).to have_gitlab_http_status(200) expect_paginated_array_response([merge_request_merged.id])
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.length).to eq(1)
expect(json_response.first['title']).to eq(merge_request_merged.title) expect(json_response.first['title']).to eq(merge_request_merged.title)
end end
...@@ -210,17 +201,13 @@ describe API::MergeRequests do ...@@ -210,17 +201,13 @@ describe API::MergeRequests do
it 'returns an empty array if no issue matches milestone' do it 'returns an empty array if no issue matches milestone' do
get api(endpoint_path, user), params: { milestone: '1.0.0' } get api(endpoint_path, user), params: { milestone: '1.0.0' }
expect(response).to have_gitlab_http_status(200) expect_empty_array_response
expect(json_response).to be_an Array
expect(json_response.length).to eq(0)
end end
it 'returns an empty array if milestone does not exist' do it 'returns an empty array if milestone does not exist' do
get api(endpoint_path, user), params: { milestone: 'foo' } get api(endpoint_path, user), params: { milestone: 'foo' }
expect(response).to have_gitlab_http_status(200) expect_empty_array_response
expect(json_response).to be_an Array
expect(json_response.length).to eq(0)
end end
it 'returns an array of merge requests in given milestone' do it 'returns an array of merge requests in given milestone' do
...@@ -234,9 +221,7 @@ describe API::MergeRequests do ...@@ -234,9 +221,7 @@ describe API::MergeRequests do
it 'returns an array of merge requests matching state in milestone' do it 'returns an array of merge requests matching state in milestone' do
get api(endpoint_path, user), params: { milestone: '0.9', state: 'closed' } get api(endpoint_path, user), params: { milestone: '0.9', state: 'closed' }
expect(response).to have_gitlab_http_status(200) expect_paginated_array_response([merge_request_closed.id])
expect(json_response).to be_an Array
expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(merge_request_closed.id) expect(json_response.first['id']).to eq(merge_request_closed.id)
end end
...@@ -248,8 +233,7 @@ describe API::MergeRequests do ...@@ -248,8 +233,7 @@ describe API::MergeRequests do
get api(path, user) get api(path, user)
expect(response).to have_gitlab_http_status(200) expect_successful_response_with_paginated_array
expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['labels']).to eq([label2.title, label.title]) expect(json_response.first['labels']).to eq([label2.title, label.title])
end end
...@@ -259,9 +243,7 @@ describe API::MergeRequests do ...@@ -259,9 +243,7 @@ describe API::MergeRequests do
get api(path, user) get api(path, user)
expect(response).to have_gitlab_http_status(200) expect_empty_array_response
expect(json_response).to be_an Array
expect(json_response.length).to eq(0)
end end
it 'returns an empty array if no merge request matches labels' do it 'returns an empty array if no merge request matches labels' do
...@@ -269,9 +251,7 @@ describe API::MergeRequests do ...@@ -269,9 +251,7 @@ describe API::MergeRequests do
get api(path, user) get api(path, user)
expect(response).to have_gitlab_http_status(200) expect_empty_array_response
expect(json_response).to be_an Array
expect(json_response.length).to eq(0)
end end
it 'returns an array of labeled merge requests where all labels match' do it 'returns an array of labeled merge requests where all labels match' do
...@@ -279,8 +259,7 @@ describe API::MergeRequests do ...@@ -279,8 +259,7 @@ describe API::MergeRequests do
get api(path, user) get api(path, user)
expect(response).to have_gitlab_http_status(200) expect_successful_response_with_paginated_array
expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['labels']).to eq([label2.title, label.title]) expect(json_response.first['labels']).to eq([label2.title, label.title])
end end
...@@ -288,8 +267,7 @@ describe API::MergeRequests do ...@@ -288,8 +267,7 @@ describe API::MergeRequests do
it 'returns an array of merge requests with any label when filtering by any label' do it 'returns an array of merge requests with any label when filtering by any label' do
get api(endpoint_path, user), params: { labels: [" #{label.title} ", " #{label2.title} "] } get api(endpoint_path, user), params: { labels: [" #{label.title} ", " #{label2.title} "] }
expect_paginated_array_response expect_successful_response_with_paginated_array
expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['labels']).to eq([label2.title, label.title]) expect(json_response.first['labels']).to eq([label2.title, label.title])
expect(json_response.first['id']).to eq(merge_request.id) expect(json_response.first['id']).to eq(merge_request.id)
...@@ -298,8 +276,7 @@ describe API::MergeRequests do ...@@ -298,8 +276,7 @@ describe API::MergeRequests do
it 'returns an array of merge requests with any label when filtering by any label' do it 'returns an array of merge requests with any label when filtering by any label' do
get api(endpoint_path, user), params: { labels: ["#{label.title} , #{label2.title}"] } get api(endpoint_path, user), params: { labels: ["#{label.title} , #{label2.title}"] }
expect_paginated_array_response expect_successful_response_with_paginated_array
expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['labels']).to eq([label2.title, label.title]) expect(json_response.first['labels']).to eq([label2.title, label.title])
expect(json_response.first['id']).to eq(merge_request.id) expect(json_response.first['id']).to eq(merge_request.id)
...@@ -308,7 +285,7 @@ describe API::MergeRequests do ...@@ -308,7 +285,7 @@ describe API::MergeRequests do
it 'returns an array of merge requests with any label when filtering by any label' do it 'returns an array of merge requests with any label when filtering by any label' do
get api(endpoint_path, user), params: { labels: IssuesFinder::FILTER_ANY } get api(endpoint_path, user), params: { labels: IssuesFinder::FILTER_ANY }
expect_paginated_array_response expect_successful_response_with_paginated_array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(merge_request.id) expect(json_response.first['id']).to eq(merge_request.id)
end end
...@@ -316,10 +293,9 @@ describe API::MergeRequests do ...@@ -316,10 +293,9 @@ describe API::MergeRequests do
it 'returns an array of merge requests without a label when filtering by no label' do it 'returns an array of merge requests without a label when filtering by no label' do
get api(endpoint_path, user), params: { labels: IssuesFinder::FILTER_NONE } get api(endpoint_path, user), params: { labels: IssuesFinder::FILTER_NONE }
response_ids = json_response.map { |merge_request| merge_request['id'] } expect_paginated_array_response([
merge_request_merged.id, merge_request_locked.id, merge_request_closed.id
expect_paginated_array_response ])
expect(response_ids).to contain_exactly(merge_request_closed.id, merge_request_merged.id, merge_request_locked.id)
end end
end end
...@@ -339,10 +315,7 @@ describe API::MergeRequests do ...@@ -339,10 +315,7 @@ describe API::MergeRequests do
get api(path, user) get api(path, user)
expect(response).to have_gitlab_http_status(200) expect_paginated_array_response([mr2.id])
expect(json_response).to be_an Array
expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(mr2.id)
end end
context 'with ordering' do context 'with ordering' do
...@@ -356,10 +329,10 @@ describe API::MergeRequests do ...@@ -356,10 +329,10 @@ describe API::MergeRequests do
get api(path, user) get api(path, user)
expect(response).to have_gitlab_http_status(200) expect_paginated_array_response([
expect(response).to include_pagination_headers merge_request_closed.id, merge_request_locked.id,
expect(json_response).to be_an Array merge_request_merged.id, merge_request.id
expect(json_response.length).to eq(4) ])
response_dates = json_response.map { |merge_request| merge_request['created_at'] } response_dates = json_response.map { |merge_request| merge_request['created_at'] }
expect(response_dates).to eq(response_dates.sort) expect(response_dates).to eq(response_dates.sort)
end end
...@@ -369,10 +342,10 @@ describe API::MergeRequests do ...@@ -369,10 +342,10 @@ describe API::MergeRequests do
get api(path, user) get api(path, user)
expect(response).to have_gitlab_http_status(200) expect_paginated_array_response([
expect(response).to include_pagination_headers merge_request.id, merge_request_merged.id,
expect(json_response).to be_an Array merge_request_locked.id, merge_request_closed.id
expect(json_response.length).to eq(4) ])
response_dates = json_response.map { |merge_request| merge_request['created_at'] } response_dates = json_response.map { |merge_request| merge_request['created_at'] }
expect(response_dates).to eq(response_dates.sort.reverse) expect(response_dates).to eq(response_dates.sort.reverse)
end end
...@@ -414,10 +387,10 @@ describe API::MergeRequests do ...@@ -414,10 +387,10 @@ describe API::MergeRequests do
get api(path, user) get api(path, user)
expect(response).to have_gitlab_http_status(200) expect_paginated_array_response([
expect(response).to include_pagination_headers merge_request.id, merge_request_locked.id,
expect(json_response).to be_an Array merge_request_merged.id, merge_request_closed.id
expect(json_response.length).to eq(4) ])
response_dates = json_response.map { |merge_request| merge_request['updated_at'] } response_dates = json_response.map { |merge_request| merge_request['updated_at'] }
expect(response_dates).to eq(response_dates.sort.reverse) expect(response_dates).to eq(response_dates.sort.reverse)
end end
...@@ -427,10 +400,10 @@ describe API::MergeRequests do ...@@ -427,10 +400,10 @@ describe API::MergeRequests do
get api(path, user) get api(path, user)
expect(response).to have_gitlab_http_status(200) expect_paginated_array_response([
expect(response).to include_pagination_headers merge_request_closed.id, merge_request_locked.id,
expect(json_response).to be_an Array merge_request_merged.id, merge_request.id
expect(json_response.length).to eq(4) ])
response_dates = json_response.map { |merge_request| merge_request['created_at'] } response_dates = json_response.map { |merge_request| merge_request['created_at'] }
expect(response_dates).to eq(response_dates.sort) expect(response_dates).to eq(response_dates.sort)
end end
...@@ -440,7 +413,9 @@ describe API::MergeRequests do ...@@ -440,7 +413,9 @@ describe API::MergeRequests do
it 'returns merge requests with the given source branch' do it 'returns merge requests with the given source branch' do
get api(endpoint_path, user), params: { source_branch: merge_request_closed.source_branch, state: 'all' } get api(endpoint_path, user), params: { source_branch: merge_request_closed.source_branch, state: 'all' }
expect_response_contain_exactly(merge_request_closed, merge_request_merged, merge_request_locked) expect_paginated_array_response([
merge_request_merged.id, merge_request_locked.id, merge_request_closed.id
])
end end
end end
...@@ -448,7 +423,9 @@ describe API::MergeRequests do ...@@ -448,7 +423,9 @@ describe API::MergeRequests do
it 'returns merge requests with the given target branch' do it 'returns merge requests with the given target branch' do
get api(endpoint_path, user), params: { target_branch: merge_request_closed.target_branch, state: 'all' } get api(endpoint_path, user), params: { target_branch: merge_request_closed.target_branch, state: 'all' }
expect_response_contain_exactly(merge_request_closed, merge_request_merged, merge_request_locked) expect_paginated_array_response([
merge_request_merged.id, merge_request_locked.id, merge_request_closed.id
])
end end
end end
end end
...@@ -471,7 +448,10 @@ describe API::MergeRequests do ...@@ -471,7 +448,10 @@ describe API::MergeRequests do
it 'returns an array of all merge requests' do it 'returns an array of all merge requests' do
get api('/merge_requests', user), params: { scope: 'all' } get api('/merge_requests', user), params: { scope: 'all' }
expect_paginated_array_response expect_paginated_array_response([
merge_request_merged.id, merge_request_locked.id,
merge_request_closed.id, merge_request.id
])
end end
it "returns authentication error without any scope" do it "returns authentication error without any scope" do
...@@ -507,30 +487,23 @@ describe API::MergeRequests do ...@@ -507,30 +487,23 @@ describe API::MergeRequests do
it 'returns an array of all merge requests except unauthorized ones' do it 'returns an array of all merge requests except unauthorized ones' do
get api('/merge_requests', user), params: { scope: :all } get api('/merge_requests', user), params: { scope: :all }
expect(response).to have_gitlab_http_status(200) expect_paginated_array_response([
expect(response).to include_pagination_headers merge_request_merged.id, merge_request2.id, merge_request_locked.id, merge_request_closed.id, merge_request.id
expect(json_response).to be_an Array ])
expect(json_response.map { |mr| mr['id'] })
.to contain_exactly(merge_request.id, merge_request_closed.id, merge_request_merged.id, merge_request_locked.id, merge_request2.id)
end end
it "returns an array of no merge_requests when wip=yes" do it "returns an array of no merge_requests when wip=yes" do
get api("/merge_requests", user), params: { wip: 'yes' } get api("/merge_requests", user), params: { wip: 'yes' }
expect(response).to have_gitlab_http_status(200) expect_empty_array_response
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.length).to eq(0)
end end
it "returns an array of no merge_requests when wip=no" do it "returns an array of no merge_requests when wip=no" do
get api("/merge_requests", user), params: { wip: 'no' } get api("/merge_requests", user), params: { wip: 'no' }
expect(response).to have_gitlab_http_status(200) expect_paginated_array_response([
expect(response).to include_pagination_headers merge_request_merged.id, merge_request2.id, merge_request_locked.id, merge_request_closed.id, merge_request.id
expect(json_response).to be_an Array ])
expect(json_response.map { |mr| mr['id'] })
.to contain_exactly(merge_request.id, merge_request_closed.id, merge_request_merged.id, merge_request_locked.id, merge_request2.id)
end end
it 'does not return unauthorized merge requests' do it 'does not return unauthorized merge requests' do
...@@ -539,7 +512,9 @@ describe API::MergeRequests do ...@@ -539,7 +512,9 @@ describe API::MergeRequests do
get api('/merge_requests', user), params: { scope: :all } get api('/merge_requests', user), params: { scope: :all }
expect_response_contain_exactly(merge_request2, merge_request_merged, merge_request_closed, merge_request, merge_request_locked) expect_paginated_array_response([
merge_request_merged.id, merge_request2.id, merge_request_locked.id, merge_request_closed.id, merge_request.id
])
expect(json_response.map { |mr| mr['id'] }).not_to include(merge_request3.id) expect(json_response.map { |mr| mr['id'] }).not_to include(merge_request3.id)
end end
...@@ -548,7 +523,7 @@ describe API::MergeRequests do ...@@ -548,7 +523,7 @@ describe API::MergeRequests do
get api('/merge_requests', user2) get api('/merge_requests', user2)
expect_response_ordered_exactly(merge_request3) expect_paginated_array_response([merge_request3.id])
end end
it 'returns an array of merge requests authored by the given user' do it 'returns an array of merge requests authored by the given user' do
...@@ -556,7 +531,7 @@ describe API::MergeRequests do ...@@ -556,7 +531,7 @@ describe API::MergeRequests do
get api('/merge_requests', user), params: { author_id: user2.id, scope: :all } get api('/merge_requests', user), params: { author_id: user2.id, scope: :all }
expect_response_ordered_exactly(merge_request3) expect_paginated_array_response([merge_request3.id])
end end
it 'returns an array of merge requests assigned to the given user' do it 'returns an array of merge requests assigned to the given user' do
...@@ -564,7 +539,7 @@ describe API::MergeRequests do ...@@ -564,7 +539,7 @@ describe API::MergeRequests do
get api('/merge_requests', user), params: { assignee_id: user2.id, scope: :all } get api('/merge_requests', user), params: { assignee_id: user2.id, scope: :all }
expect_response_ordered_exactly(merge_request3) expect_paginated_array_response([merge_request3.id])
end end
it 'returns an array of merge requests with no assignee' do it 'returns an array of merge requests with no assignee' do
...@@ -572,7 +547,7 @@ describe API::MergeRequests do ...@@ -572,7 +547,7 @@ describe API::MergeRequests do
get api('/merge_requests', user), params: { assignee_id: 'None', scope: :all } get api('/merge_requests', user), params: { assignee_id: 'None', scope: :all }
expect_response_ordered_exactly(merge_request3) expect_paginated_array_response([merge_request3.id])
end end
it 'returns an array of merge requests with any assignee' do it 'returns an array of merge requests with any assignee' do
...@@ -581,7 +556,10 @@ describe API::MergeRequests do ...@@ -581,7 +556,10 @@ describe API::MergeRequests do
get api('/merge_requests', user), params: { assignee_id: 'Any', scope: :all } get api('/merge_requests', user), params: { assignee_id: 'Any', scope: :all }
expect_response_contain_exactly(merge_request, merge_request2, merge_request_closed, merge_request_merged, merge_request_locked) expect_paginated_array_response([
merge_request_merged.id, merge_request2.id, merge_request_locked.id,
merge_request_closed.id, merge_request.id
])
end end
it 'returns an array of merge requests assigned to me' do it 'returns an array of merge requests assigned to me' do
...@@ -589,7 +567,7 @@ describe API::MergeRequests do ...@@ -589,7 +567,7 @@ describe API::MergeRequests do
get api('/merge_requests', user2), params: { scope: 'assigned_to_me' } get api('/merge_requests', user2), params: { scope: 'assigned_to_me' }
expect_response_ordered_exactly(merge_request3) expect_paginated_array_response([merge_request3.id])
end end
it 'returns an array of merge requests assigned to me (kebab-case)' do it 'returns an array of merge requests assigned to me (kebab-case)' do
...@@ -597,7 +575,7 @@ describe API::MergeRequests do ...@@ -597,7 +575,7 @@ describe API::MergeRequests do
get api('/merge_requests', user2), params: { scope: 'assigned-to-me' } get api('/merge_requests', user2), params: { scope: 'assigned-to-me' }
expect_response_ordered_exactly(merge_request3) expect_paginated_array_response([merge_request3.id])
end end
it 'returns an array of merge requests created by me' do it 'returns an array of merge requests created by me' do
...@@ -605,7 +583,7 @@ describe API::MergeRequests do ...@@ -605,7 +583,7 @@ describe API::MergeRequests do
get api('/merge_requests', user2), params: { scope: 'created_by_me' } get api('/merge_requests', user2), params: { scope: 'created_by_me' }
expect_response_ordered_exactly(merge_request3) expect_paginated_array_response([merge_request3.id])
end end
it 'returns an array of merge requests created by me (kebab-case)' do it 'returns an array of merge requests created by me (kebab-case)' do
...@@ -613,7 +591,7 @@ describe API::MergeRequests do ...@@ -613,7 +591,7 @@ describe API::MergeRequests do
get api('/merge_requests', user2), params: { scope: 'created-by-me' } get api('/merge_requests', user2), params: { scope: 'created-by-me' }
expect_response_ordered_exactly(merge_request3) expect_paginated_array_response([merge_request3.id])
end end
it 'returns merge requests reacted by the authenticated user by the given emoji' do it 'returns merge requests reacted by the authenticated user by the given emoji' do
...@@ -622,14 +600,16 @@ describe API::MergeRequests do ...@@ -622,14 +600,16 @@ describe API::MergeRequests do
get api('/merge_requests', user2), params: { my_reaction_emoji: award_emoji.name, scope: 'all' } get api('/merge_requests', user2), params: { my_reaction_emoji: award_emoji.name, scope: 'all' }
expect_response_ordered_exactly(merge_request3) expect_paginated_array_response([merge_request3.id])
end end
context 'source_branch param' do context 'source_branch param' do
it 'returns merge requests with the given source branch' do it 'returns merge requests with the given source branch' do
get api('/merge_requests', user), params: { source_branch: merge_request_closed.source_branch, state: 'all' } get api('/merge_requests', user), params: { source_branch: merge_request_closed.source_branch, state: 'all' }
expect_response_contain_exactly(merge_request_closed, merge_request_merged, merge_request_locked) expect_paginated_array_response([
merge_request_merged.id, merge_request_locked.id, merge_request_closed.id
])
end end
end end
...@@ -637,7 +617,9 @@ describe API::MergeRequests do ...@@ -637,7 +617,9 @@ describe API::MergeRequests do
it 'returns merge requests with the given target branch' do it 'returns merge requests with the given target branch' do
get api('/merge_requests', user), params: { target_branch: merge_request_closed.target_branch, state: 'all' } get api('/merge_requests', user), params: { target_branch: merge_request_closed.target_branch, state: 'all' }
expect_response_contain_exactly(merge_request_closed, merge_request_merged, merge_request_locked) expect_paginated_array_response([
merge_request_merged.id, merge_request_locked.id, merge_request_closed.id
])
end end
end end
...@@ -646,7 +628,7 @@ describe API::MergeRequests do ...@@ -646,7 +628,7 @@ describe API::MergeRequests do
get api('/merge_requests?created_before=2000-01-02T00:00:00.060Z', user) get api('/merge_requests?created_before=2000-01-02T00:00:00.060Z', user)
expect_response_ordered_exactly(merge_request2) expect_paginated_array_response([merge_request2.id])
end end
it 'returns merge requests created after a specific date' do it 'returns merge requests created after a specific date' do
...@@ -654,7 +636,7 @@ describe API::MergeRequests do ...@@ -654,7 +636,7 @@ describe API::MergeRequests do
get api("/merge_requests?created_after=#{merge_request2.created_at}", user) get api("/merge_requests?created_after=#{merge_request2.created_at}", user)
expect_response_ordered_exactly(merge_request2) expect_paginated_array_response([merge_request2.id])
end end
it 'returns merge requests updated before a specific date' do it 'returns merge requests updated before a specific date' do
...@@ -662,7 +644,7 @@ describe API::MergeRequests do ...@@ -662,7 +644,7 @@ describe API::MergeRequests do
get api('/merge_requests?updated_before=2000-01-02T00:00:00.060Z', user) get api('/merge_requests?updated_before=2000-01-02T00:00:00.060Z', user)
expect_response_ordered_exactly(merge_request2) expect_paginated_array_response([merge_request2.id])
end end
it 'returns merge requests updated after a specific date' do it 'returns merge requests updated after a specific date' do
...@@ -670,7 +652,7 @@ describe API::MergeRequests do ...@@ -670,7 +652,7 @@ describe API::MergeRequests do
get api("/merge_requests?updated_after=#{merge_request2.updated_at}", user) get api("/merge_requests?updated_after=#{merge_request2.updated_at}", user)
expect_response_ordered_exactly(merge_request2) expect_paginated_array_response([merge_request2.id])
end end
context 'search params' do context 'search params' do
...@@ -681,25 +663,25 @@ describe API::MergeRequests do ...@@ -681,25 +663,25 @@ describe API::MergeRequests do
it 'returns merge requests matching given search string for title' do it 'returns merge requests matching given search string for title' do
get api("/merge_requests", user), params: { search: merge_request.title } get api("/merge_requests", user), params: { search: merge_request.title }
expect_response_ordered_exactly(merge_request) expect_paginated_array_response([merge_request.id])
end end
it 'returns merge requests matching given search string for title and scoped in title' do it 'returns merge requests matching given search string for title and scoped in title' do
get api("/merge_requests", user), params: { search: merge_request.title, in: 'title' } get api("/merge_requests", user), params: { search: merge_request.title, in: 'title' }
expect_response_ordered_exactly(merge_request) expect_paginated_array_response([merge_request.id])
end end
it 'returns an empty array if no merge reques matches given search string for description and scoped in title' do it 'returns an empty array if no merge request matches given search string for description and scoped in title' do
get api("/merge_requests", user), params: { search: merge_request.description, in: 'title' } get api("/merge_requests", user), params: { search: merge_request.description, in: 'title' }
expect_response_contain_exactly expect_empty_array_response
end end
it 'returns merge requests for project matching given search string for description' do it 'returns merge requests for project matching given search string for description' do
get api("/merge_requests", user), params: { project_id: project.id, search: merge_request.description } get api("/merge_requests", user), params: { project_id: project.id, search: merge_request.description }
expect_response_ordered_exactly(merge_request) expect_paginated_array_response([merge_request.id])
end end
end end
...@@ -707,7 +689,7 @@ describe API::MergeRequests do ...@@ -707,7 +689,7 @@ describe API::MergeRequests do
it 'returns merge requests with the given state' do it 'returns merge requests with the given state' do
get api('/merge_requests', user), params: { state: 'locked' } get api('/merge_requests', user), params: { state: 'locked' }
expect_response_contain_exactly(merge_request_locked) expect_paginated_array_response([merge_request_locked.id])
end end
end end
end end
...@@ -729,18 +711,13 @@ describe API::MergeRequests do ...@@ -729,18 +711,13 @@ describe API::MergeRequests do
it "returns an array of no merge_requests when wip=yes" do it "returns an array of no merge_requests when wip=yes" do
get api("/projects/#{project.id}/merge_requests", user), params: { wip: 'yes' } get api("/projects/#{project.id}/merge_requests", user), params: { wip: 'yes' }
expect(response).to have_gitlab_http_status(200) expect_empty_array_response
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.length).to eq(0)
end end
it 'returns merge_request by "iids" array' do it 'returns merge_request by "iids" array' do
get api(endpoint_path, user), params: { iids: [merge_request.iid, merge_request_closed.iid] } get api(endpoint_path, user), params: { iids: [merge_request.iid, merge_request_closed.iid] }
expect(response).to have_gitlab_http_status(200) expect_paginated_array_response([merge_request_closed.id, merge_request.id])
expect(json_response).to be_an Array
expect(json_response.length).to eq(2)
expect(json_response.first['title']).to eq merge_request_closed.title expect(json_response.first['title']).to eq merge_request_closed.title
expect(json_response.first['id']).to eq merge_request_closed.id expect(json_response.first['id']).to eq merge_request_closed.id
end end
...@@ -815,12 +792,10 @@ describe API::MergeRequests do ...@@ -815,12 +792,10 @@ describe API::MergeRequests do
it 'returns an array excluding merge_requests from archived projects' do it 'returns an array excluding merge_requests from archived projects' do
get api(endpoint_path, user) get api(endpoint_path, user)
expect_response_contain_exactly( expect_paginated_array_response([
merge_request_merged, merge_request_merged.id, merge_request_locked.id,
merge_request_locked, merge_request_closed.id, merge_request.id
merge_request_closed, ])
merge_request
)
end end
context 'with non_archived param set as false' do context 'with non_archived param set as false' do
...@@ -829,13 +804,10 @@ describe API::MergeRequests do ...@@ -829,13 +804,10 @@ describe API::MergeRequests do
get api(path, user) get api(path, user)
expect_response_contain_exactly( expect_paginated_array_response([
merge_request_merged, merge_request_merged.id, merge_request_archived.id, merge_request_locked.id,
merge_request_locked, merge_request_closed.id, merge_request.id
merge_request_closed, ])
merge_request,
merge_request_archived
)
end end
end end
end end
...@@ -1079,9 +1051,7 @@ describe API::MergeRequests do ...@@ -1079,9 +1051,7 @@ describe API::MergeRequests do
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/commits", user) get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/commits", user)
commit = merge_request.commits.first commit = merge_request.commits.first
expect(response).to have_gitlab_http_status(200) expect_successful_response_with_paginated_array
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.size).to eq(merge_request.commits.size) expect(json_response.size).to eq(merge_request.commits.size)
expect(json_response.first['id']).to eq(commit.id) expect(json_response.first['id']).to eq(commit.id)
expect(json_response.first['title']).to eq(commit.title) expect(json_response.first['title']).to eq(commit.title)
...@@ -1105,9 +1075,7 @@ describe API::MergeRequests do ...@@ -1105,9 +1075,7 @@ describe API::MergeRequests do
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/context_commits", user) get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/context_commits", user)
expect(response).to have_gitlab_http_status(200) expect_successful_response_with_paginated_array
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.size).to eq(merge_request.context_commits.size) expect(json_response.size).to eq(merge_request.context_commits.size)
expect(json_response.first['id']).to eq(context_commit.id) expect(json_response.first['id']).to eq(context_commit.id)
expect(json_response.first['title']).to eq(context_commit.title) expect(json_response.first['title']).to eq(context_commit.title)
...@@ -1147,9 +1115,7 @@ describe API::MergeRequests do ...@@ -1147,9 +1115,7 @@ describe API::MergeRequests do
it 'returns a paginated array of corresponding pipelines' do it 'returns a paginated array of corresponding pipelines' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/pipelines") get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/pipelines")
expect(response).to have_gitlab_http_status(200) expect_successful_response_with_paginated_array
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.count).to eq(1) expect(json_response.count).to eq(1)
expect(json_response.first['id']).to eq(pipeline.id) expect(json_response.first['id']).to eq(pipeline.id)
end end
...@@ -1395,7 +1361,7 @@ describe API::MergeRequests do ...@@ -1395,7 +1361,7 @@ describe API::MergeRequests do
expect(json_response['labels']).to eq([]) expect(json_response['labels']).to eq([])
end end
xit 'empty label param as array, does not add any labels' do it 'empty label param as array, does not add any labels' do
params[:labels] = [] params[:labels] = []
post api("/projects/#{project.id}/merge_requests", user), params: params post api("/projects/#{project.id}/merge_requests", user), params: params
...@@ -2232,7 +2198,7 @@ describe API::MergeRequests do ...@@ -2232,7 +2198,7 @@ describe API::MergeRequests do
expect(json_response['labels']).to eq [] expect(json_response['labels']).to eq []
end end
xit 'empty label as array, removes labels' do it 'empty label as array, removes labels' do
put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user), put api("/projects/#{project.id}/merge_requests/#{merge_request.iid}", user),
params: { params: {
title: 'new issue', title: 'new issue',
...@@ -2240,7 +2206,6 @@ describe API::MergeRequests do ...@@ -2240,7 +2206,6 @@ describe API::MergeRequests do
} }
expect(response.status).to eq(200) expect(response.status).to eq(200)
# fails, as grape ommits for some reason empty array as optional param value, so nothing it passed along
expect(json_response['labels']).to eq [] expect(json_response['labels']).to eq []
end end
...@@ -2306,9 +2271,7 @@ describe API::MergeRequests do ...@@ -2306,9 +2271,7 @@ describe API::MergeRequests do
get api("/projects/#{project.id}/merge_requests/#{mr.iid}/closes_issues", user) get api("/projects/#{project.id}/merge_requests/#{mr.iid}/closes_issues", user)
expect(response).to have_gitlab_http_status(200) expect_successful_response_with_paginated_array
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(issue.id) expect(json_response.first['id']).to eq(issue.id)
end end
...@@ -2316,10 +2279,7 @@ describe API::MergeRequests do ...@@ -2316,10 +2279,7 @@ describe API::MergeRequests do
it 'returns an empty array when there are no issues to be closed' do it 'returns an empty array when there are no issues to be closed' do
get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/closes_issues", user) get api("/projects/#{project.id}/merge_requests/#{merge_request.iid}/closes_issues", user)
expect(response).to have_gitlab_http_status(200) expect_empty_array_response
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.length).to eq(0)
end end
it 'handles external issues' do it 'handles external issues' do
...@@ -2332,9 +2292,7 @@ describe API::MergeRequests do ...@@ -2332,9 +2292,7 @@ describe API::MergeRequests do
get api("/projects/#{jira_project.id}/merge_requests/#{merge_request.iid}/closes_issues", user) get api("/projects/#{jira_project.id}/merge_requests/#{merge_request.iid}/closes_issues", user)
expect(response).to have_gitlab_http_status(200) expect_successful_response_with_paginated_array
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.length).to eq(2) expect(json_response.length).to eq(2)
expect(json_response.second['title']).to eq(ext_issue.title) expect(json_response.second['title']).to eq(ext_issue.title)
expect(json_response.second['id']).to eq(ext_issue.id) expect(json_response.second['id']).to eq(ext_issue.id)
...@@ -2546,22 +2504,4 @@ describe API::MergeRequests do ...@@ -2546,22 +2504,4 @@ describe API::MergeRequests do
merge_request_closed.save merge_request_closed.save
merge_request_closed merge_request_closed
end end
def expect_response_contain_exactly(*items)
expect_paginated_array_response
expect(json_response.length).to eq(items.size)
expect(json_response.map { |element| element['id'] }).to contain_exactly(*items.map(&:id))
end
def expect_response_ordered_exactly(*items)
expect_paginated_array_response
expect(json_response.length).to eq(items.size)
expect(json_response.map { |element| element['id'] }).to eq(items.map(&:id))
end
def expect_paginated_array_response
expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
end
end end
...@@ -40,6 +40,17 @@ module ApiHelpers ...@@ -40,6 +40,17 @@ module ApiHelpers
end end
end end
def expect_empty_array_response
expect_successful_response_with_paginated_array
expect(json_response.length).to eq(0)
end
def expect_successful_response_with_paginated_array
expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
end
def expect_paginated_array_response(items) def expect_paginated_array_response(items)
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers expect(response).to include_pagination_headers
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment