summaryrefslogtreecommitdiff
path: root/qa/qa/specs/features/browser_ui/8_monitor/alert_management/create_alert_using_authorization_key_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'qa/qa/specs/features/browser_ui/8_monitor/alert_management/create_alert_using_authorization_key_spec.rb')
-rw-r--r--qa/qa/specs/features/browser_ui/8_monitor/alert_management/create_alert_using_authorization_key_spec.rb98
1 files changed, 98 insertions, 0 deletions
diff --git a/qa/qa/specs/features/browser_ui/8_monitor/alert_management/create_alert_using_authorization_key_spec.rb b/qa/qa/specs/features/browser_ui/8_monitor/alert_management/create_alert_using_authorization_key_spec.rb
new file mode 100644
index 00000000000..9d4aff59e48
--- /dev/null
+++ b/qa/qa/specs/features/browser_ui/8_monitor/alert_management/create_alert_using_authorization_key_spec.rb
@@ -0,0 +1,98 @@
+# frozen_string_literal: true
+
+module QA
+ RSpec.describe 'Monitor', product_group: :respond do
+ describe 'Alert settings' do
+ shared_examples 'sends test alert using authorization key' do |type|
+ it 'creates new alert', :aggregate_failures do
+ response = RestClient.post(
+ credentials[:url],
+ payload.to_json,
+ { 'Content-Type': 'application/json', Authorization: "Bearer #{credentials[:auth_key]}" }
+ )
+
+ # With HTTP type, a successful request returns 200 and a JSON with the alert's title
+ # With Prometheus type, a successful request returns 201
+ if type == 'http'
+ expect(response.code).to eq 200
+ expect(JSON.parse(response).first['title']).to eq alert_title
+ else
+ expect(response.code).to eq 201
+ end
+
+ Page::Project::Menu.perform(&:go_to_monitor_alerts)
+ Page::Project::Monitor::Alerts::Index.perform do |index|
+ expect(index).to have_alert_with_title(alert_title)
+ end
+ end
+ end
+
+ let(:project) do
+ Resource::Project.fabricate_via_api! do |project|
+ project.name = 'project-for-alerts'
+ project.description = 'Project for alerts'
+ end
+ end
+
+ let(:alert_title) { Faker::Lorem.word }
+
+ before do
+ Flow::Login.sign_in
+ project.visit!
+ end
+
+ context(
+ 'when using HTTP endpoint integration',
+ testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/386734'
+ ) do
+ let(:payload) do
+ { title: alert_title, description: alert_title }
+ end
+
+ let(:credentials) do
+ Flow::AlertSettings.setup_http_endpoint(send: false)
+ end
+
+ it_behaves_like 'sends test alert using authorization key', 'http'
+ end
+
+ context(
+ 'when using Prometheus integration',
+ testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/386735'
+ ) do
+ let(:payload) do
+ {
+ version: '4',
+ groupKey: nil,
+ status: 'firing',
+ receiver: '',
+ groupLabels: {},
+ commonLabels: {},
+ commonAnnotations: {},
+ externalURL: '',
+ alerts: [
+ {
+ startsAt: Time.now,
+ generatorURL: Faker::Internet.url,
+ endsAt: nil,
+ status: 'firing',
+ labels: { gitlab_environment_name: Faker::Lorem.word },
+ annotations:
+ {
+ title: alert_title,
+ gitlab_y_label: 'status'
+ }
+ }
+ ]
+ }
+ end
+
+ let(:credentials) do
+ Flow::AlertSettings.setup_prometheus(send: false)
+ end
+
+ it_behaves_like 'sends test alert using authorization key'
+ end
+ end
+ end
+end