Skip to content

Commit

Permalink
added mock to test
Browse files Browse the repository at this point in the history
  • Loading branch information
parkiino committed Jun 23, 2021
1 parent 7226770 commit 8cb45fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,27 @@
* 2.0.
*/

import _ from 'lodash';
import { mockDetailItemData } from '../mock';
import { endpointAlertCheck } from './endpoint_alert_check';

describe('utils', () => {
describe('endpoinAlertCheck', () => {
it('should return true if detections data comes from an endpoint rule', () => {
expect(endpointAlertCheck(mockData)).toBeTruthy();
});
describe('endpointAlertCheck', () => {
it('should return false if detections data does not come from endpoint rule', () => {
expect(endpointAlertCheck(mockDataWithout)).toBeFalsy();
expect(endpointAlertCheck({ data: mockDetailItemData })).toBeFalsy();
});
it('should return true if detections data comes from an endpoint rule', () => {
_.remove(mockDetailItemData, function (o) {
return o.field === 'agent.type';
});
const mockEndpointDetailItemData = _.concat(mockDetailItemData, {
field: 'agent.type',
originalValue: 'endpoint',
values: ['endpoint'],
isObjectArray: false,
});

expect(endpointAlertCheck({ data: mockEndpointDetailItemData })).toBeTruthy();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import { find } from 'lodash/fp';
import { TimelineEventsDetailsItem } from '../../../common/search_strategy';

export const endpointAlertCheck = ({ data }: { data: TimelineEventsDetailsItem[] | null }) => {
const findEndpointAlert = find({ category: 'agent', field: 'agent.type' }, data)?.values;
const findEndpointAlert = find({ field: 'agent.type' }, data)?.values;
return findEndpointAlert ? findEndpointAlert[0] === 'endpoint' : false;
};

0 comments on commit 8cb45fc

Please sign in to comment.