Skip to content

Commit

Permalink
additional testing
Browse files Browse the repository at this point in the history
  • Loading branch information
legrego committed Feb 28, 2020
1 parent 1596988 commit c011ef9
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ describe('copySavedObjectsToSpaces', () => {
"_maxListeners": undefined,
"_read": [Function],
"_readableState": ReadableState {
"autoDestroy": false,
"awaitDrain": 0,
"buffer": BufferList {
"head": null,
Expand All @@ -192,7 +191,6 @@ describe('copySavedObjectsToSpaces', () => {
"length": 0,
"needReadable": false,
"objectMode": true,
"paused": false,
"pipes": null,
"pipesCount": 0,
"readableListening": false,
Expand Down Expand Up @@ -225,7 +223,6 @@ describe('copySavedObjectsToSpaces', () => {
"_maxListeners": undefined,
"_read": [Function],
"_readableState": ReadableState {
"autoDestroy": false,
"awaitDrain": 0,
"buffer": BufferList {
"head": null,
Expand All @@ -245,7 +242,6 @@ describe('copySavedObjectsToSpaces', () => {
"length": 0,
"needReadable": false,
"objectMode": true,
"paused": false,
"pipes": null,
"pipesCount": 0,
"readableListening": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ describe('resolveCopySavedObjectsToSpacesConflicts', () => {
"_maxListeners": undefined,
"_read": [Function],
"_readableState": ReadableState {
"autoDestroy": false,
"awaitDrain": 0,
"buffer": BufferList {
"head": null,
Expand All @@ -211,7 +210,6 @@ describe('resolveCopySavedObjectsToSpacesConflicts', () => {
"length": 0,
"needReadable": false,
"objectMode": true,
"paused": false,
"pipes": null,
"pipesCount": 0,
"readableListening": false,
Expand Down Expand Up @@ -251,7 +249,6 @@ describe('resolveCopySavedObjectsToSpacesConflicts', () => {
"_maxListeners": undefined,
"_read": [Function],
"_readableState": ReadableState {
"autoDestroy": false,
"awaitDrain": 0,
"buffer": BufferList {
"head": null,
Expand All @@ -271,7 +268,6 @@ describe('resolveCopySavedObjectsToSpacesConflicts', () => {
"length": 0,
"needReadable": false,
"objectMode": true,
"paused": false,
"pipes": null,
"pipesCount": 0,
"readableListening": false,
Expand Down
25 changes: 25 additions & 0 deletions x-pack/plugins/spaces/server/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,30 @@ describe('Spaces Plugin', () => {

expect(usageCollection.getCollectorByType('spaces')).toBeDefined();
});

it('registers the "space" saved object type and client wrapper', async () => {
const initializerContext = coreMock.createPluginInitializerContext({});
const core = coreMock.createSetup() as CoreSetup<PluginsSetup>;
const features = featuresPluginMock.createSetup();
const licensing = licensingMock.createSetup();

const plugin = new Plugin(initializerContext);

await plugin.setup(core, { features, licensing });

expect(core.savedObjects.registerType).toHaveBeenCalledWith({
name: 'space',
namespaceAgnostic: true,
hidden: true,
mappings: expect.any(Object),
migrations: expect.any(Object),
});

expect(core.savedObjects.addClientWrapper).toHaveBeenCalledWith(
Number.MIN_SAFE_INTEGER,
'spaces',
expect.any(Function)
);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* 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 { coreMock } from 'src/core/server/mocks';
import { spacesServiceMock } from '../spaces_service/spaces_service.mock';
import { SpacesSavedObjectsService } from './saved_objects_service';

describe('SpacesSavedObjectsService', () => {
describe('#setup', () => {
it('registers the "space" saved object type with appropriate mappings and migrations', () => {
const core = coreMock.createSetup();
const spacesService = spacesServiceMock.createSetupContract();

const service = new SpacesSavedObjectsService();
service.setup({ core, spacesService });

expect(core.savedObjects.registerType).toHaveBeenCalledTimes(1);
expect(core.savedObjects.registerType.mock.calls[0]).toMatchInlineSnapshot(`
Array [
Object {
"hidden": true,
"mappings": Object {
"properties": Object {
"_reserved": Object {
"type": "boolean",
},
"color": Object {
"type": "keyword",
},
"description": Object {
"type": "text",
},
"disabledFeatures": Object {
"type": "keyword",
},
"imageUrl": Object {
"index": false,
"type": "text",
},
"initials": Object {
"type": "keyword",
},
"name": Object {
"fields": Object {
"keyword": Object {
"ignore_above": 2048,
"type": "keyword",
},
},
"type": "text",
},
},
},
"migrations": Object {
"6.6.0": [Function],
},
"name": "space",
"namespaceAgnostic": true,
},
]
`);
});

it('registers the client wrapper', () => {
const core = coreMock.createSetup();
const spacesService = spacesServiceMock.createSetupContract();

const service = new SpacesSavedObjectsService();
service.setup({ core, spacesService });

expect(core.savedObjects.addClientWrapper).toHaveBeenCalledTimes(1);
expect(core.savedObjects.addClientWrapper).toHaveBeenCalledWith(
Number.MIN_SAFE_INTEGER,
'spaces',
expect.any(Function)
);
});
});
});

0 comments on commit c011ef9

Please sign in to comment.