Skip to content

Commit

Permalink
Functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ymao1 committed May 12, 2021
1 parent 3395506 commit 0a9637c
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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: {},
Expand All @@ -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(
Expand Down Expand Up @@ -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: {},
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 0a9637c

Please sign in to comment.