Skip to content

Commit 3b2bedd

Browse files
author
Aaron Caldwell
committed
Pass context keys to alert instance factory
1 parent c1b6f40 commit 3b2bedd

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

x-pack/plugins/stack_alerts/server/alert_types/geo_containment/tests/geo_containment.test.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
} from '../alert_type';
2525
import { SearchResponse } from 'elasticsearch';
2626

27-
const alertInstanceFactory = (expectedAlertResults: unknown[], testAlertActionArr: unknown[]) => (
27+
const alertInstanceFactory = (contextKeys: unknown[], testAlertActionArr: unknown[]) => (
2828
instanceId: string
2929
) => {
3030
const alertInstance = alertsMock.createAlertInstanceFactory<
@@ -33,9 +33,8 @@ const alertInstanceFactory = (expectedAlertResults: unknown[], testAlertActionAr
3333
>();
3434
alertInstance.scheduleActions.mockImplementation(
3535
(actionGroupId: string, context?: GeoContainmentInstanceContext) => {
36-
// Store descriptive subset of created alerts in passed-in array for calling test
36+
// Check subset of alert for comparison to expected results
3737
// @ts-ignore
38-
const contextKeys = Object.keys(expectedAlertResults[0].context);
3938
const contextSubset = _.pickBy(context, (v, k) => contextKeys.includes(k));
4039
testAlertActionArr.push({
4140
actionGroupId,
@@ -249,6 +248,7 @@ describe('geo_containment', () => {
249248
instanceId: 'c-789',
250249
},
251250
];
251+
const contextKeys = Object.keys(expectedAlertResults[0].context);
252252
const emptyShapesIdsNamesMap = {};
253253

254254
const currentDateTime = new Date();
@@ -258,7 +258,7 @@ describe('geo_containment', () => {
258258
const allActiveEntriesMap = getActiveEntriesAndGenerateAlerts(
259259
emptyPrevLocationMap,
260260
currLocationMap,
261-
alertInstanceFactory(expectedAlertResults, testAlertActionArr),
261+
alertInstanceFactory(contextKeys, testAlertActionArr),
262262
emptyShapesIdsNamesMap,
263263
currentDateTime
264264
);
@@ -283,7 +283,7 @@ describe('geo_containment', () => {
283283
const allActiveEntriesMap = getActiveEntriesAndGenerateAlerts(
284284
prevLocationMapWithIdenticalEntityEntry,
285285
currLocationMap,
286-
alertInstanceFactory(expectedAlertResults, testAlertActionArr),
286+
alertInstanceFactory(contextKeys, testAlertActionArr),
287287
emptyShapesIdsNamesMap,
288288
currentDateTime
289289
);
@@ -322,7 +322,7 @@ describe('geo_containment', () => {
322322
const allActiveEntriesMap = getActiveEntriesAndGenerateAlerts(
323323
prevLocationMapWithNonIdenticalEntityEntry,
324324
currLocationMap,
325-
alertInstanceFactory(expectedAlertResults, testAlertActionArr),
325+
alertInstanceFactory(contextKeys, testAlertActionArr),
326326
emptyShapesIdsNamesMap,
327327
currentDateTime
328328
);
@@ -345,7 +345,7 @@ describe('geo_containment', () => {
345345
const allActiveEntriesMap = getActiveEntriesAndGenerateAlerts(
346346
emptyPrevLocationMap,
347347
currLocationMapWithOther,
348-
alertInstanceFactory(expectedAlertResults, testAlertActionArr),
348+
alertInstanceFactory(contextKeys, testAlertActionArr),
349349
emptyShapesIdsNamesMap,
350350
currentDateTime
351351
);
@@ -378,7 +378,7 @@ describe('geo_containment', () => {
378378
getActiveEntriesAndGenerateAlerts(
379379
emptyPrevLocationMap,
380380
currLocationMapWithThreeMore,
381-
alertInstanceFactory(expectedAlertResults, testAlertActionArr),
381+
alertInstanceFactory(contextKeys, testAlertActionArr),
382382
emptyShapesIdsNamesMap,
383383
currentDateTime
384384
);
@@ -415,7 +415,7 @@ describe('geo_containment', () => {
415415
const allActiveEntriesMap = getActiveEntriesAndGenerateAlerts(
416416
emptyPrevLocationMap,
417417
currLocationMapWithOther,
418-
alertInstanceFactory(expectedAlertResults, testAlertActionArr),
418+
alertInstanceFactory(contextKeys, testAlertActionArr),
419419
emptyShapesIdsNamesMap,
420420
currentDateTime
421421
);
@@ -447,7 +447,7 @@ describe('geo_containment', () => {
447447
const allActiveEntriesMap = getActiveEntriesAndGenerateAlerts(
448448
emptyPrevLocationMap,
449449
currLocationMapWithOther,
450-
alertInstanceFactory(expectedAlertResults, testAlertActionArr),
450+
alertInstanceFactory(contextKeys, testAlertActionArr),
451451
emptyShapesIdsNamesMap,
452452
currentDateTime
453453
);
@@ -515,10 +515,11 @@ describe('geo_containment', () => {
515515
// Boundary test mocks
516516
const boundaryCall = jest.fn();
517517
const esAggCall = jest.fn();
518+
const contextKeys = Object.keys(expectedAlertResults[0].context);
518519
const alertServicesWithSearchMock: AlertServicesMock = {
519520
...alertsMock.createAlertServices(),
520521
// @ts-ignore
521-
alertInstanceFactory: alertInstanceFactory(expectedAlertResults, testAlertActionArr),
522+
alertInstanceFactory: alertInstanceFactory(contextKeys, testAlertActionArr),
522523
scopedClusterClient: {
523524
asCurrentUser: {
524525
// @ts-ignore

0 commit comments

Comments
 (0)