Commit dc8ce956 authored by Stan Hu's avatar Stan Hu

Merge branch '9070-refactor-specs' into 'master'

Refactor epics/issues API specs

Closes #9070

See merge request gitlab-org/gitlab-ee!9086
parents afee5539 cf745a24
......@@ -69,16 +69,6 @@ describe API::Epics do
describe 'GET /groups/:id/epics' do
let(:url) { "/groups/#{group.path}/epics" }
def expect_paginated_array_of_items(expected)
expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
items = json_response.map { |i| i['id'] }
expect(items).to eq(expected)
end
it_behaves_like 'error requests'
context 'when the request is correct' do
......@@ -125,61 +115,61 @@ describe API::Epics do
it 'returns epics authored by the given author id' do
get api(url, user), params: { author_id: user2.id }
expect_paginated_array_of_items([epic2.id])
expect_paginated_array_response([epic2.id])
end
it 'returns epics matching given search string for title' do
get api(url, user), params: { search: epic2.title }
expect_paginated_array_of_items([epic2.id])
expect_paginated_array_response([epic2.id])
end
it 'returns epics matching given search string for description' do
get api(url, user), params: { search: epic2.description }
expect_paginated_array_of_items([epic2.id])
expect_paginated_array_response([epic2.id])
end
it 'returns epics matching given status' do
get api(url, user), params: { state: :opened }
expect_paginated_array_of_items([epic2.id])
expect_paginated_array_response([epic2.id])
end
it 'returns all epics when state set to all' do
get api(url, user), params: { state: :all }
expect_paginated_array_of_items([epic2.id, epic.id])
expect_paginated_array_response([epic2.id, epic.id])
end
it 'sorts by created_at descending by default' do
get api(url, user)
expect_paginated_array_of_items([epic2.id, epic.id])
expect_paginated_array_response([epic2.id, epic.id])
end
it 'sorts ascending when requested' do
get api(url, user), params: { sort: :asc }
expect_paginated_array_of_items([epic.id, epic2.id])
expect_paginated_array_response([epic.id, epic2.id])
end
it 'sorts by updated_at descending when requested' do
get api(url, user), params: { order_by: :updated_at }
expect_paginated_array_of_items([epic.id, epic2.id])
expect_paginated_array_response([epic.id, epic2.id])
end
it 'sorts by updated_at ascending when requested' do
get api(url, user), params: { order_by: :updated_at, sort: :asc }
expect_paginated_array_of_items([epic2.id, epic.id])
expect_paginated_array_response([epic2.id, epic.id])
end
it 'returns an array of labeled epics' do
get api(url, user), params: { labels: label.title }
expect_paginated_array_of_items([epic2.id])
expect_paginated_array_response([epic2.id])
end
it_behaves_like 'can admin epics'
......@@ -201,7 +191,7 @@ describe API::Epics do
get api(url, user), params: { page: page, per_page: per_page }
expect(response.headers['X-Page']).to eq(page.to_s)
expect_paginated_array_of_items(expected)
expect_paginated_array_response(expected)
end
end
......
......@@ -38,31 +38,26 @@ describe API::Issues, :mailer do
end
describe "filtering by weight" do
before do
create(:issue, author: user2, project: project, weight: 1)
create(:issue, author: user2, project: project, weight: 3)
end
let!(:issue2) { create(:issue, author: user2, project: project, weight: 5) }
let!(:issue1) { create(:issue, author: user2, project: project, weight: 1, created_at: 3.days.ago) }
let!(:issue2) { create(:issue, author: user2, project: project, weight: 5, created_at: 2.days.ago) }
let!(:issue3) { create(:issue, author: user2, project: project, weight: 3, created_at: 1.day.ago) }
it 'returns issues with specific weight' do
get api('/issues', user), params: { weight: 5, scope: 'all' }
expect_paginated_array_response(size: 1)
expect(json_response.first['id']).to eq(issue2.id)
expect_paginated_array_response(issue2.id)
end
it 'returns issues with no weight' do
get api('/issues', user), params: { weight: 'None', scope: 'all' }
expect_paginated_array_response(size: 1)
expect(json_response.first['id']).to eq(issue.id)
expect_paginated_array_response(issue.id)
end
it 'returns issues with any weight' do
get api('/issues', user), params: { weight: 'Any', scope: 'all' }
expect_paginated_array_response(size: 3)
expect_paginated_array_response([issue3.id, issue2.id, issue1.id])
end
end
end
......@@ -131,11 +126,4 @@ describe API::Issues, :mailer do
end
end
end
def expect_paginated_array_response(size: nil)
expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.length).to eq(size) if size
end
end
This diff is collapsed.
......@@ -36,4 +36,11 @@ module ApiHelpers
full_path
end
def expect_paginated_array_response(items)
expect(response).to have_gitlab_http_status(200)
expect(response).to include_pagination_headers
expect(json_response).to be_an Array
expect(json_response.map { |item| item['id'] }).to eq(Array(items))
end
end
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