Skip to content

Commit 8cb45fc

Browse files
committed
added mock to test
1 parent 7226770 commit 8cb45fc

2 files changed

Lines changed: 18 additions & 6 deletions

File tree

x-pack/plugins/security_solution/public/common/utils/endpoint_alert_check.test.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,27 @@
55
* 2.0.
66
*/
77

8+
import _ from 'lodash';
9+
import { mockDetailItemData } from '../mock';
810
import { endpointAlertCheck } from './endpoint_alert_check';
911

1012
describe('utils', () => {
11-
describe('endpoinAlertCheck', () => {
12-
it('should return true if detections data comes from an endpoint rule', () => {
13-
expect(endpointAlertCheck(mockData)).toBeTruthy();
14-
});
13+
describe('endpointAlertCheck', () => {
1514
it('should return false if detections data does not come from endpoint rule', () => {
16-
expect(endpointAlertCheck(mockDataWithout)).toBeFalsy();
15+
expect(endpointAlertCheck({ data: mockDetailItemData })).toBeFalsy();
16+
});
17+
it('should return true if detections data comes from an endpoint rule', () => {
18+
_.remove(mockDetailItemData, function (o) {
19+
return o.field === 'agent.type';
20+
});
21+
const mockEndpointDetailItemData = _.concat(mockDetailItemData, {
22+
field: 'agent.type',
23+
originalValue: 'endpoint',
24+
values: ['endpoint'],
25+
isObjectArray: false,
26+
});
27+
28+
expect(endpointAlertCheck({ data: mockEndpointDetailItemData })).toBeTruthy();
1729
});
1830
});
1931
});

x-pack/plugins/security_solution/public/common/utils/endpoint_alert_check.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ import { find } from 'lodash/fp';
99
import { TimelineEventsDetailsItem } from '../../../common/search_strategy';
1010

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

0 commit comments

Comments
 (0)