xpack_main legacy plugin pre-removal cleanup (#76257)

* cleanup xpack_main legacy plugin, remove capabilities mixin

* fix test env

* delete injectXpackSignature and related tests
This commit is contained in:
Pierre Gayvallet 2020-09-01 12:19:06 +02:00 committed by GitHub
parent e7966e9d46
commit d802bf03f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 35 additions and 828 deletions

View file

@ -4,23 +4,30 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { coreMock, savedObjectsServiceMock } from 'src/core/server/mocks';
import { Plugin } from './plugin';
const initContext = coreMock.createPluginInitializerContext();
const coreSetup = coreMock.createSetup();
const coreStart = coreMock.createStart();
const typeRegistry = savedObjectsServiceMock.createTypeRegistryMock();
typeRegistry.getVisibleTypes.mockReturnValue([
{
name: 'foo',
hidden: false,
mappings: { properties: {} },
namespaceType: 'single' as 'single',
},
]);
coreStart.savedObjects.getTypeRegistry.mockReturnValue(typeRegistry);
describe('Features Plugin', () => {
let initContext: ReturnType<typeof coreMock.createPluginInitializerContext>;
let coreSetup: ReturnType<typeof coreMock.createSetup>;
let coreStart: ReturnType<typeof coreMock.createStart>;
let typeRegistry: ReturnType<typeof savedObjectsServiceMock.createTypeRegistryMock>;
beforeEach(() => {
initContext = coreMock.createPluginInitializerContext();
coreSetup = coreMock.createSetup();
coreStart = coreMock.createStart();
typeRegistry = savedObjectsServiceMock.createTypeRegistryMock();
typeRegistry.getVisibleTypes.mockReturnValue([
{
name: 'foo',
hidden: false,
mappings: { properties: {} },
namespaceType: 'single' as 'single',
},
]);
coreStart.savedObjects.getTypeRegistry.mockReturnValue(typeRegistry);
});
it('returns OSS + registered features', async () => {
const plugin = new Plugin(initContext);
const { registerFeature } = await plugin.setup(coreSetup, {});
@ -88,4 +95,12 @@ describe('Features Plugin', () => {
expect(soTypes.includes('foo')).toBe(true);
expect(soTypes.includes('bar')).toBe(false);
});
it('registers a capabilities provider', async () => {
const plugin = new Plugin(initContext);
await plugin.setup(coreSetup, {});
expect(coreSetup.capabilities.registerProvider).toHaveBeenCalledTimes(1);
expect(coreSetup.capabilities.registerProvider).toHaveBeenCalledWith(expect.any(Function));
});
});

View file

@ -61,10 +61,15 @@ export class Plugin {
featureRegistry: this.featureRegistry,
});
const getFeaturesUICapabilities = () =>
uiCapabilitiesForFeatures(this.featureRegistry.getAll());
core.capabilities.registerProvider(getFeaturesUICapabilities);
return deepFreeze({
registerFeature: this.featureRegistry.register.bind(this.featureRegistry),
getFeatures: this.featureRegistry.getAll.bind(this.featureRegistry),
getFeaturesUICapabilities: () => uiCapabilitiesForFeatures(this.featureRegistry.getAll()),
getFeaturesUICapabilities,
});
}