EMT-65:always return accurate endpoint count (#54423)
EMT-65:always return accurate endpoint count, independent of paging properties
This commit is contained in:
parent
487c096c41
commit
1d4c2f6ca1
|
@ -66,6 +66,7 @@ function mapToEndpointResultList(
|
|||
queryParams: Record<string, any>,
|
||||
searchResponse: SearchResponse<EndpointData>
|
||||
): EndpointResultList {
|
||||
const totalNumberOfEndpoints = searchResponse?.aggregations?.total?.value || 0;
|
||||
if (searchResponse.hits.hits.length > 0) {
|
||||
return {
|
||||
request_page_size: queryParams.size,
|
||||
|
@ -74,13 +75,13 @@ function mapToEndpointResultList(
|
|||
.map(response => response.inner_hits.most_recent.hits.hits)
|
||||
.flatMap(data => data as HitSource)
|
||||
.map(entry => entry._source),
|
||||
total: searchResponse.aggregations.total.value,
|
||||
total: totalNumberOfEndpoints,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
request_page_size: queryParams.size,
|
||||
request_index: queryParams.from,
|
||||
total: 0,
|
||||
total: totalNumberOfEndpoints,
|
||||
endpoints: [],
|
||||
};
|
||||
}
|
||||
|
|
|
@ -10,9 +10,24 @@ export default function({ getService }: FtrProviderContext) {
|
|||
const esArchiver = getService('esArchiver');
|
||||
const supertest = getService('supertest');
|
||||
describe('test endpoints api', () => {
|
||||
before(() => esArchiver.load('endpoint/endpoints'));
|
||||
after(() => esArchiver.unload('endpoint/endpoints'));
|
||||
describe('GET /api/endpoint/endpoints', () => {
|
||||
describe('POST /api/endpoint/endpoints when index is empty', () => {
|
||||
it('endpoints api should return empty result when index is empty', async () => {
|
||||
await esArchiver.unload('endpoint/endpoints');
|
||||
const { body } = await supertest
|
||||
.post('/api/endpoint/endpoints')
|
||||
.set('kbn-xsrf', 'xxx')
|
||||
.send()
|
||||
.expect(200);
|
||||
expect(body.total).to.eql(0);
|
||||
expect(body.endpoints.length).to.eql(0);
|
||||
expect(body.request_page_size).to.eql(10);
|
||||
expect(body.request_index).to.eql(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('POST /api/endpoint/endpoints when index is not empty', () => {
|
||||
before(() => esArchiver.load('endpoint/endpoints'));
|
||||
after(() => esArchiver.unload('endpoint/endpoints'));
|
||||
it('endpoints api should return one entry for each endpoint with default paging', async () => {
|
||||
const { body } = await supertest
|
||||
.post('/api/endpoint/endpoints')
|
||||
|
@ -46,6 +61,30 @@ export default function({ getService }: FtrProviderContext) {
|
|||
expect(body.request_index).to.eql(1);
|
||||
});
|
||||
|
||||
/* test that when paging properties produces no result, the total should reflect the actual number of endpoints
|
||||
in the index.
|
||||
*/
|
||||
it('endpoints api should return accurate total endpoints if page index produces no result', async () => {
|
||||
const { body } = await supertest
|
||||
.post('/api/endpoint/endpoints')
|
||||
.set('kbn-xsrf', 'xxx')
|
||||
.send({
|
||||
paging_properties: [
|
||||
{
|
||||
page_size: 10,
|
||||
},
|
||||
{
|
||||
page_index: 3,
|
||||
},
|
||||
],
|
||||
})
|
||||
.expect(200);
|
||||
expect(body.total).to.eql(3);
|
||||
expect(body.endpoints.length).to.eql(0);
|
||||
expect(body.request_page_size).to.eql(10);
|
||||
expect(body.request_index).to.eql(30);
|
||||
});
|
||||
|
||||
it('endpoints api should return 400 when pagingProperties is below boundaries.', async () => {
|
||||
const { body } = await supertest
|
||||
.post('/api/endpoint/endpoints')
|
||||
|
|
Loading…
Reference in a new issue