/* * 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 { actionsClientMock } from './actions_client.mock'; import { PluginSetupContract, PluginStartContract, renderActionParameterTemplates } from './plugin'; import { Services } from './types'; import { elasticsearchServiceMock, savedObjectsClientMock, } from '../../../../src/core/server/mocks'; import { actionsAuthorizationMock } from './authorization/actions_authorization.mock'; export { actionsAuthorizationMock }; export { actionsClientMock }; const createSetupMock = () => { const mock: jest.Mocked = { registerType: jest.fn(), }; return mock; }; const createStartMock = () => { const mock: jest.Mocked = { isActionTypeEnabled: jest.fn(), isActionExecutable: jest.fn(), getActionsClientWithRequest: jest.fn().mockResolvedValue(actionsClientMock.create()), getActionsAuthorizationWithRequest: jest .fn() .mockReturnValue(actionsAuthorizationMock.create()), preconfiguredActions: [], renderActionParameterTemplates: jest.fn(), }; return mock; }; // this is a default renderer that escapes nothing export function renderActionParameterTemplatesDefault( actionTypeId: string, params: Record, variables: Record ) { return renderActionParameterTemplates(undefined, actionTypeId, params, variables); } const createServicesMock = () => { const mock: jest.Mocked< Services & { savedObjectsClient: ReturnType; } > = { callCluster: elasticsearchServiceMock.createLegacyScopedClusterClient().callAsCurrentUser, getLegacyScopedClusterClient: jest.fn(), savedObjectsClient: savedObjectsClientMock.create(), scopedClusterClient: elasticsearchServiceMock.createScopedClusterClient().asCurrentUser, }; return mock; }; export const actionsMock = { createServices: createServicesMock, createSetup: createSetupMock, createStart: createStartMock, };