Skip to content

Commit

Permalink
add has_reference query parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
mshustov committed Feb 18, 2020
1 parent 6ff7d55 commit aaae92d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/core/server/saved_objects/routes/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ export const registerFindRoute = (router: IRouter) => {
schema.oneOf([schema.string(), schema.arrayOf(schema.string())])
),
sort_field: schema.maybe(schema.string()),
/* // TODO: need https://github.com/elastic/kibana/pull/55932 to be resolved
has_reference: schema.maybe(
schema.object({
type: schema.string(),
id: schema.string(),
})
),*/
),
fields: schema.maybe(schema.oneOf([schema.string(), schema.arrayOf(schema.string())])),
filter: schema.maybe(schema.string()),
}),
Expand All @@ -60,7 +59,7 @@ export const registerFindRoute = (router: IRouter) => {
searchFields:
typeof query.search_fields === 'string' ? [query.search_fields] : query.search_fields,
sortField: query.sort_field,
// hasReference: query.has_reference,
hasReference: query.has_reference,
fields: typeof query.fields === 'string' ? [query.fields] : query.fields,
filter: query.filter,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/

import supertest from 'supertest';
import querystring from 'querystring';

import { UnwrapPromise } from '@kbn/utility-types';
import { registerFindRoute } from '../find';
import { savedObjectsClientMock } from '../../../../../core/server/mocks';
Expand Down Expand Up @@ -126,6 +128,37 @@ describe('GET /api/saved_objects/_find', () => {
expect(options).toEqual({ perPage: 10, page: 50, type: ['foo'], defaultSearchOperator: 'OR' });
});

it('accepts the optional query parameter has_reference', async () => {
await supertest(httpSetup.server.listener)
.get('/api/saved_objects/_find?type=foo')
.expect(200);

expect(savedObjectsClient.find).toHaveBeenCalledTimes(1);

const options = savedObjectsClient.find.mock.calls[0][0];
expect(options.hasReference).toBe(undefined);
});

it('accepts the query parameter has_reference', async () => {
const references = querystring.escape(
JSON.stringify({
id: '1',
type: 'reference',
})
);
await supertest(httpSetup.server.listener)
.get(`/api/saved_objects/_find?type=foo&has_reference=${references}`)
.expect(200);

expect(savedObjectsClient.find).toHaveBeenCalledTimes(1);

const options = savedObjectsClient.find.mock.calls[0][0];
expect(options.hasReference).toEqual({
id: '1',
type: 'reference',
});
});

it('accepts the query parameter search_fields', async () => {
await supertest(httpSetup.server.listener)
.get('/api/saved_objects/_find?type=foo&search_fields=title')
Expand Down

0 comments on commit aaae92d

Please sign in to comment.