debian-mirror-gitlab/spec/helpers/projects/alert_management_helper_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

146 lines
4.6 KiB
Ruby
Raw Normal View History

2020-05-24 23:13:21 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Projects::AlertManagementHelper do
2020-05-24 23:13:21 +05:30
include Gitlab::Routing.url_helpers
let_it_be(:project, reload: true) { create(:project) }
let_it_be(:current_user) { create(:user) }
2021-04-29 21:17:54 +05:30
2020-07-28 23:09:34 +05:30
let(:project_path) { project.full_path }
let(:project_id) { project.id }
2020-05-24 23:13:21 +05:30
describe '#alert_management_data' do
let(:user_can_enable_alert_management) { true }
2020-07-28 23:09:34 +05:30
let(:setting_path) { project_settings_operations_path(project, anchor: 'js-alert-management-settings') }
2020-05-24 23:13:21 +05:30
subject(:data) { helper.alert_management_data(current_user, project) }
before do
allow(helper)
.to receive(:can?)
2020-07-28 23:09:34 +05:30
.with(current_user, :admin_operations, project)
2020-05-24 23:13:21 +05:30
.and_return(user_can_enable_alert_management)
end
context 'without alert_managements_setting' do
it 'returns index page configuration' do
expect(helper.alert_management_data(current_user, project)).to match(
'project-path' => project_path,
'enable-alert-management-path' => setting_path,
2021-03-11 19:13:27 +05:30
'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-24 23:13:21 +05:30
'empty-alert-svg-path' => match_asset_path('/assets/illustrations/alert-management-empty-state.svg'),
'user-can-enable-alert-management' => 'true',
2021-01-03 14:25:43 +05:30
'alert-management-enabled' => 'false',
'text-query': nil,
'assignee-username-query': nil
2020-05-24 23:13:21 +05:30
)
end
end
2021-09-30 23:02:18 +05:30
context 'with prometheus integration' do
let_it_be(:prometheus_integration) { create(:prometheus_integration, project: project) }
2020-07-28 23:09:34 +05:30
2021-09-30 23:02:18 +05:30
context 'when manual prometheus integration is active' do
2021-12-11 22:18:48 +05:30
it "enables alert management" do
2021-09-30 23:02:18 +05:30
prometheus_integration.update!(manual_configuration: true)
2021-06-08 01:23:25 +05:30
2020-07-28 23:09:34 +05:30
expect(data).to include(
'alert-management-enabled' => 'true'
)
end
end
2021-12-11 22:18:48 +05:30
context 'when prometheus service is inactive' do
it 'disables alert management' do
2021-09-30 23:02:18 +05:30
prometheus_integration.update!(manual_configuration: false)
2020-07-28 23:09:34 +05:30
expect(data).to include(
'alert-management-enabled' => 'false'
)
end
end
end
2021-01-29 00:20:46 +05:30
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
2021-02-22 17:27:13 +05:30
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-24 23:13:21 +05:30
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
end
describe '#alert_management_detail_data' do
let(:alert_id) { 1 }
2020-06-23 00:09:42 +05:30
let(:issues_path) { project_issues_path(project) }
2023-01-13 00:05:48 +05:30
let(:details_alert_management_path) { details_project_alert_management_path(project, alert_id) }
2022-06-21 17:19:12 +05:30
let(:can_update_alert) { true }
before do
allow(helper)
.to receive(:can?)
.with(current_user, :update_alert_management_alert, project)
.and_return(can_update_alert)
end
2020-05-24 23:13:21 +05:30
it 'returns detail page configuration' do
2022-06-21 17:19:12 +05:30
expect(helper.alert_management_detail_data(current_user, project, alert_id)).to eq(
2020-05-24 23:13:21 +05:30
'alert-id' => alert_id,
'project-path' => project_path,
2020-07-28 23:09:34 +05:30
'project-id' => project_id,
2021-03-11 19:13:27 +05:30
'project-issues-path' => issues_path,
2023-01-13 00:05:48 +05:30
'project-alert-management-details-path' => details_alert_management_path,
2022-06-21 17:19:12 +05:30
'page' => 'OPERATIONS',
'can-update' => 'true'
2020-05-24 23:13:21 +05:30
)
end
2022-06-21 17:19:12 +05:30
context 'when user cannot update alert' do
let(:can_update_alert) { false }
it 'shows error tracking enablement as disabled' do
expect(helper.alert_management_detail_data(current_user, project, alert_id)).to include(
'can-update' => 'false'
)
end
end
2020-05-24 23:13:21 +05:30
end
end