Skip to content

Commit

Permalink
Add tests for updateAlertEventStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
Zizhou Wang committed Mar 21, 2022
1 parent 26f0b5f commit a61c73e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
5 changes: 5 additions & 0 deletions x-pack/plugins/session_view/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ export const ALERTS_INDEX = '.siem-signals-default';
export const ENTRY_SESSION_ENTITY_ID_PROPERTY = 'process.entry_leader.entity_id';
export const ALERT_UUID_PROPERTY = 'kibana.alert.uuid';
export const KIBANA_DATE_FORMAT = 'MMM DD, YYYY @ hh:mm:ss.SSS';
export const ALERT_STATUS = {
OPEN: 'open',
ACKNOWLEDGED: 'acknowledged',
CLOSED: 'closed',
};

// We fetch a large number of events per page to mitigate a few design caveats in session viewer
// 1. Due to the hierarchical nature of the data (e.g we are rendering a time ordered pid tree) there are common scenarios where there
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
* 2.0.
*/
import {
mockData,
mockEvents,
mockAlerts,
mockProcessMap,
} from '../../../common/mocks/constants/session_view_process.mock';
import { Process, ProcessMap } from '../../../common/types/process_tree';
import { Process, ProcessMap, ProcessEvent } from '../../../common/types/process_tree';
import { ALERT_STATUS } from '../../../common/constants';
import { UpdateAlertStatus } from '../../types';
import {
updateAlertEventStatus,
updateProcessMap,
buildProcessTree,
searchProcessTree,
Expand All @@ -20,8 +24,6 @@ const SESSION_ENTITY_ID = '3d0192c6-7c54-5ee6-a110-3539a7cf42bc';
const SEARCH_QUERY = 'vi';
const SEARCH_RESULT_PROCESS_ID = '8e4daeb2-4a4e-56c4-980e-f0dcfdbc3727';

const mockEvents = mockData[0].events;

describe('process tree hook helpers tests', () => {
let processMap: ProcessMap;

Expand Down Expand Up @@ -73,4 +75,46 @@ describe('process tree hook helpers tests', () => {
// session leader should have autoExpand to be true
expect(processMap[SESSION_ENTITY_ID].autoExpand).toBeTruthy();
});

it('updateAlertEventStatus works', () => {
const events: ProcessEvent[] = JSON.parse(JSON.stringify([...mockEvents, ...mockAlerts]));
const updatedAlertsStatus: UpdateAlertStatus = {
[mockAlerts[0].kibana?.alert.uuid!]: {
status: ALERT_STATUS.CLOSED,
processEntityId: mockAlerts[0].process.entity_id,
},
[mockAlerts[1].kibana?.alert.uuid!]: {
status: ALERT_STATUS.ACKNOWLEDGED,
processEntityId: mockAlerts[1].process.entity_id,
},
};

expect(
events.find(
(event) =>
event.kibana?.alert.uuid && event.kibana?.alert.uuid === mockAlerts[0].kibana?.alert.uuid
)?.kibana?.alert.workflow_status
).toEqual(ALERT_STATUS.OPEN);
expect(
events.find(
(event) =>
event.kibana?.alert.uuid && event.kibana?.alert.uuid === mockAlerts[1].kibana?.alert.uuid
)?.kibana?.alert.workflow_status
).toEqual(ALERT_STATUS.OPEN);

updateAlertEventStatus(events, updatedAlertsStatus);

expect(
events.find(
(event) =>
event.kibana?.alert.uuid && event.kibana?.alert.uuid === mockAlerts[0].kibana?.alert.uuid
)?.kibana?.alert.workflow_status
).toEqual(ALERT_STATUS.CLOSED);
expect(
events.find(
(event) =>
event.kibana?.alert.uuid && event.kibana?.alert.uuid === mockAlerts[1].kibana?.alert.uuid
)?.kibana?.alert.workflow_status
).toEqual(ALERT_STATUS.ACKNOWLEDGED);
});
});

0 comments on commit a61c73e

Please sign in to comment.