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')
-rw-r--r--spec/models/alert_management/alert_spec.rb7
-rw-r--r--spec/models/alert_management/http_integration_spec.rb48
2 files changed, 52 insertions, 3 deletions
diff --git a/spec/models/alert_management/alert_spec.rb b/spec/models/alert_management/alert_spec.rb
index b57062b5fc1..80a45b1c1be 100644
--- a/spec/models/alert_management/alert_spec.rb
+++ b/spec/models/alert_management/alert_spec.rb
@@ -99,7 +99,8 @@ RSpec.describe AlertManagement::Alert do
describe 'fingerprint' do
let_it_be(:fingerprint) { 'fingerprint' }
- let(:new_alert) { build(:alert_management_alert, fingerprint: fingerprint, project: project) }
+ let_it_be(:project3, refind: true) { create(:project) }
+ let(:new_alert) { build(:alert_management_alert, fingerprint: fingerprint, project: project3) }
subject { new_alert }
@@ -107,7 +108,7 @@ RSpec.describe AlertManagement::Alert do
context 'same project, various states' do
using RSpec::Parameterized::TableSyntax
- let_it_be(:existing_alert) { create(:alert_management_alert, fingerprint: fingerprint, project: project) }
+ let_it_be(:existing_alert, refind: true) { create(:alert_management_alert, fingerprint: fingerprint, project: project3) }
# We are only validating uniqueness for non-resolved alerts
where(:existing_status, :new_status, :valid) do
@@ -130,7 +131,7 @@ RSpec.describe AlertManagement::Alert do
end
with_them do
- let(:new_alert) { build(:alert_management_alert, new_status, fingerprint: fingerprint, project: project) }
+ let(:new_alert) { build(:alert_management_alert, new_status, fingerprint: fingerprint, project: project3) }
before do
existing_alert.change_status_to(existing_status)
diff --git a/spec/models/alert_management/http_integration_spec.rb b/spec/models/alert_management/http_integration_spec.rb
index a3e7b47c116..910df51801a 100644
--- a/spec/models/alert_management/http_integration_spec.rb
+++ b/spec/models/alert_management/http_integration_spec.rb
@@ -31,6 +31,54 @@ RSpec.describe AlertManagement::HttpIntegration do
it { is_expected.not_to validate_uniqueness_of(:endpoint_identifier).scoped_to(:project_id, :active) }
end
+
+ context 'payload_attribute_mapping' do
+ subject { build(:alert_management_http_integration, payload_attribute_mapping: attribute_mapping) }
+
+ context 'with valid JSON schema' do
+ let(:attribute_mapping) do
+ {
+ title: { path: %w(a b c), type: 'string' },
+ description: { path: %w(a), type: 'string' }
+ }
+ end
+
+ it { is_expected.to be_valid }
+ end
+
+ context 'with invalid JSON schema' do
+ shared_examples 'is invalid record' do
+ it do
+ expect(subject).to be_invalid
+ expect(subject.errors.messages[:payload_attribute_mapping]).to eq(['must be a valid json schema'])
+ end
+ end
+
+ context 'when property is not an object' do
+ let(:attribute_mapping) do
+ { title: 'That is not a valid schema' }
+ end
+
+ it_behaves_like 'is invalid record'
+ end
+
+ context 'when property missing required attributes' do
+ let(:attribute_mapping) do
+ { title: { type: 'string' } }
+ end
+
+ it_behaves_like 'is invalid record'
+ end
+
+ context 'when property has extra attributes' do
+ let(:attribute_mapping) do
+ { title: { path: %w(a b c), type: 'string', extra: 'property' } }
+ end
+
+ it_behaves_like 'is invalid record'
+ end
+ end
+ end
end
describe '#token' do