Skip to content

Commit

Permalink
Moving over the spaces only saved objects tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kobelb committed Sep 4, 2018
1 parent 94054a2 commit d3babea
Show file tree
Hide file tree
Showing 13 changed files with 1,265 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
"value": {
"index": ".kibana",
"type": "doc",
"id": "index-pattern:space_1:91200a00-9efd-11e7-acb3-3dab96693fab",
"id": "index-pattern:space_1:space_1-91200a00-9efd-11e7-acb3-3dab96693fab",
"source": {
"type": "index-pattern",
"updated_at": "2017-09-21T18:49:16.270Z",
Expand Down Expand Up @@ -206,7 +206,7 @@
"value": {
"index": ".kibana",
"type": "doc",
"id": "visualization:space_1:dd7caf20-9efd-11e7-acb3-3dab96693fab",
"id": "visualization:space_1:space_1-dd7caf20-9efd-11e7-acb3-3dab96693fab",
"source": {
"type": "visualization",
"updated_at": "2017-09-21T18:51:23.794Z",
Expand All @@ -230,7 +230,7 @@
"value": {
"index": ".kibana",
"type": "doc",
"id": "dashboard:space_1:be3733a0-9efe-11e7-acb3-3dab96693fab",
"id": "dashboard:space_1:space_1-be3733a0-9efe-11e7-acb3-3dab96693fab",
"source": {
"type": "dashboard",
"updated_at": "2017-09-21T18:57:40.826Z",
Expand Down Expand Up @@ -264,7 +264,7 @@
"value": {
"index": ".kibana",
"type": "doc",
"id": "visualization:space_1:dd7caf20-9efd-11e7-acb3-3dab96693faa",
"id": "visualization:space_1:space_1-dd7caf20-9efd-11e7-acb3-3dab96693faa",
"source": {
"type": "not-a-visualization",
"updated_at": "2017-09-21T18:51:23.794Z",
Expand All @@ -288,7 +288,7 @@
"value": {
"index": ".kibana",
"type": "doc",
"id": "index-pattern:space_2:91200a00-9efd-11e7-acb3-3dab96693fab",
"id": "index-pattern:space_2:space_2-91200a00-9efd-11e7-acb3-3dab96693fab",
"source": {
"type": "index-pattern",
"updated_at": "2017-09-21T18:49:16.270Z",
Expand Down Expand Up @@ -325,7 +325,7 @@
"value": {
"index": ".kibana",
"type": "doc",
"id": "visualization:space_2:dd7caf20-9efd-11e7-acb3-3dab96693fab",
"id": "visualization:space_2:space_2-dd7caf20-9efd-11e7-acb3-3dab96693fab",
"source": {
"type": "visualization",
"updated_at": "2017-09-21T18:51:23.794Z",
Expand All @@ -349,7 +349,7 @@
"value": {
"index": ".kibana",
"type": "doc",
"id": "dashboard:space_2:be3733a0-9efe-11e7-acb3-3dab96693fab",
"id": "dashboard:space_2:space_2-be3733a0-9efe-11e7-acb3-3dab96693fab",
"source": {
"type": "dashboard",
"updated_at": "2017-09-21T18:57:40.826Z",
Expand Down Expand Up @@ -383,7 +383,7 @@
"value": {
"index": ".kibana",
"type": "doc",
"id": "visualization:space_2:dd7caf20-9efd-11e7-acb3-3dab96693faa",
"id": "visualization:space_2:space_2-dd7caf20-9efd-11e7-acb3-3dab96693faa",
"source": {
"type": "not-a-visualization",
"updated_at": "2017-09-21T18:51:23.794Z",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { DEFAULT_SPACE_ID } from '../../../../plugins/spaces/common/constants';

export function getUrlPrefix(spaceId) {
return spaceId && spaceId !== DEFAULT_SPACE_ID ? `/s/${spaceId}` : ``;
}

export function getIdPrefix(spaceId) {
return spaceId === DEFAULT_SPACE_ID ? '' : `${spaceId}-`;
}

export function getExpectedSpaceIdProperty(spaceId) {
if (spaceId === DEFAULT_SPACE_ID) {
return {};
}
return {
spaceId
};
}
17 changes: 17 additions & 0 deletions x-pack/test/saved_object_api_integration/common/lib/spaces.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export const SPACES = {
SPACE_1: {
spaceId: 'space_1',
},
SPACE_2: {
spaceId: 'space_2',
},
DEFAULT: {
spaceId: 'default',
}
};
11 changes: 11 additions & 0 deletions x-pack/test/saved_object_api_integration/spaces_only/apis/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export default function ({ loadTestFile }) {
describe('apis spaces', () => {
loadTestFile(require.resolve('./saved_objects'));
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import expect from 'expect.js';
import { SPACES } from '../../../common/lib/spaces';
import { getIdPrefix, getUrlPrefix, getExpectedSpaceIdProperty } from '../../../common/lib/space_test_utils';

export default function ({ getService }) {
const supertest = getService('supertest');
const esArchiver = getService('esArchiver');

const BULK_REQUESTS = [
{
type: 'visualization',
id: 'dd7caf20-9efd-11e7-acb3-3dab96693fab',
},
{
type: 'dashboard',
id: 'does not exist',
},
{
type: 'config',
id: '7.0.0-alpha1',
},
];

const createBulkRequests = (spaceId) => BULK_REQUESTS.map(r => ({
...r,
id: `${getIdPrefix(spaceId)}${r.id}`
}));

describe('_bulk_get', () => {
const expectNotFoundResults = (spaceId) => resp => {
expect(resp.body).to.eql({
saved_objects: [
{
id: `${getIdPrefix(spaceId)}dd7caf20-9efd-11e7-acb3-3dab96693fab`,
type: 'visualization',
error: {
statusCode: 404,
message: 'Not found',
},
},
{
id: `${getIdPrefix(spaceId)}does not exist`,
type: 'dashboard',
error: {
statusCode: 404,
message: 'Not found',
},
},
//todo(legrego) fix when config is space aware
{
id: `${getIdPrefix(spaceId)}7.0.0-alpha1`,
type: 'config',
error: {
statusCode: 404,
message: 'Not found',
},
},
],
});
};

const expectResults = (spaceId) => resp => {
expect(resp.body).to.eql({
saved_objects: [
{
id: `${getIdPrefix(spaceId)}dd7caf20-9efd-11e7-acb3-3dab96693fab`,
type: 'visualization',
updated_at: '2017-09-21T18:51:23.794Z',
version: resp.body.saved_objects[0].version,
...getExpectedSpaceIdProperty(spaceId),
attributes: {
title: 'Count of requests',
description: '',
version: 1,
// cheat for some of the more complex attributes
visState: resp.body.saved_objects[0].attributes.visState,
uiStateJSON: resp.body.saved_objects[0].attributes.uiStateJSON,
kibanaSavedObjectMeta:
resp.body.saved_objects[0].attributes.kibanaSavedObjectMeta,
},
},
{
id: `${getIdPrefix(spaceId)}does not exist`,
type: 'dashboard',
error: {
statusCode: 404,
message: 'Not found',
},
},
//todo(legrego) fix when config is space aware
{
id: `${getIdPrefix(spaceId)}7.0.0-alpha1`,
type: 'config',
error: {
statusCode: 404,
message: 'Not found',
},
},
],
});
};

const bulkGetTest = (description, { spaceId, tests, otherSpaceId = spaceId }) => {
describe(description, () => {
before(() => esArchiver.load('saved_objects/spaces'));
after(() => esArchiver.unload('saved_objects/spaces'));

it(`should return ${tests.default.statusCode}`, async () => {
await supertest
.post(`${getUrlPrefix(spaceId)}/api/saved_objects/_bulk_get`)
.send(createBulkRequests(otherSpaceId))
.expect(tests.default.statusCode)
.then(tests.default.response);
});
});
};

bulkGetTest(`objects within the current space (space_1)`, {
...SPACES.SPACE_1,
tests: {
default: {
statusCode: 200,
response: expectResults(SPACES.SPACE_1.spaceId),
},
}
});

bulkGetTest(`objects within another space`, {
...SPACES.SPACE_1,
otherSpaceId: SPACES.SPACE_2.spaceId,
tests: {
default: {
statusCode: 200,
response: expectNotFoundResults(SPACES.SPACE_2.spaceId)
},
}
});

});
}
Loading

0 comments on commit d3babea

Please sign in to comment.