Skip to content

Commit

Permalink
creates so internal contracts mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Feb 5, 2020
1 parent cfe4aba commit 252f1de
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/core/server/legacy/legacy_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ beforeEach(() => {
getAuthHeaders: () => undefined,
} as any,
},
savedObjects: savedObjectsServiceMock.createSetupContract(),
savedObjects: savedObjectsServiceMock.createInternalSetupContract(),
plugins: {
contracts: new Map([['plugin-id', 'plugin-value']]),
uiPlugins: {
Expand All @@ -101,7 +101,7 @@ beforeEach(() => {
startDeps = {
core: {
capabilities: capabilitiesServiceMock.createStartContract(),
savedObjects: savedObjectsServiceMock.createStartContract(),
savedObjects: savedObjectsServiceMock.createInternalStartContract(),
uiSettings: uiSettingsServiceMock.createStartContract(),
plugins: { contracts: new Map() },
},
Expand Down
4 changes: 2 additions & 2 deletions src/core/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
42 changes: 31 additions & 11 deletions src/core/server/saved_objects/saved_objects_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -31,47 +33,65 @@ import { typeRegistryMock } from './saved_objects_type_registry.mock';
type SavedObjectsServiceContract = PublicMethodsOf<SavedObjectsService>;

const createStartContractMock = () => {
const startContract: jest.Mocked<InternalSavedObjectsServiceStart> = {
clientProvider: savedObjectsClientProviderMock.create(),
const startContrat: jest.Mocked<SavedObjectsServiceStart> = {
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<InternalSavedObjectsServiceStart> = {
...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<InternalSavedObjectsServiceSetup> = {
const setupContract: jest.Mocked<SavedObjectsServiceSetup> = {
setClientFactoryProvider: jest.fn(),
addClientWrapper: jest.fn(),
registerType: jest.fn(),
};

return setupContract;
};

const createInternalSetupContractMock = () => {
const internalSetupContract: jest.Mocked<InternalSavedObjectsServiceSetup> = {
...createSetupContractMock(),
registerType: jest.fn(),
};
return internalSetupContract;
};

const createSavedObjectsServiceMock = () => {
const mocked: jest.Mocked<SavedObjectsServiceContract> = {
setup: jest.fn(),
start: jest.fn(),
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,
};

0 comments on commit 252f1de

Please sign in to comment.