-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Reporting] Set Fields into the SearchSource in Discover's getSharingData #123412
Changes from all commits
c32a3b7
2e13480
c090bab
10df2d3
005606b
b0bae75
a1b6963
8ed8d3a
8d0dfe3
3124ef0
84cb1cc
c3bca2c
f446486
369c596
9223061
bc72252
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,21 +69,6 @@ const mockDataClientSearchDefault = jest.fn().mockImplementation( | |
}, | ||
}) | ||
); | ||
const mockSearchSourceGetFieldDefault = jest.fn().mockImplementation((key: string) => { | ||
switch (key) { | ||
case 'fields': | ||
return ['date', 'ip', 'message']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This mock is not needed, as the Reporting code is no longer calling |
||
case 'index': | ||
return { | ||
fields: { | ||
getByName: jest.fn().mockImplementation(() => []), | ||
getByType: jest.fn().mockImplementation(() => []), | ||
}, | ||
metaFields: ['_id', '_index', '_type', '_score'], | ||
getFormatterForField: jest.fn(), | ||
}; | ||
} | ||
}); | ||
|
||
const mockFieldFormatsRegistry = { | ||
deserialize: jest | ||
|
@@ -123,14 +108,26 @@ beforeEach(async () => { | |
}) | ||
); | ||
|
||
searchSourceMock.getField = mockSearchSourceGetFieldDefault; | ||
searchSourceMock.getField = jest.fn((key: string) => { | ||
switch (key) { | ||
case 'index': | ||
return { | ||
fields: { | ||
getByName: jest.fn(() => []), | ||
getByType: jest.fn(() => []), | ||
}, | ||
metaFields: ['_id', '_index', '_type', '_score'], | ||
getFormatterForField: jest.fn(), | ||
}; | ||
} | ||
}); | ||
}); | ||
|
||
const logger = createMockLevelLogger(); | ||
|
||
it('formats an empty search result to CSV content', async () => { | ||
const generateCsv = new CsvGenerator( | ||
createMockJob({}), | ||
createMockJob({ columns: ['date', 'ip', 'message'] }), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All of the mock jobs in the test had to be updated to explicitly set the set of columns in the parameters. Previously, columns could be empty since it was assumed that the fields were set into the SearchSource in the browser. This PR does set the fields into the SearchSource in the browser, but not for most use cases. If Reporting tries to get its CSV columns using Existing POST URLs that were generated in 7.13+ should still yield the same results. The tests don't yield the same results, because they took shortcuts by assuming the set of fields could be retrieved from the searchSource. |
||
mockConfig, | ||
{ | ||
es: mockEsClient, | ||
|
@@ -170,7 +167,7 @@ it('formats a search result to CSV content', async () => { | |
}) | ||
); | ||
const generateCsv = new CsvGenerator( | ||
createMockJob({}), | ||
createMockJob({ columns: ['date', 'ip', 'message'] }), | ||
mockConfig, | ||
{ | ||
es: mockEsClient, | ||
|
@@ -193,12 +190,6 @@ it('formats a search result to CSV content', async () => { | |
const HITS_TOTAL = 100; | ||
|
||
it('calculates the bytes of the content', async () => { | ||
searchSourceMock.getField = jest.fn().mockImplementation((key: string) => { | ||
if (key === 'fields') { | ||
return ['message']; | ||
} | ||
return mockSearchSourceGetFieldDefault(key); | ||
}); | ||
mockDataClient.search = jest.fn().mockImplementation(() => | ||
Rx.of({ | ||
rawResponse: { | ||
|
@@ -215,7 +206,7 @@ it('calculates the bytes of the content', async () => { | |
); | ||
|
||
const generateCsv = new CsvGenerator( | ||
createMockJob({}), | ||
createMockJob({ columns: ['message'] }), | ||
mockConfig, | ||
{ | ||
es: mockEsClient, | ||
|
@@ -267,7 +258,7 @@ it('warns if max size was reached', async () => { | |
); | ||
|
||
const generateCsv = new CsvGenerator( | ||
createMockJob({}), | ||
createMockJob({ columns: ['date', 'ip', 'message'] }), | ||
mockConfig, | ||
{ | ||
es: mockEsClient, | ||
|
@@ -321,7 +312,7 @@ it('uses the scrollId to page all the data', async () => { | |
}); | ||
|
||
const generateCsv = new CsvGenerator( | ||
createMockJob({}), | ||
createMockJob({ columns: ['date', 'ip', 'message'] }), | ||
mockConfig, | ||
{ | ||
es: mockEsClient, | ||
|
@@ -361,12 +352,6 @@ it('uses the scrollId to page all the data', async () => { | |
|
||
describe('fields from job.searchSource.getFields() (7.12 generated)', () => { | ||
it('cells can be multi-value', async () => { | ||
searchSourceMock.getField = jest.fn().mockImplementation((key: string) => { | ||
if (key === 'fields') { | ||
return ['_id', 'sku']; | ||
} | ||
return mockSearchSourceGetFieldDefault(key); | ||
}); | ||
mockDataClient.search = jest.fn().mockImplementation(() => | ||
Rx.of({ | ||
rawResponse: { | ||
|
@@ -388,7 +373,7 @@ describe('fields from job.searchSource.getFields() (7.12 generated)', () => { | |
); | ||
|
||
const generateCsv = new CsvGenerator( | ||
createMockJob({ searchSource: {} }), | ||
createMockJob({ searchSource: {}, columns: ['_id', 'sku'] }), | ||
mockConfig, | ||
{ | ||
es: mockEsClient, | ||
|
@@ -409,12 +394,6 @@ describe('fields from job.searchSource.getFields() (7.12 generated)', () => { | |
}); | ||
|
||
it('provides top-level underscored fields as columns', async () => { | ||
searchSourceMock.getField = jest.fn().mockImplementation((key: string) => { | ||
if (key === 'fields') { | ||
return ['_id', '_index', 'date', 'message']; | ||
} | ||
return mockSearchSourceGetFieldDefault(key); | ||
}); | ||
mockDataClient.search = jest.fn().mockImplementation(() => | ||
Rx.of({ | ||
rawResponse: { | ||
|
@@ -445,6 +424,7 @@ describe('fields from job.searchSource.getFields() (7.12 generated)', () => { | |
fields: ['_id', '_index', '@date', 'message'], | ||
filter: [], | ||
}, | ||
columns: ['_id', '_index', 'date', 'message'], | ||
}), | ||
mockConfig, | ||
{ | ||
|
@@ -468,12 +448,6 @@ describe('fields from job.searchSource.getFields() (7.12 generated)', () => { | |
}); | ||
|
||
it('sorts the fields when they are to be used as table column names', async () => { | ||
searchSourceMock.getField = jest.fn().mockImplementation((key: string) => { | ||
if (key === 'fields') { | ||
return ['*']; | ||
} | ||
return mockSearchSourceGetFieldDefault(key); | ||
}); | ||
mockDataClient.search = jest.fn().mockImplementation(() => | ||
Rx.of({ | ||
rawResponse: { | ||
|
@@ -620,13 +594,7 @@ describe('fields from job.columns (7.13+ generated)', () => { | |
expect(content).toMatchSnapshot(); | ||
}); | ||
|
||
it('empty columns defaults to using searchSource.getFields()', async () => { | ||
searchSourceMock.getField = jest.fn().mockImplementation((key: string) => { | ||
if (key === 'fields') { | ||
return ['product']; | ||
} | ||
return mockSearchSourceGetFieldDefault(key); | ||
}); | ||
it('default column names come from tabify', async () => { | ||
mockDataClient.search = jest.fn().mockImplementation(() => | ||
Rx.of({ | ||
rawResponse: { | ||
|
@@ -694,7 +662,7 @@ describe('formulas', () => { | |
); | ||
|
||
const generateCsv = new CsvGenerator( | ||
createMockJob({}), | ||
createMockJob({ columns: ['date', 'ip', 'message'] }), | ||
mockConfig, | ||
{ | ||
es: mockEsClient, | ||
|
@@ -736,15 +704,8 @@ describe('formulas', () => { | |
}) | ||
); | ||
|
||
searchSourceMock.getField = jest.fn().mockImplementation((key: string) => { | ||
if (key === 'fields') { | ||
return ['date', 'ip', TEST_FORMULA]; | ||
} | ||
return mockSearchSourceGetFieldDefault(key); | ||
}); | ||
|
||
const generateCsv = new CsvGenerator( | ||
createMockJob({}), | ||
createMockJob({ columns: ['date', 'ip', TEST_FORMULA] }), | ||
mockConfig, | ||
{ | ||
es: mockEsClient, | ||
|
@@ -797,7 +758,7 @@ describe('formulas', () => { | |
); | ||
|
||
const generateCsv = new CsvGenerator( | ||
createMockJob({}), | ||
createMockJob({ columns: ['date', 'ip', 'message'] }), | ||
mockConfig, | ||
{ | ||
es: mockEsClient, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
outdated comment