2020-04-21 15:21:10 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 09:08:32 +00:00
|
|
|
RSpec.describe Projects::AlertManagementHelper do
|
2020-04-21 15:21:10 +00:00
|
|
|
include Gitlab::Routing.url_helpers
|
|
|
|
|
2020-04-27 18:09:41 +00:00
|
|
|
let_it_be(:project, reload: true) { create(:project) }
|
|
|
|
let_it_be(:current_user) { create(:user) }
|
2021-04-19 18:09:09 +00:00
|
|
|
|
2020-06-17 09:08:38 +00:00
|
|
|
let(:project_path) { project.full_path }
|
|
|
|
let(:project_id) { project.id }
|
2020-04-21 15:21:10 +00:00
|
|
|
|
|
|
|
describe '#alert_management_data' do
|
2020-05-08 00:09:56 +00:00
|
|
|
let(:user_can_enable_alert_management) { true }
|
2020-07-13 15:09:08 +00:00
|
|
|
let(:setting_path) { project_settings_operations_path(project, anchor: 'js-alert-management-settings') }
|
2020-04-21 15:21:10 +00:00
|
|
|
|
2020-05-08 09:09:39 +00:00
|
|
|
subject(:data) { helper.alert_management_data(current_user, project) }
|
|
|
|
|
2020-04-27 18:09:41 +00:00
|
|
|
before do
|
|
|
|
allow(helper)
|
|
|
|
.to receive(:can?)
|
2020-06-27 00:09:17 +00:00
|
|
|
.with(current_user, :admin_operations, project)
|
2020-04-27 18:09:41 +00:00
|
|
|
.and_return(user_can_enable_alert_management)
|
|
|
|
end
|
|
|
|
|
2020-04-21 15:21:10 +00:00
|
|
|
context 'without alert_managements_setting' do
|
2020-05-06 15:09:42 +00:00
|
|
|
it 'returns index page configuration' do
|
2020-05-08 00:09:56 +00:00
|
|
|
expect(helper.alert_management_data(current_user, project)).to match(
|
2020-04-30 12:09:45 +00:00
|
|
|
'project-path' => project_path,
|
2020-04-21 15:21:10 +00:00
|
|
|
'enable-alert-management-path' => setting_path,
|
2021-02-06 21:09:10 +00:00
|
|
|
'alerts-help-url' => 'http://test.host/help/operations/incident_management/alerts.md',
|
|
|
|
'populating-alerts-help-url' => 'http://test.host/help/operations/incident_management/integrations.md#configuration',
|
2020-05-08 00:09:56 +00:00
|
|
|
'empty-alert-svg-path' => match_asset_path('/assets/illustrations/alert-management-empty-state.svg'),
|
|
|
|
'user-can-enable-alert-management' => 'true',
|
2020-10-15 18:08:43 +00:00
|
|
|
'alert-management-enabled' => 'false',
|
2021-05-12 18:10:35 +00:00
|
|
|
'has-managed-prometheus' => 'false',
|
2020-10-15 18:08:43 +00:00
|
|
|
'text-query': nil,
|
|
|
|
'assignee-username-query': nil
|
2020-04-21 15:21:10 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2020-05-08 00:09:56 +00:00
|
|
|
|
2021-06-18 21:10:06 +00:00
|
|
|
context 'with prometheus integration' do
|
|
|
|
let_it_be(:prometheus_integration) { create(:prometheus_integration, project: project) }
|
2020-06-18 00:08:35 +00:00
|
|
|
|
2021-06-18 21:10:06 +00:00
|
|
|
context 'when manual prometheus integration is active' do
|
2021-05-12 18:10:35 +00:00
|
|
|
it "enables alert management and doesn't show managed prometheus" do
|
2021-06-18 21:10:06 +00:00
|
|
|
prometheus_integration.update!(manual_configuration: true)
|
2021-05-12 18:10:35 +00:00
|
|
|
|
2020-06-18 00:08:35 +00:00
|
|
|
expect(data).to include(
|
|
|
|
'alert-management-enabled' => 'true'
|
|
|
|
)
|
2021-05-12 18:10:35 +00:00
|
|
|
expect(data).to include(
|
|
|
|
'has-managed-prometheus' => 'false'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a cluster prometheus is available' do
|
|
|
|
let(:cluster) { create(:cluster, projects: [project]) }
|
|
|
|
|
|
|
|
it 'has managed prometheus' do
|
2021-06-03 12:10:18 +00:00
|
|
|
create(:clusters_integrations_prometheus, cluster: cluster)
|
2021-05-12 18:10:35 +00:00
|
|
|
|
|
|
|
expect(data).to include(
|
|
|
|
'has-managed-prometheus' => 'true'
|
|
|
|
)
|
2020-06-18 00:08:35 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-18 21:10:06 +00:00
|
|
|
context 'when prometheus integration is inactive' do
|
2021-05-12 18:10:35 +00:00
|
|
|
it 'disables alert management and hides managed prometheus' do
|
2021-06-18 21:10:06 +00:00
|
|
|
prometheus_integration.update!(manual_configuration: false)
|
2020-06-18 00:08:35 +00:00
|
|
|
|
|
|
|
expect(data).to include(
|
|
|
|
'alert-management-enabled' => 'false'
|
|
|
|
)
|
2021-05-12 18:10:35 +00:00
|
|
|
expect(data).to include(
|
|
|
|
'has-managed-prometheus' => 'false'
|
|
|
|
)
|
2020-06-18 00:08:35 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-18 21:10:06 +00:00
|
|
|
context 'without prometheus integration' do
|
2021-05-12 18:10:35 +00:00
|
|
|
it "doesn't have managed prometheus" do
|
|
|
|
expect(data).to include(
|
|
|
|
'has-managed-prometheus' => 'false'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-11-20 18:09:37 +00:00
|
|
|
context 'with http integration' do
|
|
|
|
let_it_be(:integration) { create(:alert_management_http_integration, project: project) }
|
|
|
|
|
|
|
|
context 'when integration is active' do
|
|
|
|
it 'enables alert management' do
|
|
|
|
expect(data).to include(
|
|
|
|
'alert-management-enabled' => 'true'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when integration is inactive' do
|
|
|
|
it 'disables alert management' do
|
|
|
|
integration.update!(active: false)
|
|
|
|
|
|
|
|
expect(data).to include(
|
|
|
|
'alert-management-enabled' => 'false'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-12-08 03:09:37 +00:00
|
|
|
context 'with an alert' do
|
|
|
|
let_it_be(:alert) { create(:alert_management_alert, project: project) }
|
|
|
|
|
|
|
|
it 'enables alert management' do
|
|
|
|
expect(data).to include(
|
|
|
|
'alert-management-enabled' => 'true'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-08 00:09:56 +00:00
|
|
|
context 'when user does not have requisite enablement permissions' do
|
|
|
|
let(:user_can_enable_alert_management) { false }
|
|
|
|
|
|
|
|
it 'shows error tracking enablement as disabled' do
|
|
|
|
expect(helper.alert_management_data(current_user, project)).to include(
|
|
|
|
'user-can-enable-alert-management' => 'false'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2020-04-21 15:21:10 +00:00
|
|
|
end
|
2020-05-06 15:09:42 +00:00
|
|
|
|
|
|
|
describe '#alert_management_detail_data' do
|
|
|
|
let(:alert_id) { 1 }
|
2020-05-21 00:08:06 +00:00
|
|
|
let(:issues_path) { project_issues_path(project) }
|
2020-05-06 15:09:42 +00:00
|
|
|
|
|
|
|
it 'returns detail page configuration' do
|
2020-05-08 18:09:55 +00:00
|
|
|
expect(helper.alert_management_detail_data(project, alert_id)).to eq(
|
2020-05-06 15:09:42 +00:00
|
|
|
'alert-id' => alert_id,
|
2020-05-08 18:09:55 +00:00
|
|
|
'project-path' => project_path,
|
2020-06-17 09:08:38 +00:00
|
|
|
'project-id' => project_id,
|
2021-02-12 12:09:02 +00:00
|
|
|
'project-issues-path' => issues_path,
|
|
|
|
'page' => 'OPERATIONS'
|
2020-05-06 15:09:42 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
2020-04-21 15:21:10 +00:00
|
|
|
end
|