diff --git a/x-pack/legacy/plugins/siem/server/plugin.ts b/x-pack/legacy/plugins/siem/server/plugin.ts index 3221adbf12539..e15248e5200ee 100644 --- a/x-pack/legacy/plugins/siem/server/plugin.ts +++ b/x-pack/legacy/plugins/siem/server/plugin.ts @@ -37,7 +37,7 @@ export interface SetupPlugins { encryptedSavedObjects: EncryptedSavedObjectsSetup; features: FeaturesSetup; security: SecuritySetup; - spaces: SpacesSetup; + spaces?: SpacesSetup; } export interface StartPlugins { diff --git a/x-pack/legacy/plugins/siem/server/services/clients.test.ts b/x-pack/legacy/plugins/siem/server/services/clients.test.ts new file mode 100644 index 0000000000000..7f63a8f5e949c --- /dev/null +++ b/x-pack/legacy/plugins/siem/server/services/clients.test.ts @@ -0,0 +1,32 @@ +/* + * 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, httpServerMock } from '../../../../../../src/core/server/mocks'; +import { actionsMock } from '../../../../../plugins/actions/server/mocks'; + +import { ClientsService } from './clients'; + +describe('ClientsService', () => { + describe('spacesClient', () => { + describe('#getSpaceId', () => { + it('returns the default spaceId if spaces are disabled', async () => { + const clients = new ClientsService(); + + const actions = actionsMock.createStart(); + const { elasticsearch } = coreMock.createSetup(); + const { savedObjects } = coreMock.createStart(); + const request = httpServerMock.createRawRequest(); + const spacesService = undefined; + + clients.setup(elasticsearch.dataClient, spacesService); + clients.start(savedObjects, actions); + + const { spacesClient } = await clients.createGetScoped()(request); + expect(spacesClient.getSpaceId()).toEqual('default'); + }); + }); + }); +}); diff --git a/x-pack/legacy/plugins/siem/server/services/clients.ts b/x-pack/legacy/plugins/siem/server/services/clients.ts index cb78f6e5c7838..ca50eda4e7a6c 100644 --- a/x-pack/legacy/plugins/siem/server/services/clients.ts +++ b/x-pack/legacy/plugins/siem/server/services/clients.ts @@ -13,7 +13,8 @@ import { } from '../../../../../../src/core/server'; import { ActionsClient } from '../../../../../plugins/actions/server'; import { AlertsClient } from '../../../../../legacy/plugins/alerting/server'; -import { CoreStart, StartPlugins, SetupPlugins } from '../plugin'; +import { SpacesServiceSetup } from '../../../../../plugins/spaces/server'; +import { CoreStart, StartPlugins } from '../plugin'; export interface Clients { actionsClient?: ActionsClient; @@ -30,12 +31,9 @@ export class ClientsService { private actions?: StartPlugins['actions']; private clusterClient?: IClusterClient; private savedObjects?: CoreStart['savedObjects']; - private spacesService?: SetupPlugins['spaces']['spacesService']; + private spacesService?: SpacesServiceSetup; - public setup( - clusterClient: IClusterClient, - spacesService: SetupPlugins['spaces']['spacesService'] - ) { + public setup(clusterClient: IClusterClient, spacesService?: SpacesServiceSetup) { this.clusterClient = clusterClient; this.spacesService = spacesService; }