2020-03-13 15:44:24 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe GitlabSchema.types['Environment'] do
|
2020-05-24 23:13:21 +05:30
|
|
|
specify { expect(described_class.graphql_name).to eq('Environment') }
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
it 'has the expected fields' do
|
|
|
|
expected_fields = %w[
|
2021-01-03 14:25:43 +05:30
|
|
|
name id state metrics_dashboard latest_opened_most_severe_alert path
|
2020-03-13 15:44:24 +05:30
|
|
|
]
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
expect(described_class).to have_graphql_fields(*expected_fields)
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
specify { expect(described_class).to require_graphql_authorizations(:read_environment) }
|
2020-10-24 23:57:45 +05:30
|
|
|
|
|
|
|
context 'when there is an environment' do
|
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
let_it_be(:environment) { create(:environment, project: project) }
|
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
|
|
|
|
subject { GitlabSchema.execute(query, context: { current_user: user }).as_json }
|
|
|
|
|
|
|
|
let(:query) do
|
|
|
|
%(
|
|
|
|
query {
|
|
|
|
project(fullPath: "#{project.full_path}") {
|
|
|
|
environment(name: "#{environment.name}") {
|
|
|
|
name
|
2021-01-03 14:25:43 +05:30
|
|
|
path
|
2020-10-24 23:57:45 +05:30
|
|
|
state
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an environment' do
|
|
|
|
expect(subject['data']['project']['environment']['name']).to eq(environment.name)
|
|
|
|
end
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
it 'returns the path when the feature is enabled' do
|
|
|
|
expect(subject['data']['project']['environment']['path']).to eq(
|
|
|
|
Gitlab::Routing.url_helpers.project_environment_path(project, environment)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not return the path when the feature is disabled' do
|
|
|
|
stub_feature_flags(expose_environment_path_in_alert_details: false)
|
|
|
|
|
|
|
|
expect(subject['data']['project']['environment']['path']).to be_nil
|
|
|
|
end
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
context 'when query alert data for the environment' do
|
|
|
|
let_it_be(:query) do
|
|
|
|
%(
|
|
|
|
query {
|
|
|
|
project(fullPath: "#{project.full_path}") {
|
|
|
|
environment(name: "#{environment.name}") {
|
|
|
|
name
|
|
|
|
state
|
|
|
|
latestOpenedMostSevereAlert {
|
|
|
|
severity
|
|
|
|
title
|
|
|
|
detailsUrl
|
|
|
|
prometheusAlert {
|
|
|
|
humanizedText
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not return alert information' do
|
|
|
|
expect(subject['data']['project']['environment']['latestOpenedMostSevereAlert']).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when alert is raised on the environment' do
|
|
|
|
let!(:prometheus_alert) { create(:prometheus_alert, project: project, environment: environment) }
|
|
|
|
let!(:alert) { create(:alert_management_alert, :triggered, :prometheus, project: project, environment: environment, prometheus_alert: prometheus_alert) }
|
|
|
|
|
|
|
|
it 'returns alert information' do
|
|
|
|
expect(subject['data']['project']['environment']['latestOpenedMostSevereAlert']['severity']).to eq(alert.severity.upcase)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|