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

125 lines
3.7 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
require 'spec_helper'
describe API::ProjectMilestones do
let(:user) { create(:user) }
let!(:project) { create(:project, namespace: user.namespace ) }
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
2018-03-17 18:26:18 +05:30
project.add_developer(user)
2017-09-10 17:25:29 +05:30
end
2019-03-02 22:35:43 +05:30
it_behaves_like 'group and project milestones', "/projects/:id/milestones" do
2017-09-10 17:25:29 +05:30
let(:route) { "/projects/#{project.id}/milestones" }
end
2018-03-17 18:26:18 +05:30
describe 'DELETE /projects/:id/milestones/:milestone_id' do
let(:guest) { create(:user) }
let(:reporter) { create(:user) }
before do
project.add_reporter(reporter)
end
2020-05-24 23:13:21 +05:30
it 'returns 404 response when the project does not exist' do
2019-07-07 11:18:12 +05:30
delete api("/projects/0/milestones/#{milestone.id}", user)
2018-03-17 18:26:18 +05:30
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2018-03-17 18:26:18 +05:30
end
2020-05-24 23:13:21 +05:30
it 'returns 404 response when the milestone does not exist' do
2019-07-07 11:18:12 +05:30
delete api("/projects/#{project.id}/milestones/0", user)
2018-03-17 18:26:18 +05:30
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2018-03-17 18:26:18 +05:30
end
it "returns 404 from guest user deleting a milestone" do
delete api("/projects/#{project.id}/milestones/#{milestone.id}", guest)
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2018-03-17 18:26:18 +05:30
end
end
2017-09-10 17:25:29 +05:30
describe 'PUT /projects/:id/milestones/:milestone_id to test observer on close' do
2020-05-24 23:13:21 +05:30
it 'creates an activity event when a milestone is closed' do
2018-03-17 18:26:18 +05:30
expect(Event).to receive(:create!)
2017-09-10 17:25:29 +05:30
put api("/projects/#{project.id}/milestones/#{milestone.id}", user),
2019-02-15 15:39:39 +05:30
params: { state_event: 'close' }
2017-09-10 17:25:29 +05:30
end
end
2019-07-07 11:18:12 +05:30
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)
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:forbidden)
2019-07-07 11:18:12 +05:30
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)
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:ok)
2019-07-07 11:18:12 +05:30
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)
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:ok)
2019-07-07 11:18:12 +05:30
expect(group.milestones.first.title).to eq(closed_milestone.title)
end
end
2020-05-24 23:13:21 +05:30
context 'when no such resource' do
2019-07-07 11:18:12 +05:30
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)
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2019-07-07 11:18:12 +05:30
end
it 'returns 404 response when the milestone does not exist' do
post api("/projects/#{project.id}/milestones/0/promote", user)
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:not_found)
2019-07-07 11:18:12 +05:30
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)
2020-04-08 14:13:33 +05:30
expect(response).to have_gitlab_http_status(:forbidden)
2019-07-07 11:18:12 +05:30
end
end
end
2017-09-10 17:25:29 +05:30
end