-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b45370b
commit 0e9c318
Showing
1 changed file
with
82 additions
and
0 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
src/plugins/data/common/search/search_source/query_to_fields.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { EsQuerySortValue, queryToFields, SearchRequest, SortDirection } from '../..'; | ||
import { DataViewLazy } from '@kbn/data-views-plugin/common'; | ||
|
||
describe('SearchSource#queryToFields', () => { | ||
it('should include time field', async () => { | ||
const dataView = { | ||
timeFieldName: '@timestamp', | ||
getSourceFiltering: jest.fn(), | ||
getFields: jest.fn().mockResolvedValue({ | ||
getFieldMapSorted: jest.fn(), | ||
}), | ||
}; | ||
const request: SearchRequest = { query: [] }; | ||
await queryToFields({ dataView: dataView as unknown as DataViewLazy, request }); | ||
const { fieldName } = dataView.getFields.mock.calls[0][0]; | ||
expect(fieldName).toEqual(['@timestamp']); | ||
}); | ||
|
||
it('should include sort field', async () => { | ||
const dataView = { | ||
getSourceFiltering: jest.fn(), | ||
getFields: jest.fn().mockResolvedValue({ | ||
getFieldMapSorted: jest.fn(), | ||
}), | ||
}; | ||
const sort: EsQuerySortValue = { bytes: SortDirection.asc }; | ||
const request: SearchRequest = { query: [] }; | ||
await queryToFields({ dataView: dataView as unknown as DataViewLazy, sort, request }); | ||
const { fieldName } = dataView.getFields.mock.calls[0][0]; | ||
expect(fieldName).toEqual(['bytes']); | ||
}); | ||
|
||
it('should include request KQL query fields', async () => { | ||
const dataView = { | ||
timeFieldName: '@timestamp', | ||
getSourceFiltering: jest.fn(), | ||
getFields: jest.fn().mockResolvedValue({ | ||
getFieldMapSorted: jest.fn(), | ||
}), | ||
}; | ||
const request: SearchRequest = { | ||
query: [ | ||
{ | ||
language: 'kuery', | ||
query: 'log.level: debug AND NOT message: unknown', | ||
}, | ||
], | ||
}; | ||
await queryToFields({ dataView: dataView as unknown as DataViewLazy, request }); | ||
const { fieldName } = dataView.getFields.mock.calls[0][0]; | ||
expect(fieldName).toEqual(['@timestamp', 'log.level', 'message']); | ||
}); | ||
|
||
it('should not include request Lucene query fields', async () => { | ||
const dataView = { | ||
timeFieldName: '@timestamp', | ||
getSourceFiltering: jest.fn(), | ||
getFields: jest.fn().mockResolvedValue({ | ||
getFieldMapSorted: jest.fn(), | ||
}), | ||
}; | ||
const request: SearchRequest = { | ||
query: [ | ||
{ | ||
language: 'lucene', | ||
query: 'host: artifacts\\.*', | ||
}, | ||
], | ||
}; | ||
await queryToFields({ dataView: dataView as unknown as DataViewLazy, request }); | ||
const { fieldName } = dataView.getFields.mock.calls[0][0]; | ||
expect(fieldName).toEqual(['@timestamp']); | ||
}); | ||
}); |