gitlab-org--gitlab-foss/spec/requests/api/milestones_spec.rb

187 lines
6.9 KiB
Ruby
Raw Normal View History

2012-08-16 14:51:31 -04:00
require 'spec_helper'
2014-04-11 15:45:56 -04:00
describe API::API, api: true do
include ApiHelpers
let(:user) { create(:user) }
let!(:project) { create(:project, namespace: user.namespace ) }
2016-04-06 14:53:17 -04:00
let!(:closed_milestone) { create(:closed_milestone, project: project) }
let!(:milestone) { create(:milestone, project: project) }
2012-08-16 14:51:31 -04:00
2013-01-04 11:50:31 -05:00
before { project.team << [user, :developer] }
2012-08-16 14:51:31 -04:00
describe 'GET /projects/:id/milestones' do
it 'returns project milestones' do
2013-01-02 12:46:06 -05:00
get api("/projects/#{project.id}/milestones", user)
2016-06-27 14:10:42 -04:00
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
expect(json_response.first['title']).to eq(milestone.title)
2012-08-16 14:51:31 -04:00
end
it 'returns a 401 error if user not authenticated' do
get api("/projects/#{project.id}/milestones")
2016-06-27 14:10:42 -04:00
expect(response).to have_http_status(401)
end
2016-04-06 14:53:17 -04:00
it 'returns an array of active milestones' do
get api("/projects/#{project.id}/milestones?state=active", user)
2016-04-06 14:53:17 -04:00
2016-06-27 14:10:42 -04:00
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(milestone.id)
end
2016-04-06 14:53:17 -04:00
it 'returns an array of closed milestones' do
get api("/projects/#{project.id}/milestones?state=closed", user)
2016-04-06 14:53:17 -04:00
2016-06-27 14:10:42 -04:00
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(closed_milestone.id)
end
2012-08-16 14:51:31 -04:00
end
describe 'GET /projects/:id/milestones/:milestone_id' do
it 'returns a project milestone by id' do
2013-01-02 12:46:06 -05:00
get api("/projects/#{project.id}/milestones/#{milestone.id}", user)
2016-06-27 14:10:42 -04:00
expect(response).to have_http_status(200)
expect(json_response['title']).to eq(milestone.title)
expect(json_response['iid']).to eq(milestone.iid)
2012-08-16 14:51:31 -04:00
end
it 'returns a project milestone by iid' do
2016-04-07 04:59:54 -04:00
get api("/projects/#{project.id}/milestones?iid=#{closed_milestone.iid}", user)
expect(response.status).to eq 200
2016-04-07 04:59:54 -04:00
expect(json_response.size).to eq(1)
expect(json_response.first['title']).to eq closed_milestone.title
expect(json_response.first['id']).to eq closed_milestone.id
end
it 'returns 401 error if user not authenticated' do
get api("/projects/#{project.id}/milestones/#{milestone.id}")
2016-06-27 14:10:42 -04:00
expect(response).to have_http_status(401)
end
it 'returns a 404 error if milestone id not found' do
get api("/projects/#{project.id}/milestones/1234", user)
2016-06-27 14:10:42 -04:00
expect(response).to have_http_status(404)
end
2012-08-16 14:51:31 -04:00
end
describe 'POST /projects/:id/milestones' do
it 'creates a new project milestone' do
post api("/projects/#{project.id}/milestones", user), title: 'new milestone'
2016-06-27 14:10:42 -04:00
expect(response).to have_http_status(201)
expect(json_response['title']).to eq('new milestone')
expect(json_response['description']).to be_nil
2012-08-16 14:51:31 -04:00
end
it 'creates a new project milestone with description and due date' do
post api("/projects/#{project.id}/milestones", user),
title: 'new milestone', description: 'release', due_date: '2013-03-02'
2016-06-27 14:10:42 -04:00
expect(response).to have_http_status(201)
expect(json_response['description']).to eq('release')
expect(json_response['due_date']).to eq('2013-03-02')
end
it 'returns a 400 error if title is missing' do
post api("/projects/#{project.id}/milestones", user)
2016-06-27 14:10:42 -04:00
expect(response).to have_http_status(400)
end
2012-08-16 14:51:31 -04:00
end
describe 'PUT /projects/:id/milestones/:milestone_id' do
it 'updates a project milestone' do
2013-01-02 12:46:06 -05:00
put api("/projects/#{project.id}/milestones/#{milestone.id}", user),
2012-08-16 14:51:31 -04:00
title: 'updated title'
2016-06-27 14:10:42 -04:00
expect(response).to have_http_status(200)
expect(json_response['title']).to eq('updated title')
2012-08-16 14:51:31 -04:00
end
it 'returns a 404 error if milestone id not found' do
put api("/projects/#{project.id}/milestones/1234", user),
title: 'updated title'
2016-06-27 14:10:42 -04:00
expect(response).to have_http_status(404)
end
2012-08-16 14:51:31 -04:00
end
2013-02-18 04:10:09 -05:00
describe 'PUT /projects/:id/milestones/:milestone_id to close milestone' do
it 'updates a project milestone' do
2013-02-18 04:10:09 -05:00
put api("/projects/#{project.id}/milestones/#{milestone.id}", user),
state_event: 'close'
2016-06-27 14:10:42 -04:00
expect(response).to have_http_status(200)
2013-02-18 04:10:09 -05:00
expect(json_response['state']).to eq('closed')
2013-02-18 04:10:09 -05:00
end
end
describe 'PUT /projects/:id/milestones/:milestone_id to test observer on close' do
it 'creates an activity event when an milestone is closed' do
expect(Event).to receive(:create)
put api("/projects/#{project.id}/milestones/#{milestone.id}", user),
state_event: 'close'
end
end
2014-06-02 19:10:38 -04:00
describe 'GET /projects/:id/milestones/:milestone_id/issues' do
before do
milestone.issues << create(:issue, project: project)
end
it 'returns project issues for a particular milestone' do
2014-06-02 19:10:38 -04:00
get api("/projects/#{project.id}/milestones/#{milestone.id}/issues", user)
2016-06-27 14:10:42 -04:00
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
expect(json_response.first['milestone']['title']).to eq(milestone.title)
2014-06-02 19:10:38 -04:00
end
it 'returns a 401 error if user not authenticated' do
2014-06-02 19:10:38 -04:00
get api("/projects/#{project.id}/milestones/#{milestone.id}/issues")
2016-06-27 14:10:42 -04:00
expect(response).to have_http_status(401)
2014-06-02 19:10:38 -04:00
end
describe 'confidential issues' do
let(:public_project) { create(:project, :public) }
let(:milestone) { create(:milestone, project: public_project) }
let(:issue) { create(:issue, project: public_project) }
let(:confidential_issue) { create(:issue, confidential: true, project: public_project) }
before do
public_project.team << [user, :developer]
milestone.issues << issue << confidential_issue
end
it 'returns confidential issues to team members' do
get api("/projects/#{public_project.id}/milestones/#{milestone.id}/issues", user)
2016-06-27 14:10:42 -04:00
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
expect(json_response.size).to eq(2)
expect(json_response.map { |issue| issue['id'] }).to include(issue.id, confidential_issue.id)
end
it 'does not return confidential issues to team members with guest role' do
member = create(:user)
project.team << [member, :guest]
get api("/projects/#{public_project.id}/milestones/#{milestone.id}/issues", member)
2016-06-27 14:10:42 -04:00
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
expect(json_response.size).to eq(1)
expect(json_response.map { |issue| issue['id'] }).to include(issue.id)
end
it 'does not return confidential issues to regular users' do
get api("/projects/#{public_project.id}/milestones/#{milestone.id}/issues", create(:user))
2016-06-27 14:10:42 -04:00
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
expect(json_response.size).to eq(1)
expect(json_response.map { |issue| issue['id'] }).to include(issue.id)
end
end
end
2012-08-16 14:51:31 -04:00
end