debian-mirror-gitlab/spec/serializers/deployment_entity_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

169 lines
5.4 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe DeploymentEntity do
2022-11-25 23:54:43 +05:30
let_it_be(:developer) { create(:user) }
let_it_be(:reporter) { create(:user) }
let_it_be(:user) { developer }
let_it_be(:project) { create(:project, :repository) }
let_it_be(:environment) { create(:environment, project: project) }
let_it_be_with_reload(:pipeline) { create(:ci_pipeline, project: project, user: user) }
let_it_be_with_reload(:build) { create(:ci_build, :manual, :environment_with_deployment_tier, pipeline: pipeline) }
let_it_be_with_refind(:deployment) { create(:deployment, deployable: build, environment: environment) }
2017-08-17 22:00:37 +05:30
let(:request) { double('request') }
let(:entity) { described_class.new(deployment, request: request) }
2019-09-04 21:01:54 +05:30
2017-08-17 22:00:37 +05:30
subject { entity.as_json }
2022-11-25 23:54:43 +05:30
before_all do
2019-03-02 22:35:43 +05:30
project.add_developer(developer)
project.add_reporter(reporter)
2022-11-25 23:54:43 +05:30
end
before do
2017-08-17 22:00:37 +05:30
allow(request).to receive(:current_user).and_return(user)
2019-03-02 22:35:43 +05:30
allow(request).to receive(:project).and_return(project)
2017-08-17 22:00:37 +05:30
end
2022-11-25 23:54:43 +05:30
it 'exposes fields', :aggregate_failures do
2017-08-17 22:00:37 +05:30
expect(subject).to include(:iid)
expect(subject[:ref][:name]).to eq 'master'
2021-01-03 14:25:43 +05:30
expect(subject).to include(:status)
2017-08-17 22:00:37 +05:30
expect(subject).to include(:created_at)
2019-12-04 20:38:33 +05:30
expect(subject).to include(:deployed_at)
2022-01-26 12:08:38 +05:30
expect(subject).to include(:is_last)
2022-06-21 17:19:12 +05:30
expect(subject).to include(:tier_in_yaml)
end
2019-12-04 20:38:33 +05:30
context 'when deployable is nil' do
let(:entity) { described_class.new(deployment, request: request, deployment_details: false) }
2022-11-25 23:54:43 +05:30
before do
deployment.update!(deployable: nil)
end
2019-12-04 20:38:33 +05:30
it 'does not expose deployable entry' do
expect(subject).not_to include(:deployable)
end
2019-10-12 21:52:04 +05:30
end
2019-03-02 22:35:43 +05:30
context 'when the pipeline has another manual action' do
2022-11-25 23:54:43 +05:30
let_it_be(:other_build) do
2022-10-11 01:57:18 +05:30
create(:ci_build, :manual, name: 'another deploy', pipeline: pipeline, environment: build.environment)
2022-07-23 23:45:48 +05:30
end
2022-11-25 23:54:43 +05:30
let_it_be(:other_deployment) { create(:deployment, deployable: build, environment: environment) }
2019-03-02 22:35:43 +05:30
it 'returns another manual action' do
2022-11-25 23:54:43 +05:30
expect(subject[:manual_actions].count).to eq(1)
expect(subject[:manual_actions].pluck(:name)).to match_array(['another deploy'])
2019-03-02 22:35:43 +05:30
end
context 'when user is a reporter' do
2022-11-25 23:54:43 +05:30
let_it_be(:user) { reporter }
2019-03-02 22:35:43 +05:30
it 'returns another manual action' do
expect(subject[:manual_actions]).not_to be_present
end
end
2019-09-04 21:01:54 +05:30
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-03-02 22:35:43 +05:30
end
2018-12-13 13:39:08 +05:30
describe 'scheduled_actions' do
let(:build) { create(:ci_build, :success, pipeline: pipeline) }
2022-11-25 23:54:43 +05:30
before do
deployment.update!(deployable: build)
end
2018-12-13 13:39:08 +05:30
context 'when the same pipeline has a scheduled action' do
let(:other_build) { create(:ci_build, :schedulable, :success, pipeline: pipeline, name: 'other build') }
2022-11-25 23:54:43 +05:30
let!(:other_deployment) { create(:deployment, deployable: other_build, environment: environment) }
2018-12-13 13:39:08 +05:30
it 'returns other scheduled actions' do
expect(subject[:scheduled_actions][0][:name]).to eq 'other build'
end
end
context 'when the same pipeline does not have a scheduled action' do
it 'does not return other actions' do
expect(subject[:scheduled_actions]).to be_empty
end
end
2019-09-04 21:01:54 +05:30
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
2020-01-01 13:55:28 +05:30
describe 'playable_build' do
2022-11-25 23:54:43 +05:30
before do
deployment.update!(deployable: build)
end
2020-01-01 13:55:28 +05:30
context 'when the deployment has a playable deployable' do
context 'when this build is ready to be played' do
let(:build) { create(:ci_build, :playable, :scheduled, pipeline: pipeline) }
it 'exposes only the play_path' do
expect(subject[:playable_build].keys).to contain_exactly(:play_path)
end
end
context 'when this build has failed' do
let(:build) { create(:ci_build, :playable, :failed, pipeline: pipeline) }
it 'exposes the play_path and the retry_path' do
expect(subject[:playable_build].keys).to contain_exactly(:play_path, :retry_path)
end
end
end
context 'when the deployment does not have a playable deployable' do
2022-11-25 23:54:43 +05:30
let(:build) { create(:ci_build, pipeline: pipeline) }
2020-01-01 13:55:28 +05:30
it 'is not exposed' do
expect(subject[:playable_build]).to be_nil
end
end
end
2019-09-04 21:01:54 +05:30
context 'when deployment details serialization was disabled' do
include Gitlab::Routing
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)
.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))
.to eq(name: 'test', build_path: path)
end
end
2018-12-13 13:39:08 +05:30
end
2017-08-17 22:00:37 +05:30
end