Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierM committed Dec 10, 2020
1 parent 592c664 commit 66240b1
Show file tree
Hide file tree
Showing 4 changed files with 446 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { get, has, merge, uniq } from 'lodash/fp';
import { EventHit, TimelineEdges } from '../../../../../../common/search_strategy';
import { toStringArray } from '../../../../helpers/to_array';
import { formatGeoLocation } from '../details/helpers';
import { formatGeoLocation, isGeoField } from '../details/helpers';

export const formatTimelineData = (
dataFields: readonly string[],
Expand Down Expand Up @@ -57,7 +57,7 @@ const mergeTimelineFieldsWithHit = <T>(
field: fieldName,
value: specialFields.includes(fieldName)
? toStringArray(get(fieldName, hit))
: fieldName.includes('geo.location')
: isGeoField(fieldName)
? formatGeoLocation(hit.fields[fieldName])
: toStringArray(hit.fields[fieldName]),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('#getDataFromHits', () => {
originalValue: ['process'],
values: ['process'],
},
{ category: 'process', field: 'process.ppid', originalValue: [3977], values: ['3977'] },
{ category: 'process', field: 'process.ppid', originalValue: ['3977'], values: ['3977'] },
{ category: 'user', field: 'user.name', originalValue: ['jenkins'], values: ['jenkins'] },
{
category: 'process',
Expand All @@ -68,7 +68,7 @@ describe('#getDataFromHits', () => {
originalValue: ['Process go (PID: 4313) by user jenkins STARTED'],
values: ['Process go (PID: 4313) by user jenkins STARTED'],
},
{ category: 'process', field: 'process.pid', originalValue: [4313], values: ['4313'] },
{ category: 'process', field: 'process.pid', originalValue: ['4313'], values: ['4313'] },
{
category: 'process',
field: 'process.working_directory',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export const formatGeoLocation = (item: unknown[]) => {
return toStringArray(item);
};

export const isGeoField = (field: string) =>
field.includes('geo.location') || field.includes('geoip.location');

export const getDataFromHits = (fields: Record<string, unknown[]>): TimelineEventsDetailsItem[] =>
Object.keys(fields).reduce<TimelineEventsDetailsItem[]>((accumulator, field) => {
const item: unknown[] = fields[field];
Expand All @@ -40,8 +43,8 @@ export const getDataFromHits = (fields: Record<string, unknown[]>): TimelineEven
{
category: fieldCategory,
field,
values: field.includes('geo.location') ? formatGeoLocation(item) : toStringArray(item),
originalValue: item,
values: isGeoField(field) ? formatGeoLocation(item) : toStringArray(item),
originalValue: toStringArray(item),
} as TimelineEventsDetailsItem,
];
}, []);
Loading

0 comments on commit 66240b1

Please sign in to comment.