From 252f1de3e371f3fa5f479bbf8e8da90101eb8b68 Mon Sep 17 00:00:00 2001 From: pgayvallet Date: Wed, 5 Feb 2020 16:02:01 +0100 Subject: [PATCH] creates so internal contracts mocks --- src/core/server/legacy/legacy_service.test.ts | 4 +- src/core/server/mocks.ts | 4 +- .../saved_objects_service.mock.ts | 42 ++++++++++++++----- 3 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/core/server/legacy/legacy_service.test.ts b/src/core/server/legacy/legacy_service.test.ts index af4db68ee95e1..e8e20580a36db 100644 --- a/src/core/server/legacy/legacy_service.test.ts +++ b/src/core/server/legacy/legacy_service.test.ts @@ -83,7 +83,7 @@ beforeEach(() => { getAuthHeaders: () => undefined, } as any, }, - savedObjects: savedObjectsServiceMock.createSetupContract(), + savedObjects: savedObjectsServiceMock.createInternalSetupContract(), plugins: { contracts: new Map([['plugin-id', 'plugin-value']]), uiPlugins: { @@ -101,7 +101,7 @@ beforeEach(() => { startDeps = { core: { capabilities: capabilitiesServiceMock.createStartContract(), - savedObjects: savedObjectsServiceMock.createStartContract(), + savedObjects: savedObjectsServiceMock.createInternalStartContract(), uiSettings: uiSettingsServiceMock.createStartContract(), plugins: { contracts: new Map() }, }, diff --git a/src/core/server/mocks.ts b/src/core/server/mocks.ts index 1dfb294ff8b38..9a7868d568ea0 100644 --- a/src/core/server/mocks.ts +++ b/src/core/server/mocks.ts @@ -153,7 +153,7 @@ function createInternalCoreSetupMock() { elasticsearch: elasticsearchServiceMock.createInternalSetup(), http: httpServiceMock.createSetupContract(), uiSettings: uiSettingsServiceMock.createSetupContract(), - savedObjects: savedObjectsServiceMock.createSetupContract(), + savedObjects: savedObjectsServiceMock.createInternalSetupContract(), uuid: uuidServiceMock.createSetupContract(), }; return setupDeps; @@ -162,7 +162,7 @@ function createInternalCoreSetupMock() { function createInternalCoreStartMock() { const startDeps: InternalCoreStart = { capabilities: capabilitiesServiceMock.createStartContract(), - savedObjects: savedObjectsServiceMock.createStartContract(), + savedObjects: savedObjectsServiceMock.createInternalStartContract(), uiSettings: uiSettingsServiceMock.createStartContract(), }; return startDeps; diff --git a/src/core/server/saved_objects/saved_objects_service.mock.ts b/src/core/server/saved_objects/saved_objects_service.mock.ts index 26003ab87d0c7..70f3d5a5b18e4 100644 --- a/src/core/server/saved_objects/saved_objects_service.mock.ts +++ b/src/core/server/saved_objects/saved_objects_service.mock.ts @@ -21,6 +21,8 @@ import { SavedObjectsService, InternalSavedObjectsServiceSetup, InternalSavedObjectsServiceStart, + SavedObjectsServiceSetup, + SavedObjectsServiceStart, } from './saved_objects_service'; import { mockKibanaMigrator } from './migrations/kibana/kibana_migrator.mock'; import { savedObjectsClientProviderMock } from './service/lib/scoped_client_provider.mock'; @@ -31,32 +33,48 @@ import { typeRegistryMock } from './saved_objects_type_registry.mock'; type SavedObjectsServiceContract = PublicMethodsOf; const createStartContractMock = () => { - const startContract: jest.Mocked = { - clientProvider: savedObjectsClientProviderMock.create(), + const startContrat: jest.Mocked = { getScopedClient: jest.fn(), createInternalRepository: jest.fn(), createScopedRepository: jest.fn(), createSerializer: jest.fn(), + }; + + startContrat.getScopedClient.mockReturnValue(savedObjectsClientMock.create()); + startContrat.createInternalRepository.mockReturnValue(savedObjectsRepositoryMock.create()); + startContrat.createScopedRepository.mockReturnValue(savedObjectsRepositoryMock.create()); + + return startContrat; +}; + +const createInternalStartContractMock = () => { + const internalStartContract: jest.Mocked = { + ...createStartContractMock(), + clientProvider: savedObjectsClientProviderMock.create(), migrator: mockKibanaMigrator.create(), typeRegistry: typeRegistryMock.create(), }; - startContract.getScopedClient.mockReturnValue(savedObjectsClientMock.create()); - startContract.createInternalRepository.mockReturnValue(savedObjectsRepositoryMock.create()); - startContract.createScopedRepository.mockReturnValue(savedObjectsRepositoryMock.create()); - - return startContract; + return internalStartContract; }; const createSetupContractMock = () => { - const setupContract: jest.Mocked = { + const setupContract: jest.Mocked = { setClientFactoryProvider: jest.fn(), addClientWrapper: jest.fn(), - registerType: jest.fn(), }; + return setupContract; }; +const createInternalSetupContractMock = () => { + const internalSetupContract: jest.Mocked = { + ...createSetupContractMock(), + registerType: jest.fn(), + }; + return internalSetupContract; +}; + const createSavedObjectsServiceMock = () => { const mocked: jest.Mocked = { setup: jest.fn(), @@ -64,14 +82,16 @@ const createSavedObjectsServiceMock = () => { stop: jest.fn(), }; - mocked.setup.mockResolvedValue(createSetupContractMock()); - mocked.start.mockResolvedValue(createStartContractMock()); + mocked.setup.mockResolvedValue(createInternalSetupContractMock()); + mocked.start.mockResolvedValue(createInternalStartContractMock()); mocked.stop.mockResolvedValue(); return mocked; }; export const savedObjectsServiceMock = { create: createSavedObjectsServiceMock, + createInternalSetupContract: createInternalSetupContractMock, createSetupContract: createSetupContractMock, + createInternalStartContract: createInternalStartContractMock, createStartContract: createStartContractMock, };