diff --git a/x-pack/plugins/actions/server/lib/action_executor.test.ts b/x-pack/plugins/actions/server/lib/action_executor.test.ts index 7d4233db0f8d9..8301a13c82469 100644 --- a/x-pack/plugins/actions/server/lib/action_executor.test.ts +++ b/x-pack/plugins/actions/server/lib/action_executor.test.ts @@ -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(); @@ -41,7 +41,7 @@ actionExecutor.initialize({ getServices, actionTypeRegistry, encryptedSavedObjectsPlugin, - eventLogger: createEventLoggerMock(), + eventLogger: eventLoggerMock.create(), }); beforeEach(() => jest.resetAllMocks()); diff --git a/x-pack/plugins/actions/server/lib/task_runner_factory.test.ts b/x-pack/plugins/actions/server/lib/task_runner_factory.test.ts index 8890de2483290..fda1e2f5d2456 100644 --- a/x-pack/plugins/actions/server/lib/task_runner_factory.test.ts +++ b/x-pack/plugins/actions/server/lib/task_runner_factory.test.ts @@ -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(); @@ -59,7 +59,7 @@ const actionExecutorInitializerParams = { getServices: jest.fn().mockReturnValue(services), actionTypeRegistry, encryptedSavedObjectsPlugin: mockedEncryptedSavedObjectsPlugin, - eventLogger: createEventLoggerMock(), + eventLogger: eventLoggerMock.create(), }; const taskRunnerFactoryInitializerParams = { spaceIdToNamespace, diff --git a/x-pack/plugins/event_log/server/event_log_service.mock.ts b/x-pack/plugins/event_log/server/event_log_service.mock.ts new file mode 100644 index 0000000000000..805c241414a2e --- /dev/null +++ b/x-pack/plugins/event_log/server/event_log_service.mock.ts @@ -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 = { + 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, +}; diff --git a/x-pack/plugins/event_log/server/event_logger.mock.ts b/x-pack/plugins/event_log/server/event_logger.mock.ts index 97c2b9f980dcd..6a2c10b625b8e 100644 --- a/x-pack/plugins/event_log/server/event_logger.mock.ts +++ b/x-pack/plugins/event_log/server/event_logger.mock.ts @@ -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 = { + logEvent: jest.fn(), + startTiming: jest.fn(), + stopTiming: jest.fn(), }; -} + return mock; +}; + +export const eventLoggerMock = { + create: createEventLoggerMock, +}; diff --git a/x-pack/plugins/event_log/server/mocks.ts b/x-pack/plugins/event_log/server/mocks.ts new file mode 100644 index 0000000000000..aad6cf3e24561 --- /dev/null +++ b/x-pack/plugins/event_log/server/mocks.ts @@ -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, +};