mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
8b4e2fe7ce
commit
4f840bc5e8
1 changed files with 66 additions and 13 deletions
|
@ -4,6 +4,7 @@
|
||||||
* you may not use this file except in compliance with the Elastic License.
|
* you may not use this file except in compliance with the Elastic License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import _ from 'lodash';
|
||||||
import sampleJsonResponse from './es_sample_response.json';
|
import sampleJsonResponse from './es_sample_response.json';
|
||||||
import sampleJsonResponseWithNesting from './es_sample_response_with_nesting.json';
|
import sampleJsonResponseWithNesting from './es_sample_response_with_nesting.json';
|
||||||
import { getActiveEntriesAndGenerateAlerts, transformResults } from '../geo_containment';
|
import { getActiveEntriesAndGenerateAlerts, transformResults } from '../geo_containment';
|
||||||
|
@ -120,7 +121,7 @@ describe('geo_containment', () => {
|
||||||
|
|
||||||
describe('getActiveEntriesAndGenerateAlerts', () => {
|
describe('getActiveEntriesAndGenerateAlerts', () => {
|
||||||
const testAlertActionArr: unknown[] = [];
|
const testAlertActionArr: unknown[] = [];
|
||||||
afterEach(() => {
|
beforeEach(() => {
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
testAlertActionArr.length = 0;
|
testAlertActionArr.length = 0;
|
||||||
});
|
});
|
||||||
|
@ -154,12 +155,54 @@ describe('geo_containment', () => {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const expectedContext = [
|
||||||
|
{
|
||||||
|
actionGroupId: 'Tracked entity contained',
|
||||||
|
context: {
|
||||||
|
containingBoundaryId: '123',
|
||||||
|
entityDocumentId: 'docId1',
|
||||||
|
entityId: 'a',
|
||||||
|
entityLocation: 'POINT (0 0)',
|
||||||
|
},
|
||||||
|
instanceId: 'a-123',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
actionGroupId: 'Tracked entity contained',
|
||||||
|
context: {
|
||||||
|
containingBoundaryId: '456',
|
||||||
|
entityDocumentId: 'docId2',
|
||||||
|
entityId: 'b',
|
||||||
|
entityLocation: 'POINT (0 0)',
|
||||||
|
},
|
||||||
|
instanceId: 'b-456',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
actionGroupId: 'Tracked entity contained',
|
||||||
|
context: {
|
||||||
|
containingBoundaryId: '789',
|
||||||
|
entityDocumentId: 'docId3',
|
||||||
|
entityId: 'c',
|
||||||
|
entityLocation: 'POINT (0 0)',
|
||||||
|
},
|
||||||
|
instanceId: 'c-789',
|
||||||
|
},
|
||||||
|
];
|
||||||
const emptyShapesIdsNamesMap = {};
|
const emptyShapesIdsNamesMap = {};
|
||||||
|
|
||||||
const scheduleActions = jest.fn((alertInstance: string, context: Record<string, unknown>) => {
|
const alertInstanceFactory = (instanceId: string) => {
|
||||||
testAlertActionArr.push(context.entityId);
|
return {
|
||||||
});
|
scheduleActions: (actionGroupId: string, context: Record<string, unknown>) => {
|
||||||
const alertInstanceFactory = (x: string) => ({ scheduleActions });
|
const contextKeys = Object.keys(expectedContext[0].context);
|
||||||
|
const contextSubset = _.pickBy(context, (v, k) => contextKeys.includes(k));
|
||||||
|
testAlertActionArr.push({
|
||||||
|
actionGroupId,
|
||||||
|
instanceId,
|
||||||
|
context: contextSubset,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
const currentDateTime = new Date();
|
const currentDateTime = new Date();
|
||||||
|
|
||||||
it('should use currently active entities if no older entity entries', () => {
|
it('should use currently active entities if no older entity entries', () => {
|
||||||
|
@ -172,8 +215,7 @@ describe('geo_containment', () => {
|
||||||
currentDateTime
|
currentDateTime
|
||||||
);
|
);
|
||||||
expect(allActiveEntriesMap).toEqual(currLocationMap);
|
expect(allActiveEntriesMap).toEqual(currLocationMap);
|
||||||
expect(scheduleActions.mock.calls.length).toEqual(allActiveEntriesMap.size);
|
expect(testAlertActionArr).toMatchObject(expectedContext);
|
||||||
expect(testAlertActionArr).toEqual([...allActiveEntriesMap.keys()]);
|
|
||||||
});
|
});
|
||||||
it('should overwrite older identical entity entries', () => {
|
it('should overwrite older identical entity entries', () => {
|
||||||
const prevLocationMapWithIdenticalEntityEntry = {
|
const prevLocationMapWithIdenticalEntityEntry = {
|
||||||
|
@ -192,8 +234,7 @@ describe('geo_containment', () => {
|
||||||
currentDateTime
|
currentDateTime
|
||||||
);
|
);
|
||||||
expect(allActiveEntriesMap).toEqual(currLocationMap);
|
expect(allActiveEntriesMap).toEqual(currLocationMap);
|
||||||
expect(scheduleActions.mock.calls.length).toEqual(allActiveEntriesMap.size);
|
expect(testAlertActionArr).toMatchObject(expectedContext);
|
||||||
expect(testAlertActionArr).toEqual([...allActiveEntriesMap.keys()]);
|
|
||||||
});
|
});
|
||||||
it('should preserve older non-identical entity entries', () => {
|
it('should preserve older non-identical entity entries', () => {
|
||||||
const prevLocationMapWithNonIdenticalEntityEntry = {
|
const prevLocationMapWithNonIdenticalEntityEntry = {
|
||||||
|
@ -204,6 +245,20 @@ describe('geo_containment', () => {
|
||||||
docId: 'docId7',
|
docId: 'docId7',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
const expectedContextPlusD = [
|
||||||
|
{
|
||||||
|
actionGroupId: 'Tracked entity contained',
|
||||||
|
context: {
|
||||||
|
containingBoundaryId: '999',
|
||||||
|
entityDocumentId: 'docId7',
|
||||||
|
entityId: 'd',
|
||||||
|
entityLocation: 'POINT (0 0)',
|
||||||
|
},
|
||||||
|
instanceId: 'd-999',
|
||||||
|
},
|
||||||
|
...expectedContext,
|
||||||
|
];
|
||||||
|
|
||||||
const allActiveEntriesMap = getActiveEntriesAndGenerateAlerts(
|
const allActiveEntriesMap = getActiveEntriesAndGenerateAlerts(
|
||||||
prevLocationMapWithNonIdenticalEntityEntry,
|
prevLocationMapWithNonIdenticalEntityEntry,
|
||||||
currLocationMap,
|
currLocationMap,
|
||||||
|
@ -213,8 +268,7 @@ describe('geo_containment', () => {
|
||||||
);
|
);
|
||||||
expect(allActiveEntriesMap).not.toEqual(currLocationMap);
|
expect(allActiveEntriesMap).not.toEqual(currLocationMap);
|
||||||
expect(allActiveEntriesMap.has('d')).toBeTruthy();
|
expect(allActiveEntriesMap.has('d')).toBeTruthy();
|
||||||
expect(scheduleActions.mock.calls.length).toEqual(allActiveEntriesMap.size);
|
expect(testAlertActionArr).toMatchObject(expectedContextPlusD);
|
||||||
expect(testAlertActionArr).toEqual([...allActiveEntriesMap.keys()]);
|
|
||||||
});
|
});
|
||||||
it('should remove "other" entries and schedule the expected number of actions', () => {
|
it('should remove "other" entries and schedule the expected number of actions', () => {
|
||||||
const emptyPrevLocationMap = {};
|
const emptyPrevLocationMap = {};
|
||||||
|
@ -233,8 +287,7 @@ describe('geo_containment', () => {
|
||||||
currentDateTime
|
currentDateTime
|
||||||
);
|
);
|
||||||
expect(allActiveEntriesMap).toEqual(currLocationMap);
|
expect(allActiveEntriesMap).toEqual(currLocationMap);
|
||||||
expect(scheduleActions.mock.calls.length).toEqual(allActiveEntriesMap.size);
|
expect(testAlertActionArr).toMatchObject(expectedContext);
|
||||||
expect(testAlertActionArr).toEqual([...allActiveEntriesMap.keys()]);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue