* moved legacy actions api to legacy folder * introduced connector create api * added new delete route * added new execute and get_all * introduced all connector APIs * renamed action to connector in Apis * comment on camel case type * fixed va * updated docs * legacy title * corrected APIs * legacy links * added linik to deprecatred APIs * added linik to deprecatred APIs from index * moved legacy apis down one level * Apply suggestions from code review Co-authored-by: ymao1 <ying.mao@elastic.co> * renamed route file for connectorTypesRoute * define legacy route * Update docs/api/actions-and-connectors/legacy/index.asciidoc Co-authored-by: Mike Côté <mikecote@users.noreply.github.com> * api docs Co-authored-by: ymao1 <ying.mao@elastic.co> Co-authored-by: Mike Côté <mikecote@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
96 lines
3.2 KiB
TypeScript
96 lines
3.2 KiB
TypeScript
/*
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
* or more contributor license agreements. Licensed under the Elastic License
|
|
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
* 2.0.
|
|
*/
|
|
|
|
import { getAllActionRoute } from './get_all';
|
|
import { httpServiceMock } from 'src/core/server/mocks';
|
|
import { licenseStateMock } from '../lib/license_state.mock';
|
|
import { mockHandlerArguments } from './legacy/_mock_handler_arguments';
|
|
import { actionsClientMock } from '../actions_client.mock';
|
|
import { verifyAccessAndContext } from './verify_access_and_context';
|
|
|
|
jest.mock('./verify_access_and_context.ts', () => ({
|
|
verifyAccessAndContext: jest.fn(),
|
|
}));
|
|
|
|
beforeEach(() => {
|
|
jest.resetAllMocks();
|
|
(verifyAccessAndContext as jest.Mock).mockImplementation((license, handler) => handler);
|
|
});
|
|
|
|
describe('getAllActionRoute', () => {
|
|
it('get all actions with proper parameters', async () => {
|
|
const licenseState = licenseStateMock.create();
|
|
const router = httpServiceMock.createRouter();
|
|
|
|
getAllActionRoute(router, licenseState);
|
|
|
|
const [config, handler] = router.get.mock.calls[0];
|
|
|
|
expect(config.path).toMatchInlineSnapshot(`"/api/actions/connectors"`);
|
|
|
|
const actionsClient = actionsClientMock.create();
|
|
actionsClient.getAll.mockResolvedValueOnce([]);
|
|
|
|
const [context, req, res] = mockHandlerArguments({ actionsClient }, {}, ['ok']);
|
|
|
|
expect(await handler(context, req, res)).toMatchInlineSnapshot(`
|
|
Object {
|
|
"body": Array [],
|
|
}
|
|
`);
|
|
|
|
expect(actionsClient.getAll).toHaveBeenCalledTimes(1);
|
|
|
|
expect(res.ok).toHaveBeenCalledWith({
|
|
body: [],
|
|
});
|
|
});
|
|
|
|
it('ensures the license allows getting all actions', async () => {
|
|
const licenseState = licenseStateMock.create();
|
|
const router = httpServiceMock.createRouter();
|
|
|
|
getAllActionRoute(router, licenseState);
|
|
|
|
const [config, handler] = router.get.mock.calls[0];
|
|
|
|
expect(config.path).toMatchInlineSnapshot(`"/api/actions/connectors"`);
|
|
|
|
const actionsClient = actionsClientMock.create();
|
|
actionsClient.getAll.mockResolvedValueOnce([]);
|
|
|
|
const [context, req, res] = mockHandlerArguments({ actionsClient }, {}, ['ok']);
|
|
|
|
await handler(context, req, res);
|
|
|
|
expect(verifyAccessAndContext).toHaveBeenCalledWith(licenseState, expect.any(Function));
|
|
});
|
|
|
|
it('ensures the license check prevents getting all actions', async () => {
|
|
const licenseState = licenseStateMock.create();
|
|
const router = httpServiceMock.createRouter();
|
|
|
|
(verifyAccessAndContext as jest.Mock).mockImplementation(() => async () => {
|
|
throw new Error('OMG');
|
|
});
|
|
|
|
getAllActionRoute(router, licenseState);
|
|
|
|
const [config, handler] = router.get.mock.calls[0];
|
|
|
|
expect(config.path).toMatchInlineSnapshot(`"/api/actions/connectors"`);
|
|
|
|
const actionsClient = actionsClientMock.create();
|
|
actionsClient.getAll.mockResolvedValueOnce([]);
|
|
|
|
const [context, req, res] = mockHandlerArguments({ actionsClient }, {}, ['ok']);
|
|
|
|
expect(handler(context, req, res)).rejects.toMatchInlineSnapshot(`[Error: OMG]`);
|
|
|
|
expect(verifyAccessAndContext).toHaveBeenCalledWith(licenseState, expect.any(Function));
|
|
});
|
|
});
|