mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Fixes #21416 - this is identical to https://github.com/elastic/kibana/pull/21402, but adds testing to prevent a regression. @chrisronline in the interest of speed, time, and stability for 6.4, I opted not to do a full functional test, but rather an API test to ensure that the API endpoint was interacting with the Saved Objects Client as expected.
This commit is contained in:
parent
e74ee82266
commit
8ca8ed57cd
1 changed files with 86 additions and 0 deletions
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch B.V. under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch B.V. licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import Hapi from 'hapi';
|
||||
import { registerScrollForExportRoute } from './scroll';
|
||||
|
||||
const createMockServer = () => {
|
||||
const mockServer = new Hapi.Server({ debug: false });
|
||||
mockServer.connection({ port: 8080 });
|
||||
return mockServer;
|
||||
};
|
||||
|
||||
describe(`POST /api/kibana/management/saved_objects/scroll/export`, () => {
|
||||
test('requires "typesToInclude"', async () => {
|
||||
const mockServer = createMockServer();
|
||||
registerScrollForExportRoute(mockServer);
|
||||
|
||||
const headers = {};
|
||||
const payload = {};
|
||||
|
||||
const request = {
|
||||
method: 'POST',
|
||||
url: `/api/kibana/management/saved_objects/scroll/export`,
|
||||
headers,
|
||||
payload
|
||||
};
|
||||
|
||||
const { result, statusCode } = await mockServer.inject(request);
|
||||
expect(statusCode).toEqual(400);
|
||||
expect(result).toMatchObject({
|
||||
message: `child "typesToInclude" fails because ["typesToInclude" is required]`
|
||||
});
|
||||
});
|
||||
|
||||
test(`uses "typesToInclude" when searching for objects to export`, async () => {
|
||||
const mockServer = createMockServer();
|
||||
const mockClient = {
|
||||
find: jest.fn(() => {
|
||||
return {
|
||||
saved_objects: []
|
||||
};
|
||||
})
|
||||
};
|
||||
|
||||
mockServer.decorate('request', 'getSavedObjectsClient', () => mockClient);
|
||||
|
||||
registerScrollForExportRoute(mockServer);
|
||||
|
||||
const headers = {};
|
||||
const payload = {
|
||||
typesToInclude: ['foo', 'bar']
|
||||
};
|
||||
|
||||
const request = {
|
||||
method: 'POST',
|
||||
url: `/api/kibana/management/saved_objects/scroll/export`,
|
||||
headers,
|
||||
payload
|
||||
};
|
||||
|
||||
const { result, statusCode } = await mockServer.inject(request);
|
||||
expect(statusCode).toEqual(200);
|
||||
expect(result).toEqual([]);
|
||||
|
||||
expect(mockClient.find).toHaveBeenCalledWith({
|
||||
page: 1,
|
||||
perPage: 1000,
|
||||
type: ['foo', 'bar']
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue