2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe API::V3::Deployments do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:non_member) { create(:user) }
|
|
|
|
let(:project) { deployment.environment.project }
|
|
|
|
let!(:deployment) { create(:deployment) }
|
|
|
|
|
|
|
|
before do
|
2018-03-17 18:26:18 +05:30
|
|
|
project.add_master(user)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'a paginated resources' do
|
|
|
|
before do
|
|
|
|
# Fires the request
|
|
|
|
request
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has pagination headers' do
|
|
|
|
expect(response).to include_pagination_headers
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET /projects/:id/deployments' do
|
|
|
|
context 'as member of the project' do
|
|
|
|
it_behaves_like 'a paginated resources' do
|
|
|
|
let(:request) { get v3_api("/projects/#{project.id}/deployments", user) }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns projects deployments' do
|
|
|
|
get v3_api("/projects/#{project.id}/deployments", user)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(json_response).to be_an Array
|
|
|
|
expect(json_response.size).to eq(1)
|
|
|
|
expect(json_response.first['iid']).to eq(deployment.iid)
|
|
|
|
expect(json_response.first['sha']).to match /\A\h{40}\z/
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'as non member' do
|
|
|
|
it 'returns a 404 status code' do
|
|
|
|
get v3_api("/projects/#{project.id}/deployments", non_member)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET /projects/:id/deployments/:deployment_id' do
|
|
|
|
context 'as a member of the project' do
|
|
|
|
it 'returns the projects deployment' do
|
|
|
|
get v3_api("/projects/#{project.id}/deployments/#{deployment.id}", user)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-08-17 22:00:37 +05:30
|
|
|
expect(json_response['sha']).to match /\A\h{40}\z/
|
|
|
|
expect(json_response['id']).to eq(deployment.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'as non member' do
|
|
|
|
it 'returns a 404 status code' do
|
|
|
|
get v3_api("/projects/#{project.id}/deployments/#{deployment.id}", non_member)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|