Commit 4fc571e0 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Merge branch '273573-remove-multiple_http_integrations_custom_mapping-ff' into 'master'

Remove `multiple_http_integrations_custom_mapping` feature flag [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!56021
parents 20828283 138c6e1e
...@@ -16,7 +16,6 @@ import { ...@@ -16,7 +16,6 @@ import {
import * as Sentry from '@sentry/browser'; import * as Sentry from '@sentry/browser';
import { isEmpty, omit } from 'lodash'; import { isEmpty, omit } from 'lodash';
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue'; import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { import {
integrationTypes, integrationTypes,
integrationSteps, integrationSteps,
...@@ -60,7 +59,6 @@ export default { ...@@ -60,7 +59,6 @@ export default {
directives: { directives: {
GlModal: GlModalDirective, GlModal: GlModalDirective,
}, },
mixins: [glFeatureFlagsMixin()],
inject: { inject: {
generic: { generic: {
default: {}, default: {},
...@@ -163,12 +161,7 @@ export default { ...@@ -163,12 +161,7 @@ export default {
}; };
}, },
showMappingBuilder() { showMappingBuilder() {
return ( return this.multiIntegrations && this.isHttp && this.alertFields?.length;
this.multiIntegrations &&
this.glFeatures.multipleHttpIntegrationsCustomMapping &&
this.isHttp &&
this.alertFields?.length
);
}, },
hasSamplePayload() { hasSamplePayload() {
return this.isValidNonEmptyJSON(this.currentIntegration?.payloadExample); return this.isValidNonEmptyJSON(this.currentIntegration?.payloadExample);
...@@ -234,12 +227,10 @@ export default { ...@@ -234,12 +227,10 @@ export default {
}, },
submit() { submit() {
const { name, apiUrl } = this.integrationForm; const { name, apiUrl } = this.integrationForm;
const customMappingVariables = this.glFeatures.multipleHttpIntegrationsCustomMapping const customMappingVariables = {
? { payloadAttributeMappings: this.mapping,
payloadAttributeMappings: this.mapping, payloadExample: this.samplePayload.json || '{}',
payloadExample: this.samplePayload.json || '{}', };
}
: {};
const variables = const variables =
this.selectedIntegration === typeSet.http this.selectedIntegration === typeSet.http
......
...@@ -63,10 +63,7 @@ export default (el) => { ...@@ -63,10 +63,7 @@ export default (el) => {
render(createElement) { render(createElement) {
return createElement('alert-settings-wrapper', { return createElement('alert-settings-wrapper', {
props: { props: {
alertFields: alertFields: parseBoolean(multiIntegrations) ? JSON.parse(alertFields) : null,
gon.features?.multipleHttpIntegrationsCustomMapping && parseBoolean(multiIntegrations)
? JSON.parse(alertFields)
: null,
}, },
}); });
}, },
......
...@@ -6,10 +6,6 @@ module Projects ...@@ -6,10 +6,6 @@ module Projects
before_action :authorize_admin_operations! before_action :authorize_admin_operations!
before_action :authorize_read_prometheus_alerts!, only: [:reset_alerting_token] before_action :authorize_read_prometheus_alerts!, only: [:reset_alerting_token]
before_action do
push_frontend_feature_flag(:multiple_http_integrations_custom_mapping, @project)
end
respond_to :json, only: [:reset_alerting_token, :reset_pagerduty_token] respond_to :json, only: [:reset_alerting_token, :reset_pagerduty_token]
helper_method :error_tracking_setting helper_method :error_tracking_setting
......
---
name: multiple_http_integrations_custom_mapping
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/46437
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/273573
milestone: '13.6'
type: development
group: group::monitor
default_enabled: false
---
title: Custom mapping for HTTP endpoints
merge_request: 56021
author:
type: added
...@@ -3,8 +3,7 @@ ...@@ -3,8 +3,7 @@
module Gitlab module Gitlab
module AlertManagement module AlertManagement
def self.custom_mapping_available?(project) def self.custom_mapping_available?(project)
::Feature.enabled?(:multiple_http_integrations_custom_mapping, project) && project.feature_available?(:multiple_alert_http_integrations)
project.feature_available?(:multiple_alert_http_integrations)
end end
# Returns the complete list of alert fields for the custom mapping to be consumed by the frontend and the GraphQL API. # Returns the complete list of alert fields for the custom mapping to be consumed by the frontend and the GraphQL API.
......
...@@ -85,28 +85,14 @@ RSpec.describe OperationsHelper, :routing do ...@@ -85,28 +85,14 @@ RSpec.describe OperationsHelper, :routing do
it { is_expected.to include('multi_integrations' => 'true') } it { is_expected.to include('multi_integrations' => 'true') }
context 'with multiple_http_integrations_custom_mapping feature flag enabled' do it 'has the correct list of fields', :aggregate_failures do
before do fields = Gitlab::Json.parse(alerts_settings_data['alert_fields'])
stub_feature_flags(multiple_http_integrations_custom_mapping: true)
end
it 'has the correct list of fields', :aggregate_failures do
fields = Gitlab::Json.parse(alerts_settings_data['alert_fields'])
expect(fields.count).to eq(10)
expect(fields.first.keys).to eq(%w[name label types])
expect(fields.map { |f| f['name'] }).to match_array(
%w[title description start_time end_time service monitoring_tool hosts severity fingerprint gitlab_environment_name]
)
end
end
context 'with multiple_http_integrations_custom_mapping feature flag disabled' do
before do
stub_feature_flags(multiple_http_integrations_custom_mapping: false)
end
it { is_expected.not_to have_key('alert_fields') } expect(fields.count).to eq(10)
expect(fields.first.keys).to eq(%w[name label types])
expect(fields.map { |f| f['name'] }).to match_array(
%w[title description start_time end_time service monitoring_tool hosts severity fingerprint gitlab_environment_name]
)
end end
end end
......
...@@ -106,178 +106,164 @@ RSpec.describe Gitlab::AlertManagement::Payload::Generic do ...@@ -106,178 +106,164 @@ RSpec.describe Gitlab::AlertManagement::Payload::Generic do
stub_licensed_features(multiple_alert_http_integrations: project) stub_licensed_features(multiple_alert_http_integrations: project)
end end
context 'with multiple_http_integrations_custom_mapping feature flag enabled' do let_it_be(:attribute_mapping) do
let_it_be(:attribute_mapping) do {
{ title: { path: %w(alert name), type: 'string' },
title: { path: %w(alert name), type: 'string' }, description: { path: %w(alert desc), type: 'string' },
description: { path: %w(alert desc), type: 'string' }, start_time: { path: %w(alert start_time), type: 'datetime' },
start_time: { path: %w(alert start_time), type: 'datetime' }, end_time: { path: %w(alert end_time), type: 'datetime' },
end_time: { path: %w(alert end_time), type: 'datetime' }, service: { path: %w(alert service), type: 'string' },
service: { path: %w(alert service), type: 'string' }, monitoring_tool: { path: %w(alert monitoring_tool), type: 'string' },
monitoring_tool: { path: %w(alert monitoring_tool), type: 'string' }, hosts: { path: %w(alert hosts), type: 'string' },
hosts: { path: %w(alert hosts), type: 'string' }, severity: { path: %w(alert severity), type: 'string' },
severity: { path: %w(alert severity), type: 'string' }, gitlab_environment_name: { path: %w(alert env_name), type: 'string' },
gitlab_environment_name: { path: %w(alert env_name), type: 'string' }, fingerprint: { path: %w(alert fingerprint), type: 'string' }
fingerprint: { path: %w(alert fingerprint), type: 'string' } }
} end
end
let(:parsed_payload) { described_class.new(project: project, payload: raw_payload, integration: integration) } let(:parsed_payload) { described_class.new(project: project, payload: raw_payload, integration: integration) }
before do context 'with defined custom mapping' do
stub_feature_flags(multiple_http_integrations_custom_mapping: project) let_it_be(:integration) do
create(:alert_management_http_integration, project: project, payload_attribute_mapping: attribute_mapping)
end end
context 'with defined custom mapping' do describe '#title' do
let_it_be(:integration) do subject { parsed_payload.title }
create(:alert_management_http_integration, project: project, payload_attribute_mapping: attribute_mapping)
end
describe '#title' do
subject { parsed_payload.title }
it { is_expected.to eq('mapped title') } it { is_expected.to eq('mapped title') }
end end
describe '#description' do describe '#description' do
subject { parsed_payload.description } subject { parsed_payload.description }
it { is_expected.to eq('mapped description') } it { is_expected.to eq('mapped description') }
end end
describe '#starts_at' do describe '#starts_at' do
subject { parsed_payload.starts_at } subject { parsed_payload.starts_at }
it { is_expected.to eq(mapped_start_time) } it { is_expected.to eq(mapped_start_time) }
end end
describe '#ends_at' do describe '#ends_at' do
subject { parsed_payload.ends_at } subject { parsed_payload.ends_at }
it { is_expected.to eq(mapped_end_time) } it { is_expected.to eq(mapped_end_time) }
end end
describe '#service' do describe '#service' do
subject { parsed_payload.service } subject { parsed_payload.service }
it { is_expected.to eq('mapped service') } it { is_expected.to eq('mapped service') }
end end
describe '#monitoring_tool' do describe '#monitoring_tool' do
subject { parsed_payload.monitoring_tool } subject { parsed_payload.monitoring_tool }
it { is_expected.to eq('mapped monitoring tool') } it { is_expected.to eq('mapped monitoring tool') }
end end
describe '#host' do describe '#host' do
subject { parsed_payload.hosts } subject { parsed_payload.hosts }
it { is_expected.to eq(['mapped-host']) } it { is_expected.to eq(['mapped-host']) }
end end
describe '#severity' do describe '#severity' do
subject { parsed_payload.severity } subject { parsed_payload.severity }
it { is_expected.to eq(:high) } it { is_expected.to eq(:high) }
end end
describe '#environment_name' do describe '#environment_name' do
subject { parsed_payload.environment_name } subject { parsed_payload.environment_name }
it { is_expected.to eq('mapped gitlab environment')} it { is_expected.to eq('mapped gitlab environment')}
end end
describe '#gitlab_fingerprint' do describe '#gitlab_fingerprint' do
subject { parsed_payload.gitlab_fingerprint } subject { parsed_payload.gitlab_fingerprint }
it { is_expected.to eq(Gitlab::AlertManagement::Fingerprint.generate('mapped fingerprint')) } it { is_expected.to eq(Gitlab::AlertManagement::Fingerprint.generate('mapped fingerprint')) }
end
end end
end
context 'with only some attributes defined in custom mapping' do context 'with only some attributes defined in custom mapping' do
let_it_be(:attribute_mapping) do let_it_be(:attribute_mapping) do
{ {
title: { path: %w(alert name), type: 'string' } title: { path: %w(alert name), type: 'string' }
} }
end end
let_it_be(:integration) do let_it_be(:integration) do
create(:alert_management_http_integration, project: project, payload_attribute_mapping: attribute_mapping) create(:alert_management_http_integration, project: project, payload_attribute_mapping: attribute_mapping)
end end
describe '#title' do describe '#title' do
subject { parsed_payload.title } subject { parsed_payload.title }
it 'uses the value defined by the custom mapping' do it 'uses the value defined by the custom mapping' do
is_expected.to eq('mapped title') is_expected.to eq('mapped title')
end
end end
end
describe '#description' do describe '#description' do
subject { parsed_payload.description } subject { parsed_payload.description }
it 'falls back to the default value' do it 'falls back to the default value' do
is_expected.to eq('default description') is_expected.to eq('default description')
end
end end
end end
end
context 'when the payload has no default generic attributes' do context 'when the payload has no default generic attributes' do
let_it_be(:raw_payload) do let_it_be(:raw_payload) do
{ {
'alert' => { 'alert' => {
'name' => 'mapped title', 'name' => 'mapped title',
'desc' => 'mapped description' 'desc' => 'mapped description'
}
}
end
let_it_be(:attribute_mapping) do
{
title: { path: %w(alert name), type: 'string' },
description: { path: %w(alert desc), type: 'string' }
} }
end }
end
let_it_be(:integration) do
create(:alert_management_http_integration, project: project, payload_attribute_mapping: attribute_mapping)
end
describe '#title' do
subject { parsed_payload.title }
it { is_expected.to eq('mapped title') }
end
describe '#description' do let_it_be(:attribute_mapping) do
subject { parsed_payload.description } {
title: { path: %w(alert name), type: 'string' },
description: { path: %w(alert desc), type: 'string' }
}
end
it { is_expected.to eq('mapped description') } let_it_be(:integration) do
end create(:alert_management_http_integration, project: project, payload_attribute_mapping: attribute_mapping)
end end
context 'with inactive HTTP integration' do describe '#title' do
let_it_be(:integration) do subject { parsed_payload.title }
create(:alert_management_http_integration, :inactive, project: project, payload_attribute_mapping: attribute_mapping)
end
it_behaves_like 'parsing alert payload fields with default paths' it { is_expected.to eq('mapped title') }
end end
context 'with blank custom mapping' do describe '#description' do
let_it_be(:integration) { create(:alert_management_http_integration, project: project) } subject { parsed_payload.description }
it_behaves_like 'parsing alert payload fields with default paths' it { is_expected.to eq('mapped description') }
end end
end end
context 'with multiple_http_integrations_custom_mapping feature flag disabled' do context 'with inactive HTTP integration' do
before do let_it_be(:integration) do
stub_feature_flags(multiple_http_integrations_custom_mapping: false) create(:alert_management_http_integration, :inactive, project: project, payload_attribute_mapping: attribute_mapping)
end end
it_behaves_like 'parsing alert payload fields with default paths' it_behaves_like 'parsing alert payload fields with default paths'
end end
context 'with blank custom mapping' do
let_it_be(:integration) { create(:alert_management_http_integration, project: project) }
it_behaves_like 'parsing alert payload fields with default paths'
end
end end
context 'with multiple HTTP integrations feature unavailable' do context 'with multiple HTTP integrations feature unavailable' do
......
...@@ -71,7 +71,6 @@ RSpec.describe 'Creating a new HTTP Integration' do ...@@ -71,7 +71,6 @@ RSpec.describe 'Creating a new HTTP Integration' do
project.add_maintainer(current_user) project.add_maintainer(current_user)
stub_licensed_features(multiple_alert_http_integrations: true) stub_licensed_features(multiple_alert_http_integrations: true)
stub_feature_flags(multiple_http_integrations_custom_mapping: project)
end end
it_behaves_like 'creating a new HTTP integration' it_behaves_like 'creating a new HTTP integration'
...@@ -108,14 +107,6 @@ RSpec.describe 'Creating a new HTTP Integration' do ...@@ -108,14 +107,6 @@ RSpec.describe 'Creating a new HTTP Integration' do
it_behaves_like 'ignoring the custom mapping' it_behaves_like 'ignoring the custom mapping'
end end
context 'with multiple_http_integrations_custom_mapping feature flag disabled' do
before do
stub_feature_flags(multiple_http_integrations_custom_mapping: false)
end
it_behaves_like 'ignoring the custom mapping'
end
it_behaves_like 'validating the payload_example' it_behaves_like 'validating the payload_example'
it_behaves_like 'validating the payload_attribute_mappings' it_behaves_like 'validating the payload_attribute_mappings'
end end
...@@ -61,7 +61,6 @@ RSpec.describe 'Updating an existing HTTP Integration' do ...@@ -61,7 +61,6 @@ RSpec.describe 'Updating an existing HTTP Integration' do
project.add_maintainer(current_user) project.add_maintainer(current_user)
stub_licensed_features(multiple_alert_http_integrations: true) stub_licensed_features(multiple_alert_http_integrations: true)
stub_feature_flags(multiple_http_integrations_custom_mapping: project)
end end
it_behaves_like 'updating an existing HTTP integration' it_behaves_like 'updating an existing HTTP integration'
...@@ -75,12 +74,4 @@ RSpec.describe 'Updating an existing HTTP Integration' do ...@@ -75,12 +74,4 @@ RSpec.describe 'Updating an existing HTTP Integration' do
it_behaves_like 'ignoring the custom mapping' it_behaves_like 'ignoring the custom mapping'
end end
context 'with multiple_http_integrations_custom_mapping feature flag disabled' do
before do
stub_feature_flags(multiple_http_integrations_custom_mapping: false)
end
it_behaves_like 'ignoring the custom mapping'
end
end end
...@@ -57,7 +57,6 @@ RSpec.describe 'getting Alert Management HTTP Integrations' do ...@@ -57,7 +57,6 @@ RSpec.describe 'getting Alert Management HTTP Integrations' do
before do before do
stub_licensed_features(multiple_alert_http_integrations: true) stub_licensed_features(multiple_alert_http_integrations: true)
stub_feature_flags(multiple_http_integrations_custom_mapping: project)
end end
before_all do before_all do
......
...@@ -47,7 +47,6 @@ RSpec.describe 'parse alert payload fields' do ...@@ -47,7 +47,6 @@ RSpec.describe 'parse alert payload fields' do
before do before do
stub_licensed_features(multiple_alert_http_integrations: license) stub_licensed_features(multiple_alert_http_integrations: license)
stub_feature_flags(multiple_http_integrations_custom_mapping: feature_flag)
post_graphql(query, current_user: current_user) post_graphql(query, current_user: current_user)
end end
...@@ -94,10 +93,4 @@ RSpec.describe 'parse alert payload fields' do ...@@ -94,10 +93,4 @@ RSpec.describe 'parse alert payload fields' do
it_behaves_like 'query with error', 'Failed to parse payload' it_behaves_like 'query with error', 'Failed to parse payload'
end end
context 'without feature flag' do
let(:feature_flag) { false }
it_behaves_like 'query with error', 'Feature not available'
end
end end
...@@ -22,76 +22,59 @@ RSpec.describe AlertManagement::ExtractAlertPayloadFieldsService do ...@@ -22,76 +22,59 @@ RSpec.describe AlertManagement::ExtractAlertPayloadFieldsService do
stub_licensed_features(multiple_alert_http_integrations: true) stub_licensed_features(multiple_alert_http_integrations: true)
end end
context 'with feature flag enabled' do context 'with permissions' do
before do before do
stub_feature_flags(multiple_http_integrations_custom_mapping: project) project.add_maintainer(user_with_permissions)
end end
context 'with permissions' do context 'when payload is valid JSON' do
before do context 'when payload has an acceptable size' do
project.add_maintainer(user_with_permissions) it 'responds with success' do
end is_expected.to be_success
context 'when payload is valid JSON' do
context 'when payload has an acceptable size' do
it 'responds with success' do
is_expected.to be_success
end
it 'returns parsed fields' do
fields = response.payload[:payload_alert_fields]
field = fields.first
expect(fields.count).to eq(1)
expect(field.label).to eq('Foo')
expect(field.type).to eq('string')
expect(field.path).to eq(%w[foo])
end
end end
context 'when limits are exceeded' do it 'returns parsed fields' do
before do fields = response.payload[:payload_alert_fields]
allow(Gitlab::Utils::DeepSize) field = fields.first
.to receive(:new)
.with(Gitlab::Json.parse(payload_json))
.and_return(double(valid?: false))
end
it 'returns payload size exceeded error' do expect(fields.count).to eq(1)
is_expected.to be_error expect(field.label).to eq('Foo')
expect(response.message).to eq('Payload size exceeded') expect(field.type).to eq('string')
end expect(field.path).to eq(%w[foo])
end end
end end
context 'when payload is not a valid JSON' do context 'when limits are exceeded' do
let(:payload) { 'not a JSON' } before do
allow(Gitlab::Utils::DeepSize)
.to receive(:new)
.with(Gitlab::Json.parse(payload_json))
.and_return(double(valid?: false))
end
it 'returns payload parse failure error' do it 'returns payload size exceeded error' do
is_expected.to be_error is_expected.to be_error
expect(response.message).to eq('Failed to parse payload') expect(response.message).to eq('Payload size exceeded')
end end
end end
end end
context 'without permissions' do context 'when payload is not a valid JSON' do
let_it_be(:user) { user_without_permissions } let(:payload) { 'not a JSON' }
it 'returns insufficient permissions error' do it 'returns payload parse failure error' do
is_expected.to be_error is_expected.to be_error
expect(response.message).to eq('Insufficient permissions') expect(response.message).to eq('Failed to parse payload')
end end
end end
end end
context 'with feature flag disabled' do context 'without permissions' do
before do let_it_be(:user) { user_without_permissions }
stub_feature_flags(multiple_http_integrations_custom_mapping: false)
end
it 'returns feature not available error' do it 'returns insufficient permissions error' do
is_expected.to be_error is_expected.to be_error
expect(response.message).to eq('Feature not available') expect(response.message).to eq('Insufficient permissions')
end end
end end
end end
......
...@@ -8,23 +8,23 @@ RSpec.describe AlertManagement::HttpIntegrations::CreateService do ...@@ -8,23 +8,23 @@ RSpec.describe AlertManagement::HttpIntegrations::CreateService do
let(:payload_example) do let(:payload_example) do
{ {
'alert' => { 'name' => 'Test alert' }, 'alert' => { 'name' => 'Test alert' },
'started_at' => Time.current.strftime('%d %B %Y, %-l:%M%p (%Z)') 'started_at' => Time.current.strftime('%d %B %Y, %-l:%M%p (%Z)')
} }
end end
let(:payload_attribute_mapping) do let(:payload_attribute_mapping) do
{ {
'title' => { 'path' => %w[alert name], 'type' => 'string' }, 'title' => { 'path' => %w[alert name], 'type' => 'string' },
'start_time' => { 'path' => %w[started_at], 'type' => 'datetime' } 'start_time' => { 'path' => %w[started_at], 'type' => 'datetime' }
} }
end end
let(:params) do let(:params) do
{ {
name: 'New HTTP Integration', name: 'New HTTP Integration',
payload_example: payload_example, payload_example: payload_example,
payload_attribute_mapping: payload_attribute_mapping payload_attribute_mapping: payload_attribute_mapping
} }
end end
...@@ -68,28 +68,14 @@ RSpec.describe AlertManagement::HttpIntegrations::CreateService do ...@@ -68,28 +68,14 @@ RSpec.describe AlertManagement::HttpIntegrations::CreateService do
end end
end end
context 'with multiple_http_integrations_custom_mapping feature flag enabled' do it 'successfully creates a new integration with the custom mappings' do
before do expect(response).to be_success
stub_feature_flags(multiple_http_integrations_custom_mapping: project)
end
it 'successfully creates a new integration with the custom mappings' do
expect(response).to be_success
integration = response.payload[:integration]
expect(integration).to be_a(::AlertManagement::HttpIntegration)
expect(integration.name).to eq('New HTTP Integration')
expect(integration.payload_example).to eq(payload_example)
expect(integration.payload_attribute_mapping).to eq(payload_attribute_mapping)
end
end
context 'with multiple_http_integrations_custom_mapping feature flag disabled' do
before do
stub_feature_flags(multiple_http_integrations_custom_mapping: false)
end
it_behaves_like 'ignoring the custom mapping' integration = response.payload[:integration]
expect(integration).to be_a(::AlertManagement::HttpIntegration)
expect(integration.name).to eq('New HTTP Integration')
expect(integration.payload_example).to eq(payload_example)
expect(integration.payload_attribute_mapping).to eq(payload_attribute_mapping)
end end
end end
end end
......
...@@ -9,23 +9,23 @@ RSpec.describe AlertManagement::HttpIntegrations::UpdateService do ...@@ -9,23 +9,23 @@ RSpec.describe AlertManagement::HttpIntegrations::UpdateService do
let(:payload_example) do let(:payload_example) do
{ {
'alert' => { 'name' => 'Test alert' }, 'alert' => { 'name' => 'Test alert' },
'started_at' => Time.current.strftime('%d %B %Y, %-l:%M%p (%Z)') 'started_at' => Time.current.strftime('%d %B %Y, %-l:%M%p (%Z)')
} }
end end
let(:payload_attribute_mapping) do let(:payload_attribute_mapping) do
{ {
'title' => { 'path' => %w[alert name], 'type' => 'string' }, 'title' => { 'path' => %w[alert name], 'type' => 'string' },
'start_time' => { 'path' => %w[started_at], 'type' => 'datetime' } 'start_time' => { 'path' => %w[started_at], 'type' => 'datetime' }
} }
end end
let(:params) do let(:params) do
{ {
name: 'New name', name: 'New name',
payload_example: payload_example, payload_example: payload_example,
payload_attribute_mapping: payload_attribute_mapping payload_attribute_mapping: payload_attribute_mapping
} }
end end
...@@ -36,17 +36,6 @@ RSpec.describe AlertManagement::HttpIntegrations::UpdateService do ...@@ -36,17 +36,6 @@ RSpec.describe AlertManagement::HttpIntegrations::UpdateService do
end end
describe '#execute' do describe '#execute' do
shared_examples 'ignoring the custom mapping' do
it 'creates integration without the custom mapping params' do
expect(response).to be_success
integration = response.payload[:integration]
expect(integration).to be_a(::AlertManagement::HttpIntegration)
expect(integration.payload_example).to eq({})
expect(integration.payload_attribute_mapping).to eq({})
end
end
subject(:response) { service.execute } subject(:response) { service.execute }
context 'with multiple HTTP integrations feature available' do context 'with multiple HTTP integrations feature available' do
...@@ -54,31 +43,15 @@ RSpec.describe AlertManagement::HttpIntegrations::UpdateService do ...@@ -54,31 +43,15 @@ RSpec.describe AlertManagement::HttpIntegrations::UpdateService do
stub_licensed_features(multiple_alert_http_integrations: true) stub_licensed_features(multiple_alert_http_integrations: true)
end end
context 'with multiple_http_integrations_custom_mapping feature flag enabled' do it 'successfully creates a new integration with the custom mappings' do
before do expect(response).to be_success
stub_feature_flags(multiple_http_integrations_custom_mapping: project)
end
it 'successfully creates a new integration with the custom mappings' do
expect(response).to be_success
integration = response.payload[:integration]
expect(integration).to be_a(::AlertManagement::HttpIntegration)
expect(integration.name).to eq('New name')
expect(integration.payload_example).to eq(payload_example)
expect(integration.payload_attribute_mapping).to eq(payload_attribute_mapping)
end
end
context 'with multiple_http_integrations_custom_mapping feature flag disabled' do
before do
stub_feature_flags(multiple_http_integrations_custom_mapping: false)
end
it_behaves_like 'ignoring the custom mapping' integration = response.payload[:integration]
expect(integration).to be_a(::AlertManagement::HttpIntegration)
expect(integration.name).to eq('New name')
expect(integration.payload_example).to eq(payload_example)
expect(integration.payload_attribute_mapping).to eq(payload_attribute_mapping)
end end
end end
it_behaves_like 'ignoring the custom mapping'
end end
end end
...@@ -19,7 +19,6 @@ RSpec.describe 'Alert integrations settings form', :js do ...@@ -19,7 +19,6 @@ RSpec.describe 'Alert integrations settings form', :js do
describe 'when viewing alert integrations as a maintainer' do describe 'when viewing alert integrations as a maintainer' do
context 'with the default page permissions' do context 'with the default page permissions' do
before do before do
stub_feature_flags(multiple_http_integrations_custom_mapping: false)
visit project_settings_operations_path(project, anchor: 'js-alert-management-settings') visit project_settings_operations_path(project, anchor: 'js-alert-management-settings')
wait_for_requests wait_for_requests
end end
......
...@@ -12,12 +12,7 @@ describe('AlertsSettingsForm', () => { ...@@ -12,12 +12,7 @@ describe('AlertsSettingsForm', () => {
let wrapper; let wrapper;
const mockToastShow = jest.fn(); const mockToastShow = jest.fn();
const createComponent = ({ const createComponent = ({ data = {}, props = {}, multiIntegrations = true } = {}) => {
data = {},
props = {},
multipleHttpIntegrationsCustomMapping = false,
multiIntegrations = true,
} = {}) => {
wrapper = mount(AlertsSettingsForm, { wrapper = mount(AlertsSettingsForm, {
data() { data() {
return { ...data }; return { ...data };
...@@ -29,7 +24,6 @@ describe('AlertsSettingsForm', () => { ...@@ -29,7 +24,6 @@ describe('AlertsSettingsForm', () => {
}, },
provide: { provide: {
...defaultAlertSettingsConfig, ...defaultAlertSettingsConfig,
glFeatures: { multipleHttpIntegrationsCustomMapping },
multiIntegrations, multiIntegrations,
}, },
mocks: { mocks: {
...@@ -142,27 +136,8 @@ describe('AlertsSettingsForm', () => { ...@@ -142,27 +136,8 @@ describe('AlertsSettingsForm', () => {
describe('submitting integration form', () => { describe('submitting integration form', () => {
describe('HTTP', () => { describe('HTTP', () => {
it('create', async () => {
createComponent();
const integrationName = 'Test integration';
await selectOptionAtIndex(1);
enableIntegration(0, integrationName);
const submitBtn = findSubmitButton();
expect(submitBtn.exists()).toBe(true);
expect(submitBtn.text()).toBe('Save integration');
findForm().trigger('submit');
expect(wrapper.emitted('create-new-integration')[0]).toEqual([
{ type: typeSet.http, variables: { name: integrationName, active: true } },
]);
});
it('create with custom mapping', async () => { it('create with custom mapping', async () => {
createComponent({ createComponent({
multipleHttpIntegrationsCustomMapping: true,
multiIntegrations: true, multiIntegrations: true,
props: { alertFields }, props: { alertFields },
}); });
...@@ -208,9 +183,19 @@ describe('AlertsSettingsForm', () => { ...@@ -208,9 +183,19 @@ describe('AlertsSettingsForm', () => {
findForm().trigger('submit'); findForm().trigger('submit');
expect(wrapper.emitted('update-integration')[0]).toEqual([ expect(wrapper.emitted('update-integration')[0]).toEqual(
{ type: typeSet.http, variables: { name: updatedIntegrationName, active: true } }, expect.arrayContaining([
]); {
type: typeSet.http,
variables: {
name: updatedIntegrationName,
active: true,
payloadAttributeMappings: [],
payloadExample: '{}',
},
},
]),
);
}); });
}); });
...@@ -301,7 +286,6 @@ describe('AlertsSettingsForm', () => { ...@@ -301,7 +286,6 @@ describe('AlertsSettingsForm', () => {
beforeEach(() => { beforeEach(() => {
createComponent({ createComponent({
multipleHttpIntegrationsCustomMapping: true,
data: { data: {
currentIntegration: { currentIntegration: {
type: typeSet.http, type: typeSet.http,
...@@ -408,22 +392,18 @@ describe('AlertsSettingsForm', () => { ...@@ -408,22 +392,18 @@ describe('AlertsSettingsForm', () => {
describe('Mapping builder section', () => { describe('Mapping builder section', () => {
describe.each` describe.each`
alertFieldsProvided | multiIntegrations | featureFlag | integrationOption | visible alertFieldsProvided | multiIntegrations | integrationOption | visible
${true} | ${true} | ${true} | ${1} | ${true} ${true} | ${true} | ${1} | ${true}
${true} | ${true} | ${true} | ${2} | ${false} ${true} | ${true} | ${2} | ${false}
${true} | ${true} | ${false} | ${1} | ${false} ${true} | ${false} | ${1} | ${false}
${true} | ${true} | ${false} | ${2} | ${false} ${false} | ${true} | ${1} | ${false}
${true} | ${false} | ${true} | ${1} | ${false} `('', ({ alertFieldsProvided, multiIntegrations, integrationOption, visible }) => {
${false} | ${true} | ${true} | ${1} | ${false}
`('', ({ alertFieldsProvided, multiIntegrations, featureFlag, integrationOption, visible }) => {
const visibleMsg = visible ? 'is rendered' : 'is not rendered'; const visibleMsg = visible ? 'is rendered' : 'is not rendered';
const featureFlagMsg = featureFlag ? 'is enabled' : 'is disabled';
const alertFieldsMsg = alertFieldsProvided ? 'are provided' : 'are not provided'; const alertFieldsMsg = alertFieldsProvided ? 'are provided' : 'are not provided';
const integrationType = integrationOption === 1 ? typeSet.http : typeSet.prometheus; const integrationType = integrationOption === 1 ? typeSet.http : typeSet.prometheus;
it(`${visibleMsg} when multipleHttpIntegrationsCustomMapping feature flag ${featureFlagMsg} and integration type is ${integrationType} and alert fields ${alertFieldsMsg}`, async () => { it(`${visibleMsg} when integration type is ${integrationType} and alert fields ${alertFieldsMsg}`, async () => {
createComponent({ createComponent({
multipleHttpIntegrationsCustomMapping: featureFlag,
multiIntegrations, multiIntegrations,
props: { props: {
alertFields: alertFieldsProvided ? alertFields : [], alertFields: alertFieldsProvided ? alertFields : [],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment