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

92 lines
2.9 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2018-12-13 13:39:08 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe EnvironmentStatusEntity do
2022-11-25 23:54:43 +05:30
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 }
2020-01-01 13:55:28 +05:30
let(:request) { double('request', project: project) }
2019-09-30 21:07:59 +05:30
let(:environment_status) { EnvironmentStatus.new(project, environment, merge_request, merge_request.diff_head_sha) }
2022-11-25 23:54:43 +05:30
let(:entity) { described_class.new(environment_status, request: request) }
2018-12-13 13:39:08 +05:30
subject { entity.as_json }
2022-11-25 23:54:43 +05:30
before_all do
project.add_maintainer(maintainer)
2020-11-24 15:15:51 +05:30
deployment.update!(sha: merge_request.diff_head_sha)
2022-11-25 23:54:43 +05:30
end
before do
2018-12-13 13:39:08 +05:30
allow(request).to receive(:current_user).and_return(user)
end
it { is_expected.to include(:id) }
it { is_expected.to include(:name) }
it { is_expected.to include(:url) }
it { is_expected.to include(:external_url) }
it { is_expected.to include(:external_url_formatted) }
it { is_expected.to include(:deployed_at) }
it { is_expected.to include(:deployed_at_formatted) }
2020-01-01 13:55:28 +05:30
it { is_expected.to include(:details) }
2018-12-13 13:39:08 +05:30
it { is_expected.to include(:changes) }
it { is_expected.to include(:status) }
it { is_expected.not_to include(:stop_url) }
it { is_expected.not_to include(:metrics_url) }
it { is_expected.not_to include(:metrics_monitoring_url) }
context 'when the user is project maintainer' do
2022-11-25 23:54:43 +05:30
let(:user) { maintainer }
2018-12-13 13:39:08 +05:30
it { is_expected.to include(:stop_url) }
end
context 'when deployment has metrics' do
2022-11-25 23:54:43 +05:30
let(:user) { maintainer }
2020-03-13 15:44:24 +05:30
let(:prometheus_adapter) { double('prometheus_adapter', can_query?: true, configured?: true) }
2018-12-13 13:39:08 +05:30
let(:simple_metrics) do
{
success: true,
metrics: {},
last_update: 42
}
end
before do
allow(deployment).to receive(:prometheus_adapter).and_return(prometheus_adapter)
allow(entity).to receive(:deployment).and_return(deployment)
2019-09-30 21:07:59 +05:30
expect_next_instance_of(DeploymentMetrics) do |deployment_metrics|
allow(deployment_metrics).to receive(:prometheus_adapter).and_return(prometheus_adapter)
allow(prometheus_adapter).to receive(:query)
.with(:deployment, deployment).and_return(simple_metrics)
end
2018-12-13 13:39:08 +05:30
end
context 'when deployment succeeded' do
it 'returns metrics url' do
expect(subject[:metrics_url])
2020-01-01 13:55:28 +05:30
.to eq("/#{project.full_path}/-/environments/#{environment.id}/deployments/#{deployment.iid}/metrics")
2018-12-13 13:39:08 +05:30
end
end
context 'when deployment is running' do
2022-11-25 23:54:43 +05:30
before do
deployment.update!(status: :running)
end
2018-12-13 13:39:08 +05:30
it 'does not return metrics url' do
expect(subject[:metrics_url]).to be_nil
end
end
end
end