2017-07-12 15:58:48 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe API::ProjectMilestones do
|
|
|
|
let(:user) { create(:user) }
|
2017-08-02 15:55:11 -04:00
|
|
|
let!(:project) { create(:project, namespace: user.namespace ) }
|
2017-07-12 15:58:48 -04:00
|
|
|
let!(:closed_milestone) { create(:closed_milestone, project: project, title: 'version1', description: 'closed milestone') }
|
|
|
|
let!(:milestone) { create(:milestone, project: project, title: 'version2', description: 'open milestone') }
|
|
|
|
|
|
|
|
before do
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_developer(user)
|
2017-07-12 15:58:48 -04:00
|
|
|
end
|
|
|
|
|
2019-01-16 07:09:29 -05:00
|
|
|
it_behaves_like 'group and project milestones', "/projects/:id/milestones" do
|
2017-07-12 15:58:48 -04:00
|
|
|
let(:route) { "/projects/#{project.id}/milestones" }
|
|
|
|
end
|
|
|
|
|
2018-01-15 17:03:43 -05:00
|
|
|
describe 'DELETE /projects/:id/milestones/:milestone_id' do
|
|
|
|
let(:guest) { create(:user) }
|
|
|
|
let(:reporter) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_reporter(reporter)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 404 response when the project does not exists' do
|
2019-02-26 18:18:40 -05:00
|
|
|
delete api("/projects/0/milestones/#{milestone.id}", user)
|
2018-01-15 17:03:43 -05:00
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(404)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 404 response when the milestone does not exists' do
|
2019-02-26 18:18:40 -05:00
|
|
|
delete api("/projects/#{project.id}/milestones/0", user)
|
2018-01-15 17:03:43 -05:00
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(404)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns 404 from guest user deleting a milestone" do
|
|
|
|
delete api("/projects/#{project.id}/milestones/#{milestone.id}", guest)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-12 15:58:48 -04:00
|
|
|
describe 'PUT /projects/:id/milestones/:milestone_id to test observer on close' do
|
|
|
|
it 'creates an activity event when an milestone is closed' do
|
2017-12-07 12:41:30 -05:00
|
|
|
expect(Event).to receive(:create!)
|
2017-07-12 15:58:48 -04:00
|
|
|
|
|
|
|
put api("/projects/#{project.id}/milestones/#{milestone.id}", user),
|
2018-12-17 17:52:17 -05:00
|
|
|
params: { state_event: 'close' }
|
2017-07-12 15:58:48 -04:00
|
|
|
end
|
|
|
|
end
|
2019-02-26 18:18:40 -05:00
|
|
|
|
|
|
|
describe 'POST /projects/:id/milestones/:milestone_id/promote' do
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.update(namespace: group)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user does not have permission to promote milestone' do
|
|
|
|
before do
|
|
|
|
group.add_guest(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 403' do
|
|
|
|
post api("/projects/#{project.id}/milestones/#{milestone.id}/promote", user)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(403)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user has permission' do
|
|
|
|
before do
|
|
|
|
group.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 200' do
|
|
|
|
post api("/projects/#{project.id}/milestones/#{milestone.id}/promote", user)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(200)
|
|
|
|
expect(group.milestones.first.title).to eq(milestone.title)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 200 for closed milestone' do
|
|
|
|
post api("/projects/#{project.id}/milestones/#{closed_milestone.id}/promote", user)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(200)
|
|
|
|
expect(group.milestones.first.title).to eq(closed_milestone.title)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when no such resources' do
|
|
|
|
before do
|
|
|
|
group.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 404 response when the project does not exist' do
|
|
|
|
post api("/projects/0/milestones/#{milestone.id}/promote", user)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(404)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 404 response when the milestone does not exist' do
|
|
|
|
post api("/projects/#{project.id}/milestones/0/promote", user)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(404)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project does not belong to group' do
|
|
|
|
before do
|
|
|
|
project.update(namespace: user.namespace)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns 403' do
|
|
|
|
post api("/projects/#{project.id}/milestones/#{milestone.id}/promote", user)
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(403)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-07-12 15:58:48 -04:00
|
|
|
end
|