-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor parseData to handle generic source type
- Loading branch information
1 parent
f522c87
commit 4162918
Showing
2 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
plugins/main/public/components/common/data-grid/data-grid-service.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,47 @@ | ||
import { parseData } from './data-grid-service'; | ||
import { SearchResponse } from '../../../../../../src/core/server'; | ||
|
||
describe('describe-grid-test', () => { | ||
describe('parseData', () => { | ||
it('should parse data extract source fields correctly', () => { | ||
const resultsHits: SearchResponse['hits']['hits'] = [ | ||
{ | ||
_id: 'id-1', | ||
_index: 'index-1', | ||
_type: 'type-1', | ||
_score: 1, | ||
_source: { | ||
test: true, | ||
}, | ||
}, | ||
]; | ||
|
||
const expectedResult = [ | ||
{ | ||
_id: 'id-1', | ||
_index: 'index-1', | ||
_type: 'type-1', | ||
_score: 1, | ||
test: true, | ||
}, | ||
]; | ||
|
||
expect(parseData(resultsHits)).toEqual(expectedResult); | ||
}); | ||
|
||
it('should parse data handle invalid hits', () => { | ||
const resultsHits: SearchResponse['hits']['hits'] = [ | ||
// @ts-expect-error | ||
undefined, | ||
// @ts-expect-error | ||
null, | ||
// @ts-expect-error | ||
0, | ||
]; | ||
|
||
const expectedResult = [{}, {}, {}]; | ||
|
||
expect(parseData(resultsHits)).toEqual(expectedResult); | ||
}); | ||
}); | ||
}); |
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