diff --git a/x-pack/test/alerting_api_integration/common/fixtures/plugins/alerts/server/alert_types.ts b/x-pack/test/alerting_api_integration/common/fixtures/plugins/alerts/server/alert_types.ts index 59efbaf24d9e..3e622b49d03d 100644 --- a/x-pack/test/alerting_api_integration/common/fixtures/plugins/alerts/server/alert_types.ts +++ b/x-pack/test/alerting_api_integration/common/fixtures/plugins/alerts/server/alert_types.ts @@ -103,10 +103,11 @@ async function alwaysFiringExecutor(alertExecutorOptions: any) { tags, createdBy, updatedBy, + rule, } = alertExecutorOptions; let group: string | null = 'default'; let subgroup: string | null = null; - const alertInfo = { alertId, spaceId, namespace, name, tags, createdBy, updatedBy }; + const alertInfo = { alertId, spaceId, namespace, name, tags, createdBy, updatedBy, ...rule }; if (params.groupsToScheduleActionsInSeries) { const index = state.groupInSeriesIndex || 0; diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/alerts.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/alerts.ts index 24e641cb0640..051a12917007 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/alerts.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/alerts.ts @@ -6,6 +6,7 @@ */ import expect from '@kbn/expect'; +import { omit } from 'lodash'; import { UserAtSpaceScenarios, Superuser } from '../../scenarios'; import { FtrProviderContext } from '../../../common/ftr_provider_context'; import { @@ -128,7 +129,11 @@ export default function alertTests({ getService }: FtrProviderContext) { reference ); expect(alertSearchResult.hits.total.value).to.eql(1); - expect(alertSearchResult.hits.hits[0]._source).to.eql({ + const alertSearchResultWithoutDates = omit(alertSearchResult.hits.hits[0]._source, [ + 'alertInfo.createdAt', + 'alertInfo.updatedAt', + ]); + expect(alertSearchResultWithoutDates).to.eql({ source: 'alert:test.always-firing', reference, state: {}, @@ -138,14 +143,37 @@ export default function alertTests({ getService }: FtrProviderContext) { }, alertInfo: { alertId, + consumer: 'alertsFixture', spaceId: space.id, namespace: space.id, name: 'abc', + enabled: true, + notifyWhen: 'onActiveAlert', + schedule: { + interval: '1m', + }, tags: ['tag-A', 'tag-B'], + throttle: '1m', createdBy: user.fullName, updatedBy: user.fullName, + actions: response.body.actions.map((action: any) => { + /* eslint-disable @typescript-eslint/naming-convention */ + const { connector_type_id, group, id, params } = action; + return { + actionTypeId: connector_type_id, + group, + id, + params, + }; + }), }, }); + expect(alertSearchResult.hits.hits[0]._source.alertInfo.createdAt).to.match( + /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/ + ); + expect(alertSearchResult.hits.hits[0]._source.alertInfo.updatedAt).to.match( + /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/ + ); // Ensure only 1 action executed with proper params const actionSearchResult = await esTestIndexTool.search( @@ -243,7 +271,11 @@ instanceStateValue: true reference ); expect(alertSearchResult.hits.total.value).to.eql(1); - expect(alertSearchResult.hits.hits[0]._source).to.eql({ + const alertSearchResultWithoutDates = omit(alertSearchResult.hits.hits[0]._source, [ + 'alertInfo.createdAt', + 'alertInfo.updatedAt', + ]); + expect(alertSearchResultWithoutDates).to.eql({ source: 'alert:test.always-firing', reference, state: {}, @@ -253,15 +285,38 @@ instanceStateValue: true }, alertInfo: { alertId, + consumer: 'alertsFixture', spaceId: space.id, namespace: space.id, name: 'abc', + enabled: true, + notifyWhen: 'onActiveAlert', + schedule: { + interval: '1m', + }, tags: ['tag-A', 'tag-B'], + throttle: '1m', createdBy: user.fullName, updatedBy: user.fullName, + actions: response.body.actions.map((action: any) => { + /* eslint-disable @typescript-eslint/naming-convention */ + const { connector_type_id, group, id, params } = action; + return { + actionTypeId: connector_type_id, + group, + id, + params, + }; + }), }, }); + expect(alertSearchResult.hits.hits[0]._source.alertInfo.createdAt).to.match( + /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/ + ); + expect(alertSearchResult.hits.hits[0]._source.alertInfo.updatedAt).to.match( + /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/ + ); // Ensure only 1 action executed with proper params const actionSearchResult = await esTestIndexTool.search( 'action:test.index-record', diff --git a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/alerts_base.ts b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/alerts_base.ts index 89f6f7f54f4c..5e5e70329ee4 100644 --- a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/alerts_base.ts +++ b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/alerts_base.ts @@ -6,6 +6,7 @@ */ import expect from '@kbn/expect'; +import { omit } from 'lodash'; import { Response as SupertestResponse } from 'supertest'; import { RecoveredActionGroup } from '../../../../../plugins/alerting/common'; import { Space } from '../../../common/types'; @@ -95,18 +96,45 @@ export function alertTests({ getService }: FtrProviderContext, space: Space) { }, alertInfo: { alertId, + consumer: 'alertsFixture', spaceId: space.id, namespace: space.namespace, name: 'abc', + enabled: true, + notifyWhen: 'onActiveAlert', + schedule: { + interval: '1m', + }, tags: ['tag-A', 'tag-B'], + throttle: '1m', createdBy: null, updatedBy: null, + actions: response.body.actions.map((action: any) => { + /* eslint-disable @typescript-eslint/naming-convention */ + const { connector_type_id, group, id, params } = action; + return { + actionTypeId: connector_type_id, + group, + id, + params, + }; + }), }, }; if (expected.alertInfo.namespace === undefined) { delete expected.alertInfo.namespace; } - expect(alertTestRecord._source).to.eql(expected); + const alertTestRecordWithoutDates = omit(alertTestRecord._source, [ + 'alertInfo.createdAt', + 'alertInfo.updatedAt', + ]); + expect(alertTestRecordWithoutDates).to.eql(expected); + expect(alertTestRecord._source.alertInfo.createdAt).to.match( + /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/ + ); + expect(alertTestRecord._source.alertInfo.updatedAt).to.match( + /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/ + ); const actionTestRecord = ( await esTestIndexTool.waitForDocs('action:test.index-record', reference) )[0];