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
This diff is collapsed.
...@@ -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