diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-10-20 12:40:42 +0300 |
commit | ee664acb356f8123f4f6b00b73c1e1cf0866c7fb (patch) | |
tree | f8479f94a28f66654c6a4f6fb99bad6b4e86a40e /spec/serializers/environment_status_entity_spec.rb | |
parent | 62f7d5c5b69180e82ae8196b7b429eeffc8e7b4f (diff) |
Add latest changes from gitlab-org/gitlab@15-5-stable-eev15.5.0-rc42
Diffstat (limited to 'spec/serializers/environment_status_entity_spec.rb')
-rw-r--r-- | spec/serializers/environment_status_entity_spec.rb | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/spec/serializers/environment_status_entity_spec.rb b/spec/serializers/environment_status_entity_spec.rb index 77ef06f90c2..2ee4e8ade8f 100644 --- a/spec/serializers/environment_status_entity_spec.rb +++ b/spec/serializers/environment_status_entity_spec.rb @@ -3,21 +3,26 @@ require 'spec_helper' RSpec.describe EnvironmentStatusEntity do - let(:user) { create(:user) } + let_it_be(:non_member) { create(:user) } + let_it_be(:maintainer) { create(:user) } + let_it_be(:deployment) { create(:deployment, :succeed, :review_app) } + let_it_be(:merge_request) { create(:merge_request, :deployed_review_app, deployment: deployment) } + let_it_be(:environment) { deployment.environment } + let_it_be(:project) { deployment.project } + + let(:user) { non_member } let(:request) { double('request', project: project) } - - let(:deployment) { create(:deployment, :succeed, :review_app) } - let(:environment) { deployment.environment } - let(:project) { deployment.project } - let(:merge_request) { create(:merge_request, :deployed_review_app, deployment: deployment) } - let(:environment_status) { EnvironmentStatus.new(project, environment, merge_request, merge_request.diff_head_sha) } - let(:entity) { described_class.new(environment_status, request: request) } + let(:entity) { described_class.new(environment_status, request: request) } subject { entity.as_json } - before do + before_all do + project.add_maintainer(maintainer) deployment.update!(sha: merge_request.diff_head_sha) + end + + before do allow(request).to receive(:current_user).and_return(user) end @@ -37,14 +42,13 @@ RSpec.describe EnvironmentStatusEntity do it { is_expected.not_to include(:metrics_monitoring_url) } context 'when the user is project maintainer' do - before do - project.add_maintainer(user) - end + let(:user) { maintainer } it { is_expected.to include(:stop_url) } end context 'when deployment has metrics' do + let(:user) { maintainer } let(:prometheus_adapter) { double('prometheus_adapter', can_query?: true, configured?: true) } let(:simple_metrics) do @@ -56,7 +60,6 @@ RSpec.describe EnvironmentStatusEntity do end before do - project.add_maintainer(user) allow(deployment).to receive(:prometheus_adapter).and_return(prometheus_adapter) allow(entity).to receive(:deployment).and_return(deployment) @@ -69,8 +72,6 @@ RSpec.describe EnvironmentStatusEntity do end context 'when deployment succeeded' do - let(:deployment) { create(:deployment, :succeed, :review_app) } - it 'returns metrics url' do expect(subject[:metrics_url]) .to eq("/#{project.full_path}/-/environments/#{environment.id}/deployments/#{deployment.iid}/metrics") @@ -78,7 +79,9 @@ RSpec.describe EnvironmentStatusEntity do end context 'when deployment is running' do - let(:deployment) { create(:deployment, :running, :review_app) } + before do + deployment.update!(status: :running) + end it 'does not return metrics url' do expect(subject[:metrics_url]).to be_nil |