Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

temp:Adds SOM integration tests for serverless #75

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ export const performFind = async <T = unknown, A = unknown>(
aggs,
migrationVersionCompatibility,
} = options;

if (!type) {
throw SavedObjectsErrorHelpers.createBadRequestError(
'options.type must be a string or an array of strings'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ export default function ({ getService }: FtrProviderContext) {
});

describe('index patterns', () => {
it('should validate visualization response schema', async () => {
it('should validate index-pattern response schema', async () => {
const resp = await supertest
.get(relationshipsUrl('index-pattern', '8963ca30-3224-11e8-a572-ffca06da1357'))
.expect(200);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import expect from '@kbn/expect';
import { SavedObjectWithMetadata } from '@kbn/saved-objects-management-plugin/common';
import { FtrProviderContext } from '../../../ftr_provider_context';
import { RoleCredentials } from '../../../../shared/services';

export default function ({ getService }: FtrProviderContext) {
const svlCommonApi = getService('svlCommonApi');
const svlUserManager = getService('svlUserManager');
const supertest = getService('supertest');
const kibanaServer = getService('kibanaServer');
let roleAuthc: RoleCredentials;

describe('_bulk_delete', () => {
const endpoint = '/internal/kibana/management/saved_objects/_bulk_delete';
const validObject = { type: 'visualization', id: 'dd7caf20-9efd-11e7-acb3-3dab96693fab' };
const invalidObject = { type: 'wigwags', id: 'foo' };

before(async () => {
roleAuthc = await svlUserManager.createApiKeyForRole('admin');
});

after(async () => {
await svlUserManager.invalidateApiKeyForRole(roleAuthc);
});

beforeEach(() =>
kibanaServer.importExport.load(
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json'
)
);
afterEach(() =>
kibanaServer.importExport.unload(
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json'
)
);

function expectSuccess(index: number, objs: SavedObjectWithMetadata[]) {
const { type, id, error } = objs[index];
expect(type).to.eql(validObject.type);
expect(id).to.eql(validObject.id);
expect(error).to.equal(undefined);
}

function expectBadRequest(index: number, objs: SavedObjectWithMetadata[]) {
const { type, id, error } = objs[index];
expect(type).to.eql(invalidObject.type);
expect(id).to.eql(invalidObject.id);
expect(error).to.eql({
message: `Unsupported saved object type: '${invalidObject.type}': Bad Request`,
statusCode: 400,
error: 'Bad Request',
});
}

it('should return 200 for an existing object', async () =>
await supertest
.post(endpoint)
.set(svlCommonApi.getInternalRequestHeader())
.set(roleAuthc.apiKeyHeader)
.send([validObject])
.expect(200)
.then(({ body }) => {
expect(body).to.have.length(1);
expectSuccess(0, body);
}));

it('should return error for invalid object type', async () =>
await supertest
.post(endpoint)
.set(svlCommonApi.getInternalRequestHeader())
.set(roleAuthc.apiKeyHeader)
.send([invalidObject])
.expect(200)
.then(({ body }) => {
expect(body).to.have.length(1);
expectBadRequest(0, body);
}));

it('should return mix of successes and errors', async () =>
await supertest
.post(endpoint)
.set(svlCommonApi.getInternalRequestHeader())
.set(roleAuthc.apiKeyHeader)
.send([validObject, invalidObject])
.expect(200)
.then(({ body }) => {
expect(body).to.have.length(2);
expectSuccess(0, body);
expectBadRequest(1, body);
}));
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import expect from '@kbn/expect';
import { SavedObjectWithMetadata } from '@kbn/saved-objects-management-plugin/common';
import { FtrProviderContext } from '../../../ftr_provider_context';
import { RoleCredentials } from '../../../../shared/services';

export default function ({ getService }: FtrProviderContext) {
const svlCommonApi = getService('svlCommonApi');
const svlUserManager = getService('svlUserManager');
const supertest = getService('supertest');
const kibanaServer = getService('kibanaServer');
let roleAuthc: RoleCredentials;

const URL = '/api/kibana/management/saved_objects/_bulk_get';
const validObject = { type: 'visualization', id: 'dd7caf20-9efd-11e7-acb3-3dab96693fab' };
const invalidObject = { type: 'wigwags', id: 'foo' };

describe('_bulk_get', () => {
before(async () => {
roleAuthc = await svlUserManager.createApiKeyForRole('admin');
});

after(async () => {
await svlUserManager.invalidateApiKeyForRole(roleAuthc);
});

describe('get objects in bulk', () => {
before(() =>
kibanaServer.importExport.load(
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json'
)
);
after(() =>
kibanaServer.importExport.unload(
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json'
)
);

function expectSuccess(index: number, objs: SavedObjectWithMetadata[]) {
const { type, id, meta, error } = objs[index];
expect(type).to.eql(validObject.type);
expect(id).to.eql(validObject.id);
expect(meta).to.not.equal(undefined);
expect(error).to.equal(undefined);
}

function expectBadRequest(index: number, objs: SavedObjectWithMetadata[]) {
const { type, id, error } = objs[index];
expect(type).to.eql(invalidObject.type);
expect(id).to.eql(invalidObject.id);
expect(error).to.eql({
message: `Unsupported saved object type: '${invalidObject.type}': Bad Request`,
statusCode: 400,
error: 'Bad Request',
});
}

it('should return 200 for object that exists and inject metadata', async () =>
await supertest
.post(URL)
.set(svlCommonApi.getInternalRequestHeader())
.set(roleAuthc.apiKeyHeader)
.send([validObject])
.expect(200)
.then(({ body }) => {
expect(body).to.have.length(1);
expectSuccess(0, body);
}));

it('should return error for invalid object type', async () =>
await supertest
.post(URL)
.set(svlCommonApi.getInternalRequestHeader())
.set(roleAuthc.apiKeyHeader)
.send([invalidObject])
.expect(200)
.then(({ body }) => {
expect(body).to.have.length(1);
expectBadRequest(0, body);
}));

it('should return mix of successes and errors', async () =>
await supertest
.post(URL)
.set(svlCommonApi.getInternalRequestHeader())
.set(roleAuthc.apiKeyHeader)
.send([validObject, invalidObject])
.expect(200)
.then(({ body }) => {
expect(body).to.have.length(2);
expectSuccess(0, body);
expectBadRequest(1, body);
}));
});
});
}
Loading
Loading