diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /spec/serializers/environment_entity_spec.rb | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'spec/serializers/environment_entity_spec.rb')
-rw-r--r-- | spec/serializers/environment_entity_spec.rb | 58 |
1 files changed, 54 insertions, 4 deletions
diff --git a/spec/serializers/environment_entity_spec.rb b/spec/serializers/environment_entity_spec.rb index f5d6706a844..5b83507b4ec 100644 --- a/spec/serializers/environment_entity_spec.rb +++ b/spec/serializers/environment_entity_spec.rb @@ -7,15 +7,20 @@ RSpec.describe EnvironmentEntity do let(:request) { double('request') } let(:entity) do - described_class.new(environment, request: spy('request')) + described_class.new(environment, request: request) end let_it_be(:user) { create(:user) } - let_it_be(:project) { create(:project) } - let_it_be(:environment) { create(:environment, project: project) } + let_it_be(:project) { create(:project, :repository) } + let_it_be(:environment, refind: true) { create(:environment, project: project) } + + before_all do + project.add_developer(user) + end before do - allow(entity).to receive(:current_user).and_return(user) + allow(request).to receive(:current_user).and_return(user) + allow(request).to receive(:project).and_return(project) end subject { entity.as_json } @@ -32,6 +37,51 @@ RSpec.describe EnvironmentEntity do expect(subject).to include(:folder_path) end + context 'when there is a successful deployment' do + let!(:pipeline) { create(:ci_pipeline, :success, project: project) } + let!(:deployable) { create(:ci_build, :success, project: project, pipeline: pipeline) } + let!(:deployment) { create(:deployment, :success, project: project, environment: environment, deployable: deployable) } + + it 'exposes it as the latest deployment' do + expect(subject[:last_deployment][:sha]).to eq(deployment.sha) + end + + it 'does not expose it as an upcoming deployment' do + expect(subject[:upcoming_deployment]).to be_nil + end + + context 'when the deployment pipeline has the other manual job' do + let!(:manual_job) { create(:ci_build, :manual, name: 'stop-review', project: project, pipeline: pipeline) } + + it 'exposes the manual job in the latest deployment' do + expect(subject[:last_deployment][:manual_actions].first[:name]) + .to eq(manual_job.name) + end + end + end + + context 'when there is a running deployment' do + let!(:pipeline) { create(:ci_pipeline, :running, project: project) } + let!(:deployable) { create(:ci_build, :running, project: project, pipeline: pipeline) } + let!(:deployment) { create(:deployment, :running, project: project, environment: environment, deployable: deployable) } + + it 'does not expose it as the latest deployment' do + expect(subject[:last_deployment]).to be_nil + end + + it 'exposes it as an upcoming deployment' do + expect(subject[:upcoming_deployment][:sha]).to eq(deployment.sha) + end + + context 'when the deployment pipeline has the other manual job' do + let!(:manual_job) { create(:ci_build, :manual, name: 'stop-review', project: project, pipeline: pipeline) } + + it 'does not expose the manual job in the latest deployment' do + expect(subject[:upcoming_deployment][:manual_actions]).to be_nil + end + end + end + context 'metrics disabled' do before do allow(environment).to receive(:has_metrics?).and_return(false) |