Skip to content

Commit

Permalink
[savedObjects] rename bulk_get/find apis to _bulk_get and _find
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Apr 3, 2018
1 parent 1e95d42 commit b064cb1
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 52 deletions.
6 changes: 3 additions & 3 deletions src/server/saved_objects/routes/__tests__/bulk_get.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,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;

Expand All @@ -29,7 +29,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'
Expand Down Expand Up @@ -62,7 +62,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
};

Expand Down
30 changes: 8 additions & 22 deletions src/server/saved_objects/routes/__tests__/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,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;

Expand All @@ -29,7 +29,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 = {
Expand Down Expand Up @@ -63,7 +63,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);
Expand All @@ -77,7 +77,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);
Expand All @@ -91,7 +91,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);
Expand All @@ -105,7 +105,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);
Expand All @@ -119,7 +119,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);
Expand All @@ -135,21 +135,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).to.be(true);

const options = savedObjectsClient.find.getCall(0).args[0];
expect(options).to.eql({ 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);
Expand Down
2 changes: 1 addition & 1 deletion src/server/saved_objects/routes/bulk_get.js
Original file line number Diff line number Diff line change
@@ -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],
Expand Down
10 changes: 1 addition & 9 deletions src/server/saved_objects/routes/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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));
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/ui/public/saved_objects/__tests__/saved_objects_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] } }));
});
Expand Down Expand Up @@ -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`
}));
});

Expand All @@ -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`
}));
});

Expand All @@ -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`
}));
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/ui/public/saved_objects/saved_objects_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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 => {
Expand Down
6 changes: 3 additions & 3 deletions test/api_integration/apis/saved_objects/bulk_get.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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 => {
Expand Down
16 changes: 8 additions & 8 deletions test/api_integration/apis/saved_objects/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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({
Expand All @@ -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({
Expand All @@ -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({
Expand All @@ -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({
Expand All @@ -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({
Expand All @@ -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({
Expand All @@ -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({
Expand Down

0 comments on commit b064cb1

Please sign in to comment.