From 5a2284f3500088e04cf3a5854fb06dc9db2b6077 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 16 Dec 2020 12:09:53 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- .../alert_management/http_integration_spec.rb | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'spec/models/alert_management') 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 -- cgit v1.2.1