2016-08-16 02:45:23 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-04-21 16:32:02 -04:00
|
|
|
describe API::Deployments do
|
2016-08-16 02:45:23 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:non_member) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
2017-12-22 03:18:28 -05:00
|
|
|
project.add_master(user)
|
2016-08-16 02:45:23 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET /projects/:id/deployments' do
|
2018-01-11 11:45:35 -05:00
|
|
|
let(:project) { create(:project) }
|
|
|
|
let!(:deployment_1) { create(:deployment, project: project, iid: 11, ref: 'master', created_at: Time.now) }
|
|
|
|
let!(:deployment_2) { create(:deployment, project: project, iid: 12, ref: 'feature', created_at: 1.day.ago) }
|
|
|
|
let!(:deployment_3) { create(:deployment, project: project, iid: 8, ref: 'feature', created_at: 2.days.ago) }
|
|
|
|
|
2016-08-16 02:45:23 -04:00
|
|
|
context 'as member of the project' do
|
2018-01-11 11:45:35 -05:00
|
|
|
it 'returns projects deployments sorted by id asc' do
|
2016-08-16 02:45:23 -04:00
|
|
|
get api("/projects/#{project.id}/deployments", user)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-01-24 15:49:10 -05:00
|
|
|
expect(response).to include_pagination_headers
|
2016-08-16 02:45:23 -04:00
|
|
|
expect(json_response).to be_an Array
|
2018-01-11 11:45:35 -05:00
|
|
|
expect(json_response.size).to eq(3)
|
|
|
|
expect(json_response.first['iid']).to eq(deployment_1.iid)
|
2016-08-16 02:45:23 -04:00
|
|
|
expect(json_response.first['sha']).to match /\A\h{40}\z/
|
2018-01-11 11:45:35 -05:00
|
|
|
expect(json_response.second['iid']).to eq(deployment_2.iid)
|
|
|
|
expect(json_response.last['iid']).to eq(deployment_3.iid)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'ordering' do
|
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
|
|
|
let(:order_by) { nil }
|
|
|
|
let(:sort) { nil }
|
|
|
|
|
|
|
|
subject { get api("/projects/#{project.id}/deployments?order_by=#{order_by}&sort=#{sort}", user) }
|
|
|
|
|
|
|
|
def expect_deployments(ordered_deployments)
|
|
|
|
json_response.each_with_index do |deployment_json, index|
|
|
|
|
expect(deployment_json['id']).to eq(public_send(ordered_deployments[index]).id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
where(:order_by, :sort, :ordered_deployments) do
|
|
|
|
'created_at' | 'asc' | [:deployment_3, :deployment_2, :deployment_1]
|
|
|
|
'created_at' | 'desc' | [:deployment_1, :deployment_2, :deployment_3]
|
|
|
|
'id' | 'asc' | [:deployment_1, :deployment_2, :deployment_3]
|
|
|
|
'id' | 'desc' | [:deployment_3, :deployment_2, :deployment_1]
|
|
|
|
'iid' | 'asc' | [:deployment_3, :deployment_1, :deployment_2]
|
|
|
|
'iid' | 'desc' | [:deployment_2, :deployment_1, :deployment_3]
|
|
|
|
'ref' | 'asc' | [:deployment_2, :deployment_3, :deployment_1]
|
|
|
|
'ref' | 'desc' | [:deployment_1, :deployment_2, :deployment_3]
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
it 'returns the deployments ordered' do
|
|
|
|
expect_deployments(ordered_deployments)
|
|
|
|
end
|
|
|
|
end
|
2016-08-16 02:45:23 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'as non member' do
|
|
|
|
it 'returns a 404 status code' do
|
|
|
|
get api("/projects/#{project.id}/deployments", non_member)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-08-16 02:45:23 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET /projects/:id/deployments/:deployment_id' do
|
2018-01-11 11:45:35 -05:00
|
|
|
let(:project) { deployment.environment.project }
|
|
|
|
let!(:deployment) { create(:deployment) }
|
|
|
|
|
2016-08-16 02:45:23 -04:00
|
|
|
context 'as a member of the project' do
|
|
|
|
it 'returns the projects deployment' do
|
|
|
|
get api("/projects/#{project.id}/deployments/#{deployment.id}", user)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2016-08-16 02:45:23 -04:00
|
|
|
expect(json_response['sha']).to match /\A\h{40}\z/
|
2016-08-16 04:11:32 -04:00
|
|
|
expect(json_response['id']).to eq(deployment.id)
|
2016-08-16 02:45:23 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'as non member' do
|
|
|
|
it 'returns a 404 status code' do
|
|
|
|
get api("/projects/#{project.id}/deployments/#{deployment.id}", non_member)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2016-08-16 02:45:23 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|