Skip to content

Commit

Permalink
Fix parsing bug
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Jul 14, 2020
1 parent f21e4cd commit b24f604
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ describe('Build KQL Query', () => {
expect(cleanUpKqlQuery(kqlQuery)).toEqual('@timestamp: 1521848183232');
});

test('Buld KQL query with one data provider as timestamp (numeric input as string)', () => {
const dataProviders = cloneDeep(mockDataProviders.slice(0, 1));
dataProviders[0].queryMatch.field = '@timestamp';
dataProviders[0].queryMatch.value = '1521848183232';
const kqlQuery = buildGlobalQuery(dataProviders, mockBrowserFields);
expect(cleanUpKqlQuery(kqlQuery)).toEqual('@timestamp: 1521848183232');
});

test('Build KQL query with one data provider as date type (string input)', () => {
const dataProviders = cloneDeep(mockDataProviders.slice(0, 1));
dataProviders[0].queryMatch.field = 'event.end';
Expand All @@ -70,6 +78,14 @@ describe('Build KQL Query', () => {
expect(cleanUpKqlQuery(kqlQuery)).toEqual('event.end: 1521848183232');
});

test('Buld KQL query with one data provider as date type (numeric input as string)', () => {
const dataProviders = cloneDeep(mockDataProviders.slice(0, 1));
dataProviders[0].queryMatch.field = 'event.end';
dataProviders[0].queryMatch.value = '1521848183232';
const kqlQuery = buildGlobalQuery(dataProviders, mockBrowserFields);
expect(cleanUpKqlQuery(kqlQuery)).toEqual('event.end: 1521848183232');
});

test('Build KQL query with two data provider', () => {
const dataProviders = cloneDeep(mockDataProviders.slice(0, 2));
const kqlQuery = buildGlobalQuery(dataProviders, mockBrowserFields);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { isEmpty, isNumber, get } from 'lodash/fp';
import { isEmpty, get } from 'lodash/fp';
import memoizeOne from 'memoize-one';

import { escapeQueryValue, convertToBuildEsQuery } from '../../../common/lib/keury';
Expand All @@ -23,6 +23,8 @@ import {
Filter,
} from '../../../../../../../src/plugins/data/public';

const isNumber = (value: string | number) => !isNaN(Number(value));

const convertDateFieldToQuery = (field: string, value: string | number) =>
`${field}: ${isNumber(value) ? value : new Date(value).valueOf()}`;

Expand Down

0 comments on commit b24f604

Please sign in to comment.