From c011ef9c8101bbd35a6fbaf4aafe399ceaf8fd9c Mon Sep 17 00:00:00 2001 From: Larry Gregory Date: Fri, 28 Feb 2020 09:32:00 -0500 Subject: [PATCH] additional testing --- .../lib/copy_to_spaces/copy_to_spaces.test.ts | 4 - .../resolve_copy_conflicts.test.ts | 4 - x-pack/plugins/spaces/server/plugin.test.ts | 25 ++++++ .../saved_objects_service.test.ts | 82 +++++++++++++++++++ 4 files changed, 107 insertions(+), 8 deletions(-) create mode 100644 x-pack/plugins/spaces/server/saved_objects/saved_objects_service.test.ts diff --git a/x-pack/plugins/spaces/server/lib/copy_to_spaces/copy_to_spaces.test.ts b/x-pack/plugins/spaces/server/lib/copy_to_spaces/copy_to_spaces.test.ts index 9ef229159a8855f..7090aab9063c296 100644 --- a/x-pack/plugins/spaces/server/lib/copy_to_spaces/copy_to_spaces.test.ts +++ b/x-pack/plugins/spaces/server/lib/copy_to_spaces/copy_to_spaces.test.ts @@ -172,7 +172,6 @@ describe('copySavedObjectsToSpaces', () => { "_maxListeners": undefined, "_read": [Function], "_readableState": ReadableState { - "autoDestroy": false, "awaitDrain": 0, "buffer": BufferList { "head": null, @@ -192,7 +191,6 @@ describe('copySavedObjectsToSpaces', () => { "length": 0, "needReadable": false, "objectMode": true, - "paused": false, "pipes": null, "pipesCount": 0, "readableListening": false, @@ -225,7 +223,6 @@ describe('copySavedObjectsToSpaces', () => { "_maxListeners": undefined, "_read": [Function], "_readableState": ReadableState { - "autoDestroy": false, "awaitDrain": 0, "buffer": BufferList { "head": null, @@ -245,7 +242,6 @@ describe('copySavedObjectsToSpaces', () => { "length": 0, "needReadable": false, "objectMode": true, - "paused": false, "pipes": null, "pipesCount": 0, "readableListening": false, diff --git a/x-pack/plugins/spaces/server/lib/copy_to_spaces/resolve_copy_conflicts.test.ts b/x-pack/plugins/spaces/server/lib/copy_to_spaces/resolve_copy_conflicts.test.ts index 25ed4dee6d4d052..069be136c23abcc 100644 --- a/x-pack/plugins/spaces/server/lib/copy_to_spaces/resolve_copy_conflicts.test.ts +++ b/x-pack/plugins/spaces/server/lib/copy_to_spaces/resolve_copy_conflicts.test.ts @@ -191,7 +191,6 @@ describe('resolveCopySavedObjectsToSpacesConflicts', () => { "_maxListeners": undefined, "_read": [Function], "_readableState": ReadableState { - "autoDestroy": false, "awaitDrain": 0, "buffer": BufferList { "head": null, @@ -211,7 +210,6 @@ describe('resolveCopySavedObjectsToSpacesConflicts', () => { "length": 0, "needReadable": false, "objectMode": true, - "paused": false, "pipes": null, "pipesCount": 0, "readableListening": false, @@ -251,7 +249,6 @@ describe('resolveCopySavedObjectsToSpacesConflicts', () => { "_maxListeners": undefined, "_read": [Function], "_readableState": ReadableState { - "autoDestroy": false, "awaitDrain": 0, "buffer": BufferList { "head": null, @@ -271,7 +268,6 @@ describe('resolveCopySavedObjectsToSpacesConflicts', () => { "length": 0, "needReadable": false, "objectMode": true, - "paused": false, "pipes": null, "pipesCount": 0, "readableListening": false, diff --git a/x-pack/plugins/spaces/server/plugin.test.ts b/x-pack/plugins/spaces/server/plugin.test.ts index 4e3f4f52cbeb497..0b9905d5e9c95fa 100644 --- a/x-pack/plugins/spaces/server/plugin.test.ts +++ b/x-pack/plugins/spaces/server/plugin.test.ts @@ -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; + 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) + ); + }); }); }); diff --git a/x-pack/plugins/spaces/server/saved_objects/saved_objects_service.test.ts b/x-pack/plugins/spaces/server/saved_objects/saved_objects_service.test.ts new file mode 100644 index 000000000000000..4a9756d9e03f893 --- /dev/null +++ b/x-pack/plugins/spaces/server/saved_objects/saved_objects_service.test.ts @@ -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) + ); + }); + }); +});