mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Changes action create/update http apis to return bodies (#42493)
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
This commit is contained in:
parent
396edb9504
commit
6acb716b2c
11 changed files with 77 additions and 13 deletions
|
@ -27,18 +27,21 @@ it('creates an action with proper parameters', async () => {
|
|||
};
|
||||
const createResult = {
|
||||
id: '1',
|
||||
type: 'action',
|
||||
description: 'My description',
|
||||
actionTypeId: 'abc',
|
||||
config: { foo: true },
|
||||
secrets: {},
|
||||
};
|
||||
|
||||
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' });
|
||||
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 [
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
import Joi from 'joi';
|
||||
import Hapi from 'hapi';
|
||||
import { WithoutQueryAndParams } from '../types';
|
||||
import { ActionResult, WithoutQueryAndParams } from '../types';
|
||||
|
||||
interface CreateRequest extends WithoutQueryAndParams<Hapi.Request> {
|
||||
query: {
|
||||
|
@ -42,13 +42,11 @@ export function createRoute(server: Hapi.Server) {
|
|||
.required(),
|
||||
},
|
||||
},
|
||||
async handler(request: CreateRequest) {
|
||||
async handler(request: CreateRequest): Promise<ActionResult> {
|
||||
const actionsClient = request.getActionsClient!();
|
||||
|
||||
const action = request.payload;
|
||||
const createdAction = await actionsClient.create({ action });
|
||||
|
||||
return { id: createdAction.id };
|
||||
return await actionsClient.create({ action });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
@ -35,7 +35,12 @@ it('calls the update function with proper parameters', async () => {
|
|||
const { payload, statusCode } = await server.inject(request);
|
||||
expect(statusCode).toBe(200);
|
||||
const response = JSON.parse(payload);
|
||||
expect(response).toEqual({ id: '1' });
|
||||
expect(response).toEqual({
|
||||
id: '1',
|
||||
actionTypeId: 'my-action-type-id',
|
||||
description: 'My description',
|
||||
config: { foo: true },
|
||||
});
|
||||
expect(actionsClient.update).toHaveBeenCalledTimes(1);
|
||||
expect(actionsClient.update.mock.calls[0]).toMatchInlineSnapshot(`
|
||||
Array [
|
||||
|
|
|
@ -42,8 +42,7 @@ export function updateRoute(server: Hapi.Server) {
|
|||
const { id } = request.params;
|
||||
const { description, config, secrets } = request.payload;
|
||||
const actionsClient = request.getActionsClient!();
|
||||
await actionsClient.update({ id, action: { description, config, secrets } });
|
||||
return { id };
|
||||
return await actionsClient.update({ id, action: { description, config, secrets } });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
@ -38,6 +38,15 @@ export default function emailTest({ getService }: FtrProviderContext) {
|
|||
createdActionId = createdAction.id;
|
||||
expect(createdAction).to.eql({
|
||||
id: createdActionId,
|
||||
description: 'An email action',
|
||||
actionTypeId: '.email',
|
||||
config: {
|
||||
service: '__json',
|
||||
host: null,
|
||||
port: null,
|
||||
secure: null,
|
||||
from: 'bob@example.com',
|
||||
},
|
||||
});
|
||||
|
||||
expect(typeof createdActionId).to.be('string');
|
||||
|
|
|
@ -35,7 +35,14 @@ export default function indexTest({ getService }: FtrProviderContext) {
|
|||
})
|
||||
.expect(200);
|
||||
|
||||
expect(createdAction).to.eql({ id: createdAction.id });
|
||||
expect(createdAction).to.eql({
|
||||
id: createdAction.id,
|
||||
description: 'An index action',
|
||||
actionTypeId: '.index',
|
||||
config: {
|
||||
index: null,
|
||||
},
|
||||
});
|
||||
createdActionID = createdAction.id;
|
||||
expect(typeof createdActionID).to.be('string');
|
||||
|
||||
|
@ -63,7 +70,14 @@ export default function indexTest({ getService }: FtrProviderContext) {
|
|||
})
|
||||
.expect(200);
|
||||
|
||||
expect(createdActionWithIndex).to.eql({ id: createdActionWithIndex.id });
|
||||
expect(createdActionWithIndex).to.eql({
|
||||
id: createdActionWithIndex.id,
|
||||
description: 'An index action with index config',
|
||||
actionTypeId: '.index',
|
||||
config: {
|
||||
index: ES_TEST_INDEX_NAME,
|
||||
},
|
||||
});
|
||||
createdActionIDWithIndex = createdActionWithIndex.id;
|
||||
expect(typeof createdActionIDWithIndex).to.be('string');
|
||||
|
||||
|
|
|
@ -30,6 +30,9 @@ export default function serverLogTest({ getService }: FtrProviderContext) {
|
|||
serverLogActionId = createdAction.id;
|
||||
expect(createdAction).to.eql({
|
||||
id: createdAction.id,
|
||||
description: 'A server.log action',
|
||||
actionTypeId: '.server-log',
|
||||
config: {},
|
||||
});
|
||||
|
||||
expect(typeof createdAction.id).to.be('string');
|
||||
|
|
|
@ -42,6 +42,9 @@ export default function slackTest({ getService }: FtrProviderContext) {
|
|||
|
||||
expect(createdAction).to.eql({
|
||||
id: createdAction.id,
|
||||
description: 'A slack action',
|
||||
actionTypeId: '.slack',
|
||||
config: {},
|
||||
});
|
||||
|
||||
expect(typeof createdAction.id).to.be('string');
|
||||
|
|
|
@ -32,6 +32,11 @@ export default function createActionTests({ getService }: FtrProviderContext) {
|
|||
.then((resp: any) => {
|
||||
expect(resp.body).to.eql({
|
||||
id: resp.body.id,
|
||||
description: 'My action',
|
||||
actionTypeId: 'test.index-record',
|
||||
config: {
|
||||
unencrypted: `This value shouldn't get encrypted`,
|
||||
},
|
||||
});
|
||||
expect(typeof resp.body.id).to.be('string');
|
||||
});
|
||||
|
@ -54,6 +59,11 @@ export default function createActionTests({ getService }: FtrProviderContext) {
|
|||
.expect(200);
|
||||
expect(createdAction).to.eql({
|
||||
id: createdAction.id,
|
||||
description: 'My action',
|
||||
actionTypeId: 'test.index-record',
|
||||
config: {
|
||||
unencrypted: `This value shouldn't get encrypted`,
|
||||
},
|
||||
});
|
||||
expect(typeof createdAction.id).to.be('string');
|
||||
await supertest.get(`/s/space_1/api/action/${createdAction.id}`).expect(200);
|
||||
|
|
|
@ -196,6 +196,11 @@ export default function({ getService }: FtrProviderContext) {
|
|||
.expect(200);
|
||||
expect(updatedAction).to.eql({
|
||||
id: ES_ARCHIVER_ACTION_ID,
|
||||
actionTypeId: 'test.index-record',
|
||||
description: 'My action updated',
|
||||
config: {
|
||||
unencrypted: `This value shouldn't get encrypted`,
|
||||
},
|
||||
});
|
||||
await supertest
|
||||
.post(`/api/action/${ES_ARCHIVER_ACTION_ID}/_fire`)
|
||||
|
|
|
@ -33,6 +33,11 @@ export default function updateActionTests({ getService }: FtrProviderContext) {
|
|||
.then((resp: any) => {
|
||||
expect(resp.body).to.eql({
|
||||
id: ES_ARCHIVER_ACTION_ID,
|
||||
actionTypeId: 'test.index-record',
|
||||
description: 'My action updated',
|
||||
config: {
|
||||
unencrypted: `This value shouldn't get encrypted`,
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -54,6 +59,11 @@ export default function updateActionTests({ getService }: FtrProviderContext) {
|
|||
.then((resp: any) => {
|
||||
expect(resp.body).to.eql({
|
||||
id: SPACE_1_ES_ARCHIVER_ACTION_ID,
|
||||
actionTypeId: 'test.index-record',
|
||||
description: 'My action updated',
|
||||
config: {
|
||||
unencrypted: `This value shouldn't get encrypted`,
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -110,6 +120,11 @@ export default function updateActionTests({ getService }: FtrProviderContext) {
|
|||
.expect(200);
|
||||
expect(updatedAction).to.eql({
|
||||
id: ES_ARCHIVER_ACTION_ID,
|
||||
actionTypeId: 'test.index-record',
|
||||
description: 'My action updated',
|
||||
config: {
|
||||
unencrypted: `This value shouldn't get encrypted`,
|
||||
},
|
||||
});
|
||||
const { body: fetchedAction } = await supertest
|
||||
.get(`/api/action/${ES_ARCHIVER_ACTION_ID}`)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue