mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
This commit is contained in:
parent
bf7a0d2e82
commit
079f303357
8 changed files with 30 additions and 52 deletions
|
@ -1,7 +1,7 @@
|
|||
import Joi from 'joi';
|
||||
|
||||
export const createBulkGetRoute = (prereqs) => ({
|
||||
path: '/api/saved_objects/bulk_get',
|
||||
path: '/api/saved_objects/_bulk_get',
|
||||
method: 'POST',
|
||||
config: {
|
||||
pre: [prereqs.getSavedObjectsClient],
|
||||
|
|
|
@ -2,7 +2,7 @@ import sinon from 'sinon';
|
|||
import { createBulkGetRoute } from './bulk_get';
|
||||
import { MockServer } from './_mock_server';
|
||||
|
||||
describe('POST /api/saved_objects/bulk_get', () => {
|
||||
describe('POST /api/saved_objects/_bulk_get', () => {
|
||||
const savedObjectsClient = { bulkGet: sinon.stub() };
|
||||
let server;
|
||||
|
||||
|
@ -28,7 +28,7 @@ describe('POST /api/saved_objects/bulk_get', () => {
|
|||
it('formats successful response', async () => {
|
||||
const request = {
|
||||
method: 'POST',
|
||||
url: '/api/saved_objects/bulk_get',
|
||||
url: '/api/saved_objects/_bulk_get',
|
||||
payload: [{
|
||||
id: 'abc123',
|
||||
type: 'index-pattern'
|
||||
|
@ -61,7 +61,7 @@ describe('POST /api/saved_objects/bulk_get', () => {
|
|||
|
||||
const request = {
|
||||
method: 'POST',
|
||||
url: '/api/saved_objects/bulk_get',
|
||||
url: '/api/saved_objects/_bulk_get',
|
||||
payload: docs
|
||||
};
|
||||
|
||||
|
|
|
@ -2,14 +2,11 @@ import Joi from 'joi';
|
|||
import { keysToCamelCaseShallow } from '../../../utils/case_conversion';
|
||||
|
||||
export const createFindRoute = (prereqs) => ({
|
||||
path: '/api/saved_objects/{type?}',
|
||||
path: '/api/saved_objects/_find',
|
||||
method: 'GET',
|
||||
config: {
|
||||
pre: [prereqs.getSavedObjectsClient],
|
||||
validate: {
|
||||
params: Joi.object().keys({
|
||||
type: Joi.string()
|
||||
}).default(),
|
||||
query: Joi.object().keys({
|
||||
per_page: Joi.number().min(0).default(20),
|
||||
page: Joi.number().min(0).default(1),
|
||||
|
@ -21,11 +18,6 @@ export const createFindRoute = (prereqs) => ({
|
|||
},
|
||||
handler(request, reply) {
|
||||
const options = keysToCamelCaseShallow(request.query);
|
||||
|
||||
if (request.params.type) {
|
||||
options.type = request.params.type;
|
||||
}
|
||||
|
||||
reply(request.pre.savedObjectsClient.find(options));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ import sinon from 'sinon';
|
|||
import { createFindRoute } from './find';
|
||||
import { MockServer } from './_mock_server';
|
||||
|
||||
describe('GET /api/saved_objects/{type?}', () => {
|
||||
describe('GET /api/saved_objects/_find', () => {
|
||||
const savedObjectsClient = { find: sinon.stub() };
|
||||
let server;
|
||||
|
||||
|
@ -28,7 +28,7 @@ describe('GET /api/saved_objects/{type?}', () => {
|
|||
it('formats successful response', async () => {
|
||||
const request = {
|
||||
method: 'GET',
|
||||
url: '/api/saved_objects'
|
||||
url: '/api/saved_objects/_find'
|
||||
};
|
||||
|
||||
const clientResponse = {
|
||||
|
@ -62,7 +62,7 @@ describe('GET /api/saved_objects/{type?}', () => {
|
|||
it('calls upon savedObjectClient.find with defaults', async () => {
|
||||
const request = {
|
||||
method: 'GET',
|
||||
url: '/api/saved_objects'
|
||||
url: '/api/saved_objects/_find'
|
||||
};
|
||||
|
||||
await server.inject(request);
|
||||
|
@ -76,7 +76,7 @@ describe('GET /api/saved_objects/{type?}', () => {
|
|||
it('accepts the query parameter page/per_page', async () => {
|
||||
const request = {
|
||||
method: 'GET',
|
||||
url: '/api/saved_objects?per_page=10&page=50'
|
||||
url: '/api/saved_objects/_find?per_page=10&page=50'
|
||||
};
|
||||
|
||||
await server.inject(request);
|
||||
|
@ -90,7 +90,7 @@ describe('GET /api/saved_objects/{type?}', () => {
|
|||
it('accepts the query parameter search_fields', async () => {
|
||||
const request = {
|
||||
method: 'GET',
|
||||
url: '/api/saved_objects?search_fields=title'
|
||||
url: '/api/saved_objects/_find?search_fields=title'
|
||||
};
|
||||
|
||||
await server.inject(request);
|
||||
|
@ -104,7 +104,7 @@ describe('GET /api/saved_objects/{type?}', () => {
|
|||
it('accepts the query parameter fields as a string', async () => {
|
||||
const request = {
|
||||
method: 'GET',
|
||||
url: '/api/saved_objects?fields=title'
|
||||
url: '/api/saved_objects/_find?fields=title'
|
||||
};
|
||||
|
||||
await server.inject(request);
|
||||
|
@ -118,7 +118,7 @@ describe('GET /api/saved_objects/{type?}', () => {
|
|||
it('accepts the query parameter fields as an array', async () => {
|
||||
const request = {
|
||||
method: 'GET',
|
||||
url: '/api/saved_objects?fields=title&fields=description'
|
||||
url: '/api/saved_objects/_find?fields=title&fields=description'
|
||||
};
|
||||
|
||||
await server.inject(request);
|
||||
|
@ -134,21 +134,7 @@ describe('GET /api/saved_objects/{type?}', () => {
|
|||
it('accepts the type as a query parameter', async () => {
|
||||
const request = {
|
||||
method: 'GET',
|
||||
url: '/api/saved_objects?type=index-pattern'
|
||||
};
|
||||
|
||||
await server.inject(request);
|
||||
|
||||
expect(savedObjectsClient.find.calledOnce).toBe(true);
|
||||
|
||||
const options = savedObjectsClient.find.getCall(0).args[0];
|
||||
expect(options).toEqual({ perPage: 20, page: 1, type: 'index-pattern' });
|
||||
});
|
||||
|
||||
it('accepts the type as a URL parameter', async () => {
|
||||
const request = {
|
||||
method: 'GET',
|
||||
url: '/api/saved_objects/index-pattern'
|
||||
url: '/api/saved_objects/_find?type=index-pattern'
|
||||
};
|
||||
|
||||
await server.inject(request);
|
||||
|
|
|
@ -103,7 +103,7 @@ describe('SavedObjectsClient', () => {
|
|||
beforeEach(() => {
|
||||
$http.withArgs({
|
||||
method: 'POST',
|
||||
url: `${basePath}/api/saved_objects/bulk_get`,
|
||||
url: `${basePath}/api/saved_objects/_bulk_get`,
|
||||
data: sinon.match.any
|
||||
}).returns(Promise.resolve({ data: { saved_objects: [doc] } }));
|
||||
});
|
||||
|
@ -308,7 +308,7 @@ describe('SavedObjectsClient', () => {
|
|||
savedObjectsClient.find(body);
|
||||
sinon.assert.calledOnce($http);
|
||||
sinon.assert.calledWithExactly($http, sinon.match({
|
||||
url: `${basePath}/api/saved_objects/?type=index-pattern&invalid=true`
|
||||
url: `${basePath}/api/saved_objects/_find?type=index-pattern&invalid=true`
|
||||
}));
|
||||
});
|
||||
|
||||
|
@ -318,7 +318,7 @@ describe('SavedObjectsClient', () => {
|
|||
savedObjectsClient.find(body);
|
||||
sinon.assert.calledOnce($http);
|
||||
sinon.assert.calledWithExactly($http, sinon.match({
|
||||
url: `${basePath}/api/saved_objects/?fields=title&fields=description`
|
||||
url: `${basePath}/api/saved_objects/_find?fields=title&fields=description`
|
||||
}));
|
||||
});
|
||||
|
||||
|
@ -328,7 +328,7 @@ describe('SavedObjectsClient', () => {
|
|||
savedObjectsClient.find(body);
|
||||
sinon.assert.calledOnce($http);
|
||||
sinon.assert.alwaysCalledWith($http, sinon.match({
|
||||
url: `${basePath}/api/saved_objects/?from=50&size=10`
|
||||
url: `${basePath}/api/saved_objects/_find?from=50&size=10`
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
|
|
@ -82,7 +82,7 @@ export class SavedObjectsClient {
|
|||
* @returns {promise} - { savedObjects: [ SavedObject({ id, type, version, attributes }) ]}
|
||||
*/
|
||||
find(options = {}) {
|
||||
const url = this._getUrl([], keysToSnakeCaseShallow(options));
|
||||
const url = this._getUrl(['_find'], keysToSnakeCaseShallow(options));
|
||||
|
||||
return this._request('GET', url).then(resp => {
|
||||
resp.saved_objects = resp.saved_objects.map(d => this.createSavedObject(d));
|
||||
|
@ -121,7 +121,7 @@ export class SavedObjectsClient {
|
|||
* ])
|
||||
*/
|
||||
bulkGet(objects = []) {
|
||||
const url = this._getUrl(['bulk_get']);
|
||||
const url = this._getUrl(['_bulk_get']);
|
||||
const filteredObjects = objects.map(obj => _.pick(obj, ['id', 'type']));
|
||||
|
||||
return this._request('POST', url, filteredObjects).then(resp => {
|
||||
|
|
|
@ -20,14 +20,14 @@ export default function ({ getService }) {
|
|||
},
|
||||
];
|
||||
|
||||
describe('bulk_get', () => {
|
||||
describe('_bulk_get', () => {
|
||||
describe('with kibana index', () => {
|
||||
before(() => esArchiver.load('saved_objects/basic'));
|
||||
after(() => esArchiver.unload('saved_objects/basic'));
|
||||
|
||||
it('should return 200 with individual responses', async () => (
|
||||
await supertest
|
||||
.post(`/api/saved_objects/bulk_get`)
|
||||
.post(`/api/saved_objects/_bulk_get`)
|
||||
.send(BULK_REQUESTS)
|
||||
.expect(200)
|
||||
.then(resp => {
|
||||
|
@ -83,7 +83,7 @@ export default function ({ getService }) {
|
|||
|
||||
it('should return 200 with individual responses', async () => (
|
||||
await supertest
|
||||
.post('/api/saved_objects/bulk_get')
|
||||
.post('/api/saved_objects/_bulk_get')
|
||||
.send(BULK_REQUESTS)
|
||||
.expect(200)
|
||||
.then(resp => {
|
||||
|
|
|
@ -12,7 +12,7 @@ export default function ({ getService }) {
|
|||
|
||||
it('should return 200 with individual responses', async () => (
|
||||
await supertest
|
||||
.get('/api/saved_objects/visualization?fields=title')
|
||||
.get('/api/saved_objects/_find?type=visualization&fields=title')
|
||||
.expect(200)
|
||||
.then(resp => {
|
||||
expect(resp.body).to.eql({
|
||||
|
@ -36,7 +36,7 @@ export default function ({ getService }) {
|
|||
describe('unknown type', () => {
|
||||
it('should return 200 with empty response', async () => (
|
||||
await supertest
|
||||
.get('/api/saved_objects/wigwags')
|
||||
.get('/api/saved_objects/_find?type=wigwags')
|
||||
.expect(200)
|
||||
.then(resp => {
|
||||
expect(resp.body).to.eql({
|
||||
|
@ -52,7 +52,7 @@ export default function ({ getService }) {
|
|||
describe('page beyond total', () => {
|
||||
it('should return 200 with empty response', async () => (
|
||||
await supertest
|
||||
.get('/api/saved_objects/visualization?page=100&per_page=100')
|
||||
.get('/api/saved_objects/_find?type=visualization&page=100&per_page=100')
|
||||
.expect(200)
|
||||
.then(resp => {
|
||||
expect(resp.body).to.eql({
|
||||
|
@ -68,7 +68,7 @@ export default function ({ getService }) {
|
|||
describe('unknown search field', () => {
|
||||
it('should return 200 with empty response', async () => (
|
||||
await supertest
|
||||
.get('/api/saved_objects/wigwags?search_fields=a')
|
||||
.get('/api/saved_objects/_find?type=wigwags&search_fields=a')
|
||||
.expect(200)
|
||||
.then(resp => {
|
||||
expect(resp.body).to.eql({
|
||||
|
@ -93,7 +93,7 @@ export default function ({ getService }) {
|
|||
|
||||
it('should return 200 with empty response', async () => (
|
||||
await supertest
|
||||
.get('/api/saved_objects/visualization')
|
||||
.get('/api/saved_objects/_find?type=visualization')
|
||||
.expect(200)
|
||||
.then(resp => {
|
||||
expect(resp.body).to.eql({
|
||||
|
@ -108,7 +108,7 @@ export default function ({ getService }) {
|
|||
describe('unknown type', () => {
|
||||
it('should return 200 with empty response', async () => (
|
||||
await supertest
|
||||
.get('/api/saved_objects/wigwags')
|
||||
.get('/api/saved_objects/_find?type=wigwags')
|
||||
.expect(200)
|
||||
.then(resp => {
|
||||
expect(resp.body).to.eql({
|
||||
|
@ -124,7 +124,7 @@ export default function ({ getService }) {
|
|||
describe('page beyond total', () => {
|
||||
it('should return 200 with empty response', async () => (
|
||||
await supertest
|
||||
.get('/api/saved_objects/visualization?page=100&per_page=100')
|
||||
.get('/api/saved_objects/_find?type=visualization&page=100&per_page=100')
|
||||
.expect(200)
|
||||
.then(resp => {
|
||||
expect(resp.body).to.eql({
|
||||
|
@ -140,7 +140,7 @@ export default function ({ getService }) {
|
|||
describe('unknown search field', () => {
|
||||
it('should return 200 with empty response', async () => (
|
||||
await supertest
|
||||
.get('/api/saved_objects/wigwags?search_fields=a')
|
||||
.get('/api/saved_objects/_find?type=wigwags&search_fields=a')
|
||||
.expect(200)
|
||||
.then(resp => {
|
||||
expect(resp.body).to.eql({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue