debian-mirror-gitlab/spec/requests/api/milestones_spec.rb

214 lines
7.5 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
require 'spec_helper'
describe API::API, api: true do
include ApiHelpers
let(:user) { create(:user) }
2016-09-29 09:46:39 +05:30
let!(:project) { create(:empty_project, namespace: user.namespace ) }
2016-06-02 11:05:42 +05:30
let!(:closed_milestone) { create(:closed_milestone, project: project) }
2014-09-02 18:07:02 +05:30
let!(:milestone) { create(:milestone, project: project) }
before { project.team << [user, :developer] }
2015-04-26 12:48:37 +05:30
describe 'GET /projects/:id/milestones' do
2016-09-13 17:45:13 +05:30
it 'returns project milestones' do
2014-09-02 18:07:02 +05:30
get api("/projects/#{project.id}/milestones", user)
2016-09-29 09:46:39 +05:30
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2015-04-26 12:48:37 +05:30
expect(json_response).to be_an Array
expect(json_response.first['title']).to eq(milestone.title)
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it 'returns a 401 error if user not authenticated' do
2014-09-02 18:07:02 +05:30
get api("/projects/#{project.id}/milestones")
2016-09-29 09:46:39 +05:30
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(401)
2014-09-02 18:07:02 +05:30
end
2016-06-02 11:05:42 +05:30
it 'returns an array of active milestones' do
get api("/projects/#{project.id}/milestones?state=active", user)
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2016-06-02 11:05:42 +05:30
expect(json_response).to be_an Array
expect(json_response.length).to eq(1)
expect(json_response.first['id']).to eq(milestone.id)
end
it 'returns an array of closed milestones' do
get api("/projects/#{project.id}/milestones?state=closed", user)
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2016-06-02 11:05:42 +05:30
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
2014-09-02 18:07:02 +05:30
end
2015-04-26 12:48:37 +05:30
describe 'GET /projects/:id/milestones/:milestone_id' do
2016-09-13 17:45:13 +05:30
it 'returns a project milestone by id' do
2014-09-02 18:07:02 +05:30
get api("/projects/#{project.id}/milestones/#{milestone.id}", user)
2016-09-29 09:46:39 +05:30
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2015-04-26 12:48:37 +05:30
expect(json_response['title']).to eq(milestone.title)
expect(json_response['iid']).to eq(milestone.iid)
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it 'returns a project milestone by iid' do
2016-06-02 11:05:42 +05:30
get api("/projects/#{project.id}/milestones?iid=#{closed_milestone.iid}", user)
2015-09-11 14:41:01 +05:30
expect(response.status).to eq 200
2016-06-02 11:05:42 +05:30
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
2015-09-11 14:41:01 +05:30
end
2016-09-13 17:45:13 +05:30
it 'returns 401 error if user not authenticated' do
2014-09-02 18:07:02 +05:30
get api("/projects/#{project.id}/milestones/#{milestone.id}")
2016-09-29 09:46:39 +05:30
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(401)
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it 'returns a 404 error if milestone id not found' do
2014-09-02 18:07:02 +05:30
get api("/projects/#{project.id}/milestones/1234", user)
2016-09-29 09:46:39 +05:30
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(404)
2014-09-02 18:07:02 +05:30
end
end
2015-04-26 12:48:37 +05:30
describe 'POST /projects/:id/milestones' do
2016-09-13 17:45:13 +05:30
it 'creates a new project milestone' do
2014-09-02 18:07:02 +05:30
post api("/projects/#{project.id}/milestones", user), title: 'new milestone'
2016-09-29 09:46:39 +05:30
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(201)
2015-04-26 12:48:37 +05:30
expect(json_response['title']).to eq('new milestone')
expect(json_response['description']).to be_nil
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it 'creates a new project milestone with description and due date' do
2014-09-02 18:07:02 +05:30
post api("/projects/#{project.id}/milestones", user),
title: 'new milestone', description: 'release', due_date: '2013-03-02'
2016-09-29 09:46:39 +05:30
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(201)
2015-04-26 12:48:37 +05:30
expect(json_response['description']).to eq('release')
expect(json_response['due_date']).to eq('2013-03-02')
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it 'returns a 400 error if title is missing' do
2014-09-02 18:07:02 +05:30
post api("/projects/#{project.id}/milestones", user)
2016-09-29 09:46:39 +05:30
expect(response).to have_http_status(400)
end
it 'returns a 400 error if params are invalid (duplicate title)' do
post api("/projects/#{project.id}/milestones", user),
title: milestone.title, description: 'release', due_date: '2013-03-02'
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(400)
2014-09-02 18:07:02 +05:30
end
2016-11-03 12:29:30 +05:30
it 'creates a new project with reserved html characters' do
post api("/projects/#{project.id}/milestones", user), title: 'foo & bar 1.1 -> 2.2'
expect(response).to have_http_status(201)
expect(json_response['title']).to eq('foo & bar 1.1 -> 2.2')
expect(json_response['description']).to be_nil
end
2014-09-02 18:07:02 +05:30
end
2015-04-26 12:48:37 +05:30
describe 'PUT /projects/:id/milestones/:milestone_id' do
2016-09-13 17:45:13 +05:30
it 'updates a project milestone' do
2014-09-02 18:07:02 +05:30
put api("/projects/#{project.id}/milestones/#{milestone.id}", user),
title: 'updated title'
2016-09-29 09:46:39 +05:30
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2015-04-26 12:48:37 +05:30
expect(json_response['title']).to eq('updated title')
2014-09-02 18:07:02 +05:30
end
2016-09-13 17:45:13 +05:30
it 'returns a 404 error if milestone id not found' do
2014-09-02 18:07:02 +05:30
put api("/projects/#{project.id}/milestones/1234", user),
title: 'updated title'
2016-09-29 09:46:39 +05:30
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(404)
2014-09-02 18:07:02 +05:30
end
end
2015-04-26 12:48:37 +05:30
describe 'PUT /projects/:id/milestones/:milestone_id to close milestone' do
2016-09-13 17:45:13 +05:30
it 'updates a project milestone' do
2014-09-02 18:07:02 +05:30
put api("/projects/#{project.id}/milestones/#{milestone.id}", user),
state_event: 'close'
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2014-09-02 18:07:02 +05:30
2015-04-26 12:48:37 +05:30
expect(json_response['state']).to eq('closed')
2014-09-02 18:07:02 +05:30
end
end
2015-04-26 12:48:37 +05:30
describe 'PUT /projects/:id/milestones/:milestone_id to test observer on close' do
2016-09-13 17:45:13 +05:30
it 'creates an activity event when an milestone is closed' do
2015-04-26 12:48:37 +05:30
expect(Event).to receive(:create)
2014-09-02 18:07:02 +05:30
put api("/projects/#{project.id}/milestones/#{milestone.id}", user),
state_event: 'close'
end
end
2015-04-26 12:48:37 +05:30
describe 'GET /projects/:id/milestones/:milestone_id/issues' do
before do
2016-06-02 11:05:42 +05:30
milestone.issues << create(:issue, project: project)
2015-04-26 12:48:37 +05:30
end
2016-09-13 17:45:13 +05:30
it 'returns project issues for a particular milestone' do
2015-04-26 12:48:37 +05:30
get api("/projects/#{project.id}/milestones/#{milestone.id}/issues", user)
2016-09-29 09:46:39 +05:30
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2015-04-26 12:48:37 +05:30
expect(json_response).to be_an Array
expect(json_response.first['milestone']['title']).to eq(milestone.title)
end
2016-09-13 17:45:13 +05:30
it 'returns a 401 error if user not authenticated' do
2015-04-26 12:48:37 +05:30
get api("/projects/#{project.id}/milestones/#{milestone.id}/issues")
2016-09-29 09:46:39 +05:30
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(401)
2015-04-26 12:48:37 +05:30
end
2016-06-02 11:05:42 +05:30
describe 'confidential issues' do
2016-09-29 09:46:39 +05:30
let(:public_project) { create(:empty_project, :public) }
2016-06-02 11:05:42 +05:30
let(:milestone) { create(:milestone, project: public_project) }
let(:issue) { create(:issue, project: public_project) }
let(:confidential_issue) { create(:issue, confidential: true, project: public_project) }
2016-06-02 11:05:42 +05:30
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-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2016-06-02 11:05:42 +05:30
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-08-24 12:49:21 +05:30
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
2016-06-02 11:05:42 +05:30
it 'does not return confidential issues to regular users' do
get api("/projects/#{public_project.id}/milestones/#{milestone.id}/issues", create(:user))
2016-08-24 12:49:21 +05:30
expect(response).to have_http_status(200)
2016-06-02 11:05:42 +05:30
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
2015-04-26 12:48:37 +05:30
end
2014-09-02 18:07:02 +05:30
end