kibana/x-pack/plugins/spaces/server/spaces_service/spaces_service.mock.ts
Larry Gregory 064fd8ef84
[7.x] Removing circular dependency between spaces and security (#81891) (#83841)
* Removing circular dependency between spaces and security

* Apply suggestions from code review

Co-authored-by: Constance <constancecchen@users.noreply.github.com>
Co-authored-by: Aleh Zasypkin <aleh.zasypkin@gmail.com>

* Tests refactor

- Reorganize top level describes into 3 space-based blocks into based on spaces:
  - space disabled
  - spaces plugin unavailable
  - space enabled (most previous tests go under this new block) with new beforeEach

- wrote new tests for uncovered lines 58, 66-69

* Review1: address PR feedback

* changing fake requests for alerts/actions

* Fixing tests

* fixing more tests

* Additional testing and refactoring

* Apply suggestions from code review

Co-authored-by: Aleh Zasypkin <aleh.zasypkin@gmail.com>

* Review 2: Address feedback

* Make ESLint happy again

Co-authored-by: Constance <constancecchen@users.noreply.github.com>
Co-authored-by: Aleh Zasypkin <aleh.zasypkin@gmail.com>
Co-authored-by: Constance Chen <constance.chen.3@gmail.com>

Co-authored-by: Constance <constancecchen@users.noreply.github.com>
Co-authored-by: Aleh Zasypkin <aleh.zasypkin@gmail.com>
Co-authored-by: Constance Chen <constance.chen.3@gmail.com>
2020-11-19 15:56:05 -05:00

36 lines
1.5 KiB
TypeScript

/*
* 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 { SpacesServiceSetup, SpacesServiceStart } from './spaces_service';
import { spacesClientMock } from '../spaces_client/spaces_client.mock';
import { DEFAULT_SPACE_ID } from '../../common/constants';
import { namespaceToSpaceId, spaceIdToNamespace } from '../lib/utils/namespace';
const createSetupContractMock = (spaceId = DEFAULT_SPACE_ID) => {
const setupContract: jest.Mocked<SpacesServiceSetup> = {
namespaceToSpaceId: jest.fn().mockImplementation(namespaceToSpaceId),
spaceIdToNamespace: jest.fn().mockImplementation(spaceIdToNamespace),
getSpaceId: jest.fn().mockReturnValue(spaceId),
};
return setupContract;
};
const createStartContractMock = (spaceId = DEFAULT_SPACE_ID) => {
const startContract: jest.Mocked<SpacesServiceStart> = {
namespaceToSpaceId: jest.fn().mockImplementation(namespaceToSpaceId),
spaceIdToNamespace: jest.fn().mockImplementation(spaceIdToNamespace),
createSpacesClient: jest.fn().mockReturnValue(spacesClientMock.create()),
getSpaceId: jest.fn().mockReturnValue(spaceId),
isInDefaultSpace: jest.fn().mockReturnValue(spaceId === DEFAULT_SPACE_ID),
getActiveSpace: jest.fn(),
};
return startContract;
};
export const spacesServiceMock = {
createSetupContract: createSetupContractMock,
createStartContract: createStartContractMock,
};