Skip to content

Commit

Permalink
Create plugin mock for event log plugin (#57048)
Browse files Browse the repository at this point in the history
* Create plugin mock for event log plugin

* Share event logger mock with event log service

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
mikecote and elasticmachine authored Feb 10, 2020
1 parent d31cf6a commit b5e28a8
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 11 deletions.
4 changes: 2 additions & 2 deletions x-pack/plugins/actions/server/lib/action_executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ActionExecutor } from './action_executor';
import { actionTypeRegistryMock } from '../action_type_registry.mock';
import { encryptedSavedObjectsMock } from '../../../encrypted_saved_objects/server/mocks';
import { savedObjectsClientMock, loggingServiceMock } from '../../../../../src/core/server/mocks';
import { createEventLoggerMock } from '../../../event_log/server/event_logger.mock';
import { eventLoggerMock } from '../../../event_log/server/mocks';

const actionExecutor = new ActionExecutor();
const savedObjectsClient = savedObjectsClientMock.create();
Expand Down Expand Up @@ -41,7 +41,7 @@ actionExecutor.initialize({
getServices,
actionTypeRegistry,
encryptedSavedObjectsPlugin,
eventLogger: createEventLoggerMock(),
eventLogger: eventLoggerMock.create(),
});

beforeEach(() => jest.resetAllMocks());
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/actions/server/lib/task_runner_factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { actionTypeRegistryMock } from '../action_type_registry.mock';
import { actionExecutorMock } from './action_executor.mock';
import { encryptedSavedObjectsMock } from '../../../encrypted_saved_objects/server/mocks';
import { savedObjectsClientMock, loggingServiceMock } from 'src/core/server/mocks';
import { createEventLoggerMock } from '../../../event_log/server/event_logger.mock';
import { eventLoggerMock } from '../../../event_log/server/mocks';

const spaceIdToNamespace = jest.fn();
const actionTypeRegistry = actionTypeRegistryMock.create();
Expand Down Expand Up @@ -59,7 +59,7 @@ const actionExecutorInitializerParams = {
getServices: jest.fn().mockReturnValue(services),
actionTypeRegistry,
encryptedSavedObjectsPlugin: mockedEncryptedSavedObjectsPlugin,
eventLogger: createEventLoggerMock(),
eventLogger: eventLoggerMock.create(),
};
const taskRunnerFactoryInitializerParams = {
spaceIdToNamespace,
Expand Down
25 changes: 25 additions & 0 deletions x-pack/plugins/event_log/server/event_log_service.mock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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 { IEventLogService } from './types';
import { eventLoggerMock } from './event_logger.mock';

const createEventLogServiceMock = () => {
const mock: jest.Mocked<IEventLogService> = {
isEnabled: jest.fn(),
isLoggingEntries: jest.fn(),
isIndexingEntries: jest.fn(),
registerProviderActions: jest.fn(),
isProviderActionRegistered: jest.fn(),
getProviderActions: jest.fn(),
getLogger: jest.fn().mockReturnValue(eventLoggerMock.create()),
};
return mock;
};

export const eventLogServiceMock = {
create: createEventLogServiceMock,
};
19 changes: 12 additions & 7 deletions x-pack/plugins/event_log/server/event_logger.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { IEvent, IEventLogger } from './types';
import { IEventLogger } from './types';

export function createEventLoggerMock(): IEventLogger {
return {
logEvent(eventProperties: IEvent): void {},
startTiming(event: IEvent): void {},
stopTiming(event: IEvent): void {},
const createEventLoggerMock = () => {
const mock: jest.Mocked<IEventLogger> = {
logEvent: jest.fn(),
startTiming: jest.fn(),
stopTiming: jest.fn(),
};
}
return mock;
};

export const eventLoggerMock = {
create: createEventLoggerMock,
};
23 changes: 23 additions & 0 deletions x-pack/plugins/event_log/server/mocks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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 { eventLogServiceMock } from './event_log_service.mock';

export { eventLogServiceMock };
export { eventLoggerMock } from './event_logger.mock';

const createSetupMock = () => {
return eventLogServiceMock.create();
};

const createStartMock = () => {
return undefined;
};

export const eventLogMock = {
createSetup: createSetupMock,
createStart: createStartMock,
};

0 comments on commit b5e28a8

Please sign in to comment.