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
|
2012-08-29 11:58:33 -04:00
|
|
|
include ApiHelpers
|
2012-11-05 22:31:55 -05:00
|
|
|
let(:user) { create(:user) }
|
2013-01-02 12:32:34 -05:00
|
|
|
let!(:project) { create(:project, namespace: user.namespace ) }
|
2012-11-05 22:31:55 -05:00
|
|
|
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
|
|
|
|
2015-01-21 17:59:30 -05:00
|
|
|
describe 'GET /projects/:id/milestones' do
|
|
|
|
it 'should return project milestones' do
|
2013-01-02 12:46:06 -05:00
|
|
|
get api("/projects/#{project.id}/milestones", user)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(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
|
2013-02-20 16:51:59 -05:00
|
|
|
|
2015-01-21 17:59:30 -05:00
|
|
|
it 'should return a 401 error if user not authenticated' do
|
2013-02-20 16:51:59 -05:00
|
|
|
get api("/projects/#{project.id}/milestones")
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(401)
|
2013-02-20 16:51:59 -05:00
|
|
|
end
|
2012-08-16 14:51:31 -04:00
|
|
|
end
|
|
|
|
|
2015-01-21 17:59:30 -05:00
|
|
|
describe 'GET /projects/:id/milestones/:milestone_id' do
|
|
|
|
it 'should return a project milestone by id' do
|
2013-01-02 12:46:06 -05:00
|
|
|
get api("/projects/#{project.id}/milestones/#{milestone.id}", user)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(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
|
2013-02-06 09:05:56 -05:00
|
|
|
|
2015-01-17 17:45:39 -05:00
|
|
|
it 'should return a project milestone by iid' do
|
|
|
|
get api("/projects/#{project.id}/milestones?iid=#{milestone.iid}", user)
|
2015-06-13 18:24:51 -04:00
|
|
|
expect(response.status).to eq 200
|
|
|
|
expect(json_response.first['title']).to eq milestone.title
|
|
|
|
expect(json_response.first['id']).to eq milestone.id
|
2015-01-17 17:45:39 -05:00
|
|
|
end
|
|
|
|
|
2015-01-21 17:59:30 -05:00
|
|
|
it 'should return 401 error if user not authenticated' do
|
2013-02-20 16:51:59 -05:00
|
|
|
get api("/projects/#{project.id}/milestones/#{milestone.id}")
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(401)
|
2013-02-20 16:51:59 -05:00
|
|
|
end
|
|
|
|
|
2015-01-21 17:59:30 -05:00
|
|
|
it 'should return a 404 error if milestone id not found' do
|
2013-02-06 09:05:56 -05:00
|
|
|
get api("/projects/#{project.id}/milestones/1234", user)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(404)
|
2013-02-06 09:05:56 -05:00
|
|
|
end
|
2012-08-16 14:51:31 -04:00
|
|
|
end
|
|
|
|
|
2015-01-21 17:59:30 -05:00
|
|
|
describe 'POST /projects/:id/milestones' do
|
|
|
|
it 'should create a new project milestone' do
|
2013-02-20 16:51:59 -05:00
|
|
|
post api("/projects/#{project.id}/milestones", user), title: 'new milestone'
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(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
|
2013-02-06 09:05:56 -05:00
|
|
|
|
2015-01-21 17:59:30 -05:00
|
|
|
it 'should create a new project milestone with description and due date' do
|
2013-02-06 09:05:56 -05:00
|
|
|
post api("/projects/#{project.id}/milestones", user),
|
|
|
|
title: 'new milestone', description: 'release', due_date: '2013-03-02'
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(201)
|
|
|
|
expect(json_response['description']).to eq('release')
|
|
|
|
expect(json_response['due_date']).to eq('2013-03-02')
|
2013-02-06 09:05:56 -05:00
|
|
|
end
|
|
|
|
|
2015-01-21 17:59:30 -05:00
|
|
|
it 'should return a 400 error if title is missing' do
|
2013-02-06 09:05:56 -05:00
|
|
|
post api("/projects/#{project.id}/milestones", user)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(400)
|
2013-02-06 09:05:56 -05:00
|
|
|
end
|
2012-08-16 14:51:31 -04:00
|
|
|
end
|
|
|
|
|
2015-01-21 17:59:30 -05:00
|
|
|
describe 'PUT /projects/:id/milestones/:milestone_id' do
|
|
|
|
it 'should update 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'
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(200)
|
|
|
|
expect(json_response['title']).to eq('updated title')
|
2012-08-16 14:51:31 -04:00
|
|
|
end
|
2013-02-06 09:05:56 -05:00
|
|
|
|
2015-01-21 17:59:30 -05:00
|
|
|
it 'should return a 404 error if milestone id not found' do
|
2013-02-06 09:05:56 -05:00
|
|
|
put api("/projects/#{project.id}/milestones/1234", user),
|
|
|
|
title: 'updated title'
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(404)
|
2013-02-06 09:05:56 -05:00
|
|
|
end
|
2012-08-16 14:51:31 -04:00
|
|
|
end
|
2013-02-18 04:10:09 -05:00
|
|
|
|
2015-01-21 17:59:30 -05:00
|
|
|
describe 'PUT /projects/:id/milestones/:milestone_id to close milestone' do
|
|
|
|
it 'should update a project milestone' do
|
2013-02-18 04:10:09 -05:00
|
|
|
put api("/projects/#{project.id}/milestones/#{milestone.id}", user),
|
|
|
|
state_event: 'close'
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(200)
|
2013-02-18 04:10:09 -05:00
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(json_response['state']).to eq('closed')
|
2013-02-18 04:10:09 -05:00
|
|
|
end
|
|
|
|
end
|
2013-10-04 15:11:50 -04:00
|
|
|
|
2015-01-21 17:59:30 -05:00
|
|
|
describe 'PUT /projects/:id/milestones/:milestone_id to test observer on close' do
|
|
|
|
it 'should create an activity event when an milestone is closed' do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(Event).to receive(:create)
|
2013-10-04 15:11:50 -04:00
|
|
|
|
|
|
|
put api("/projects/#{project.id}/milestones/#{milestone.id}", user),
|
|
|
|
state_event: 'close'
|
|
|
|
end
|
|
|
|
end
|
2014-06-02 19:10:38 -04:00
|
|
|
|
2015-01-21 17:59:30 -05:00
|
|
|
describe 'GET /projects/:id/milestones/:milestone_id/issues' do
|
|
|
|
before do
|
|
|
|
milestone.issues << create(:issue)
|
|
|
|
end
|
|
|
|
it 'should return 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)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(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
|
|
|
|
|
2015-01-21 17:59:30 -05:00
|
|
|
it 'should return 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")
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(response.status).to eq(401)
|
2014-06-02 19:10:38 -04:00
|
|
|
end
|
|
|
|
end
|
2012-08-16 14:51:31 -04:00
|
|
|
end
|