Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/alert_management/http_integration_spec.rb')
-rw-r--r--spec/models/alert_management/http_integration_spec.rb83
1 files changed, 75 insertions, 8 deletions
diff --git a/spec/models/alert_management/http_integration_spec.rb b/spec/models/alert_management/http_integration_spec.rb
index 37d67dfe09a..a3e7b47c116 100644
--- a/spec/models/alert_management/http_integration_spec.rb
+++ b/spec/models/alert_management/http_integration_spec.rb
@@ -3,6 +3,8 @@
require 'spec_helper'
RSpec.describe AlertManagement::HttpIntegration do
+ include ::Gitlab::Routing.url_helpers
+
let_it_be(:project) { create(:project) }
subject(:integration) { build(:alert_management_http_integration) }
@@ -15,19 +17,17 @@ RSpec.describe AlertManagement::HttpIntegration do
it { is_expected.to validate_presence_of(:project) }
it { is_expected.to validate_presence_of(:name) }
it { is_expected.to validate_length_of(:name).is_at_most(255) }
- it { is_expected.to validate_presence_of(:endpoint_identifier) }
- it { is_expected.to validate_length_of(:endpoint_identifier).is_at_most(255) }
context 'when active' do
# Using `create` instead of `build` the integration so `token` is set.
# Uniqueness spec saves integration with `validate: false` otherwise.
- subject { create(:alert_management_http_integration) }
+ subject { create(:alert_management_http_integration, :legacy) }
it { is_expected.to validate_uniqueness_of(:endpoint_identifier).scoped_to(:project_id, :active) }
end
context 'when inactive' do
- subject { create(:alert_management_http_integration, :inactive) }
+ subject { create(:alert_management_http_integration, :legacy, :inactive) }
it { is_expected.not_to validate_uniqueness_of(:endpoint_identifier).scoped_to(:project_id, :active) }
end
@@ -51,10 +51,6 @@ RSpec.describe AlertManagement::HttpIntegration do
context 'when unsaved' do
context 'when unassigned' do
- before do
- integration.valid?
- end
-
it_behaves_like 'valid token'
end
@@ -89,4 +85,75 @@ RSpec.describe AlertManagement::HttpIntegration do
end
end
end
+
+ describe '#endpoint_identifier' do
+ subject { integration.endpoint_identifier }
+
+ context 'when defined on initialize' do
+ let(:integration) { described_class.new }
+
+ it { is_expected.to match(/\A\h{16}\z/) }
+ end
+
+ context 'when included in initialization args' do
+ let(:integration) { described_class.new(endpoint_identifier: 'legacy') }
+
+ it { is_expected.to eq('legacy') }
+ end
+
+ context 'when reassigning' do
+ let(:integration) { create(:alert_management_http_integration) }
+ let!(:starting_identifier) { subject }
+
+ it 'does not allow reassignment' do
+ integration.endpoint_identifier = 'newValidId'
+ integration.save!
+
+ expect(integration.reload.endpoint_identifier).to eq(starting_identifier)
+ end
+ end
+ end
+
+ describe '#url' do
+ subject { integration.url }
+
+ it do
+ is_expected.to eq(
+ project_alert_http_integration_url(
+ integration.project,
+ 'datadog',
+ integration.endpoint_identifier,
+ format: :json
+ )
+ )
+ end
+
+ context 'when name is not defined' do
+ let(:integration) { described_class.new(project: project) }
+
+ it do
+ is_expected.to eq(
+ project_alert_http_integration_url(
+ integration.project,
+ 'http-endpoint',
+ integration.endpoint_identifier,
+ format: :json
+ )
+ )
+ end
+ end
+
+ context 'for a legacy integration' do
+ let(:integration) { build(:alert_management_http_integration, :legacy) }
+
+ it do
+ is_expected.to eq(
+ project_alerts_notify_url(
+ integration.project,
+ format: :json
+ )
+ )
+ end
+ end
+ end
end