Skip to content

Commit

Permalink
Account for spaces being disabled in ClientsService
Browse files Browse the repository at this point in the history
* Updates types to reflect that spaces may be unavailable
* Adds a test for getSpaceId's behavior when spaces are disabled
  • Loading branch information
rylnd committed Feb 13, 2020
1 parent 4e9f8d8 commit f53e6f7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/siem/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export interface SetupPlugins {
encryptedSavedObjects: EncryptedSavedObjectsSetup;
features: FeaturesSetup;
security: SecuritySetup;
spaces: SpacesSetup;
spaces?: SpacesSetup;
}

export interface StartPlugins {
Expand Down
32 changes: 32 additions & 0 deletions x-pack/legacy/plugins/siem/server/services/clients.test.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});
});
});
10 changes: 4 additions & 6 deletions x-pack/legacy/plugins/siem/server/services/clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit f53e6f7

Please sign in to comment.