-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving over the spaces only saved objects tests
- Loading branch information
Showing
13 changed files
with
1,265 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
x-pack/test/saved_object_api_integration/common/lib/space_test_utils.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
17
x-pack/test/saved_object_api_integration/common/lib/spaces.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
11
x-pack/test/saved_object_api_integration/spaces_only/apis/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
}); | ||
} |
146 changes: 146 additions & 0 deletions
146
x-pack/test/saved_object_api_integration/spaces_only/apis/saved_objects/bulk_get.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}, | ||
} | ||
}); | ||
|
||
}); | ||
} |
Oops, something went wrong.