mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
Prior to this PR, the create and update http apis for actions returned an object with the shape `{ id: <id of relevant action> }`. This PR changes the responses to be the complete body of the action that was created / updated, not just the `id`. I believe this is the final piece of the "fix http apis for actions / alerts" issue https://github.com/elastic/kibana/issues/41828
60 lines
1.5 KiB
TypeScript
60 lines
1.5 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;
|
|
* you may not use this file except in compliance with the Elastic License.
|
|
*/
|
|
|
|
import { createMockServer } from './_mock_server';
|
|
import { createRoute } from './create';
|
|
|
|
const { server, actionsClient } = createMockServer();
|
|
createRoute(server);
|
|
|
|
beforeEach(() => {
|
|
jest.resetAllMocks();
|
|
});
|
|
|
|
it('creates an action with proper parameters', async () => {
|
|
const request = {
|
|
method: 'POST',
|
|
url: '/api/action',
|
|
payload: {
|
|
description: 'My description',
|
|
actionTypeId: 'abc',
|
|
config: { foo: true },
|
|
secrets: {},
|
|
},
|
|
};
|
|
const createResult = {
|
|
id: '1',
|
|
description: 'My description',
|
|
actionTypeId: 'abc',
|
|
config: { foo: true },
|
|
};
|
|
|
|
actionsClient.create.mockResolvedValueOnce(createResult);
|
|
const { payload, statusCode } = await server.inject(request);
|
|
expect(statusCode).toBe(200);
|
|
const response = JSON.parse(payload);
|
|
expect(response).toEqual({
|
|
id: '1',
|
|
description: 'My description',
|
|
actionTypeId: 'abc',
|
|
config: { foo: true },
|
|
});
|
|
expect(actionsClient.create).toHaveBeenCalledTimes(1);
|
|
expect(actionsClient.create.mock.calls[0]).toMatchInlineSnapshot(`
|
|
Array [
|
|
Object {
|
|
"action": Object {
|
|
"actionTypeId": "abc",
|
|
"config": Object {
|
|
"foo": true,
|
|
},
|
|
"description": "My description",
|
|
"secrets": Object {},
|
|
},
|
|
},
|
|
]
|
|
`);
|
|
});
|