2019-09-30 05:06:31 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-04 08:23:06 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-04-20 06:21:24 -04:00
|
|
|
describe DeploymentEntity do
|
2019-02-08 07:53:35 -05:00
|
|
|
let(:user) { developer }
|
|
|
|
let(:developer) { create(:user) }
|
|
|
|
let(:reporter) { create(:user) }
|
|
|
|
let(:project) { create(:project) }
|
2017-03-06 13:22:23 -05:00
|
|
|
let(:request) { double('request') }
|
2019-02-08 07:53:35 -05:00
|
|
|
let(:deployment) { create(:deployment, deployable: build, project: project) }
|
|
|
|
let(:build) { create(:ci_build, :manual, pipeline: pipeline) }
|
|
|
|
let(:pipeline) { create(:ci_pipeline, project: project, user: user) }
|
2017-04-20 06:21:24 -04:00
|
|
|
let(:entity) { described_class.new(deployment, request: request) }
|
2019-05-06 11:30:57 -04:00
|
|
|
|
2017-04-20 06:21:24 -04:00
|
|
|
subject { entity.as_json }
|
2017-03-06 13:22:23 -05:00
|
|
|
|
|
|
|
before do
|
2019-02-08 07:53:35 -05:00
|
|
|
project.add_developer(developer)
|
|
|
|
project.add_reporter(reporter)
|
2017-05-09 00:15:34 -04:00
|
|
|
allow(request).to receive(:current_user).and_return(user)
|
2019-02-08 07:53:35 -05:00
|
|
|
allow(request).to receive(:project).and_return(project)
|
2017-03-06 13:22:23 -05:00
|
|
|
end
|
2017-03-11 12:22:08 -05:00
|
|
|
|
2019-01-16 07:09:29 -05:00
|
|
|
it 'exposes internal deployment id' do
|
2016-11-04 08:23:06 -04:00
|
|
|
expect(subject).to include(:iid)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'exposes nested information about branch' do
|
|
|
|
expect(subject[:ref][:name]).to eq 'master'
|
|
|
|
end
|
2017-03-28 06:48:53 -04:00
|
|
|
|
|
|
|
it 'exposes creation date' do
|
|
|
|
expect(subject).to include(:created_at)
|
|
|
|
end
|
2018-10-09 21:47:31 -04:00
|
|
|
|
2019-08-20 05:28:55 -04:00
|
|
|
it 'exposes deployed_at' do
|
|
|
|
expect(subject).to include(:deployed_at)
|
2019-08-14 07:17:13 -04:00
|
|
|
end
|
|
|
|
|
2019-08-26 23:51:28 -04:00
|
|
|
context 'when deployable is nil' do
|
|
|
|
let(:entity) { described_class.new(deployment, request: request, deployment_details: false) }
|
|
|
|
let(:deployment) { create(:deployment, deployable: nil, project: project) }
|
|
|
|
|
|
|
|
it 'does not expose deployable entry' do
|
|
|
|
expect(subject).not_to include(:deployable)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-08 07:53:35 -05:00
|
|
|
context 'when the pipeline has another manual action' do
|
|
|
|
let(:other_build) { create(:ci_build, :manual, name: 'another deploy', pipeline: pipeline) }
|
|
|
|
let!(:other_deployment) { create(:deployment, deployable: other_build) }
|
|
|
|
|
|
|
|
it 'returns another manual action' do
|
|
|
|
expect(subject[:manual_actions].count).to eq(1)
|
|
|
|
expect(subject[:manual_actions].first[:name]).to eq('another deploy')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is a reporter' do
|
|
|
|
let(:user) { reporter }
|
|
|
|
|
|
|
|
it 'returns another manual action' do
|
|
|
|
expect(subject[:manual_actions]).not_to be_present
|
|
|
|
end
|
|
|
|
end
|
2019-05-06 11:30:57 -04:00
|
|
|
|
|
|
|
context 'when deployment details serialization was disabled' do
|
|
|
|
let(:entity) do
|
|
|
|
described_class.new(deployment, request: request, deployment_details: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not serialize manual actions details' do
|
|
|
|
expect(subject.with_indifferent_access).not_to include(:manual_actions)
|
|
|
|
end
|
|
|
|
end
|
2019-02-08 07:53:35 -05:00
|
|
|
end
|
|
|
|
|
2018-10-09 21:47:31 -04:00
|
|
|
describe 'scheduled_actions' do
|
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:pipeline) { create(:ci_pipeline, project: project, user: user) }
|
|
|
|
let(:build) { create(:ci_build, :success, pipeline: pipeline) }
|
|
|
|
let(:deployment) { create(:deployment, deployable: build) }
|
|
|
|
|
2018-10-11 22:22:19 -04:00
|
|
|
context 'when the same pipeline has a scheduled action' do
|
|
|
|
let(:other_build) { create(:ci_build, :schedulable, :success, pipeline: pipeline, name: 'other build') }
|
2018-10-09 21:47:31 -04:00
|
|
|
let!(:other_deployment) { create(:deployment, deployable: other_build) }
|
|
|
|
|
2018-10-11 22:22:19 -04:00
|
|
|
it 'returns other scheduled actions' do
|
2018-10-09 21:47:31 -04:00
|
|
|
expect(subject[:scheduled_actions][0][:name]).to eq 'other build'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-10-11 22:22:19 -04:00
|
|
|
context 'when the same pipeline does not have a scheduled action' do
|
2018-10-09 21:47:31 -04:00
|
|
|
it 'does not return other actions' do
|
|
|
|
expect(subject[:scheduled_actions]).to be_empty
|
|
|
|
end
|
|
|
|
end
|
2019-05-06 11:30:57 -04:00
|
|
|
|
|
|
|
context 'when deployment details serialization was disabled' do
|
|
|
|
let(:entity) do
|
|
|
|
described_class.new(deployment, request: request, deployment_details: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not serialize scheduled actions details' do
|
|
|
|
expect(subject.with_indifferent_access).not_to include(:scheduled_actions)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when deployment details serialization was disabled' do
|
2019-05-10 13:02:00 -04:00
|
|
|
include Gitlab::Routing
|
|
|
|
|
2019-05-06 11:30:57 -04:00
|
|
|
let(:entity) do
|
|
|
|
described_class.new(deployment, request: request, deployment_details: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not serialize deployment details' do
|
|
|
|
expect(subject.with_indifferent_access)
|
2019-05-10 13:02:00 -04:00
|
|
|
.not_to include(:commit, :manual_actions, :scheduled_actions)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'only exposes deployable name and path' do
|
|
|
|
project_job_path(project, deployment.deployable).tap do |path|
|
|
|
|
expect(subject.fetch(:deployable))
|
2019-05-13 10:30:40 -04:00
|
|
|
.to eq(name: 'test', build_path: path)
|
2019-05-10 13:02:00 -04:00
|
|
|
end
|
2019-05-06 11:30:57 -04:00
|
|
|
end
|
2018-10-09 21:47:31 -04:00
|
|
|
end
|
2016-11-04 08:23:06 -04:00
|
|
|
end
|