|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch B.V. under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch B.V. licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +import { createPluginInitializerContext } from './plugin_context'; |
| 21 | +import { CoreContext } from '../core_context'; |
| 22 | +import { Env, ObjectToConfigAdapter } from '../config'; |
| 23 | +import { configServiceMock } from '../config/config_service.mock'; |
| 24 | +import { loggingServiceMock } from '../logging/logging_service.mock'; |
| 25 | +import { getEnvOptions } from '../config/__mocks__/env'; |
| 26 | +import { PluginManifest } from './types'; |
| 27 | +import { first } from 'rxjs/operators'; |
| 28 | + |
| 29 | +const logger = loggingServiceMock.create(); |
| 30 | +const configService = configServiceMock.create({ getConfig$: { globalConfig: { subpath: 1 } } }); |
| 31 | + |
| 32 | +let coreId: symbol; |
| 33 | +let env: Env; |
| 34 | +let coreContext: CoreContext; |
| 35 | + |
| 36 | +function createPluginManifest(manifestProps: Partial<PluginManifest> = {}): PluginManifest { |
| 37 | + return { |
| 38 | + id: 'some-plugin-id', |
| 39 | + version: 'some-version', |
| 40 | + configPath: 'path', |
| 41 | + kibanaVersion: '7.0.0', |
| 42 | + requiredPlugins: ['some-required-dep'], |
| 43 | + optionalPlugins: ['some-optional-dep'], |
| 44 | + server: true, |
| 45 | + ui: true, |
| 46 | + ...manifestProps, |
| 47 | + }; |
| 48 | +} |
| 49 | + |
| 50 | +beforeEach(() => { |
| 51 | + coreId = Symbol('core'); |
| 52 | + env = Env.createDefault(getEnvOptions()); |
| 53 | + coreContext = { coreId, env, logger, configService }; |
| 54 | +}); |
| 55 | + |
| 56 | +test('should return a globalConfig handler in the context (to be deprecated)', async () => { |
| 57 | + const manifest = createPluginManifest(); |
| 58 | + const opaqueId = Symbol(); |
| 59 | + const pluginInitializerContext = createPluginInitializerContext(coreContext, opaqueId, manifest); |
| 60 | + |
| 61 | + expect(pluginInitializerContext.config.globalConfig__deprecated$).toBeDefined(); |
| 62 | + |
| 63 | + const configObject = await pluginInitializerContext.config.globalConfig__deprecated$ |
| 64 | + .pipe(first()) |
| 65 | + .toPromise(); |
| 66 | + expect(configObject).toBeInstanceOf(ObjectToConfigAdapter); |
| 67 | + |
| 68 | + const configPaths = configObject.getFlattenedPaths(); |
| 69 | + expect(configPaths).toHaveLength(1); |
| 70 | + expect(configPaths).toStrictEqual(['globalConfig.subpath']); |
| 71 | + expect(configObject.has('globalConfig.subpath')).toBe(true); |
| 72 | + expect(configObject.get('globalConfig.subpath')).toBe(1); |
| 73 | +}); |
0 commit comments