Skip to content

Commit e7c945f

Browse files
authored
Change alert and action HTTP DELETE to return 204 (#41933) (#42032)
* Change alert and action HTTP DELETE to return 204 Prior to this, a 200 was being returned, with some kind of body. That doesn't seem to be the usual response, eg the [Delete space][] API returns a 204 with no body. [Delete space]: https://www.elastic.co/guide/en/kibana/master/spaces-api-delete.html * resolve PR comments
1 parent f5208a4 commit e7c945f

File tree

13 files changed

+21
-21
lines changed

13 files changed

+21
-21
lines changed

x-pack/legacy/plugins/actions/server/routes/delete.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ it('deletes an action with proper parameters', async () => {
2222

2323
actionsClient.delete.mockResolvedValueOnce({ success: true });
2424
const { payload, statusCode } = await server.inject(request);
25-
expect(statusCode).toBe(200);
26-
const response = JSON.parse(payload);
27-
expect(response).toEqual({ success: true });
25+
expect(statusCode).toBe(204);
26+
expect(payload).toEqual('');
2827
expect(actionsClient.delete).toHaveBeenCalledTimes(1);
2928
expect(actionsClient.delete.mock.calls[0]).toMatchInlineSnapshot(`
3029
Array [

x-pack/legacy/plugins/actions/server/routes/delete.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ export function deleteRoute(server: Hapi.Server) {
2626
.required(),
2727
},
2828
},
29-
async handler(request: DeleteRequest) {
29+
async handler(request: DeleteRequest, h: Hapi.ResponseToolkit) {
3030
const { id } = request.params;
3131
const actionsClient = request.getActionsClient!();
32-
return await actionsClient.delete({ id });
32+
await actionsClient.delete({ id });
33+
return h.response().code(204);
3334
},
3435
});
3536
}

x-pack/legacy/plugins/alerting/server/routes/delete.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ test('deletes an alert with proper parameters', async () => {
2020

2121
alertsClient.delete.mockResolvedValueOnce({});
2222
const { payload, statusCode } = await server.inject(request);
23-
expect(statusCode).toBe(200);
24-
const response = JSON.parse(payload);
25-
expect(response).toEqual({});
23+
expect(statusCode).toBe(204);
24+
expect(payload).toEqual('');
2625
expect(alertsClient.delete).toHaveBeenCalledTimes(1);
2726
expect(alertsClient.delete.mock.calls[0]).toMatchInlineSnapshot(`
2827
Array [

x-pack/legacy/plugins/alerting/server/routes/delete.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ export function deleteAlertRoute(server: Hapi.Server) {
2626
.required(),
2727
},
2828
},
29-
async handler(request: DeleteRequest) {
29+
async handler(request: DeleteRequest, h: Hapi.ResponseToolkit) {
3030
const { id } = request.params;
3131
const alertsClient = request.getAlertsClient!();
32-
return await alertsClient.delete({ id });
32+
await alertsClient.delete({ id });
33+
return h.response().code(204);
3334
},
3435
});
3536
}

x-pack/test/api_integration/apis/actions/delete.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ export default function deleteActionTests({ getService }: KibanaFunctionalTestDe
1818
beforeEach(() => esArchiver.load('actions/basic'));
1919
afterEach(() => esArchiver.unload('actions/basic'));
2020

21-
it('should return 200 when deleting an action', async () => {
21+
it('should return 204 when deleting an action', async () => {
2222
await supertest
2323
.delete(`/api/action/${ES_ARCHIVER_ACTION_ID}`)
2424
.set('kbn-xsrf', 'foo')
25-
.expect(200, {});
25+
.expect(204, '');
2626
});
2727

2828
it(`should return 404 when action doesn't exist`, async () => {

x-pack/test/api_integration/apis/alerting/alerts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default function alertTests({ getService }: KibanaFunctionalTestDefaultPr
3131
return supertest
3232
.delete(`/api/alert/${id}`)
3333
.set('kbn-xsrf', 'foo')
34-
.expect(200);
34+
.expect(204, '');
3535
})
3636
);
3737
await esArchiver.unload('actions/basic');

x-pack/test/api_integration/apis/alerting/create.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export default function createAlertTests({ getService }: KibanaFunctionalTestDef
2525
return supertest
2626
.delete(`/api/alert/${id}`)
2727
.set('kbn-xsrf', 'foo')
28-
.expect(200);
28+
.expect(204, '');
2929
})
3030
);
3131
await esArchiver.unload('actions/basic');

x-pack/test/api_integration/apis/alerting/delete.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ export default function createDeleteTests({ getService }: KibanaFunctionalTestDe
3939
});
4040
}
4141

42-
it('should return 200 when deleting an alert and removing scheduled task', async () => {
42+
it('should return 204 when deleting an alert and removing scheduled task', async () => {
4343
await supertest
4444
.delete(`/api/alert/${alertId}`)
4545
.set('kbn-xsrf', 'foo')
46-
.expect(200);
46+
.expect(204, '');
4747
let hasThrownError = false;
4848
try {
4949
await getScheduledTask(scheduledTaskId);

x-pack/test/api_integration/apis/alerting/disable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default function createDisableAlertTests({
3333
await supertest
3434
.delete(`/api/alert/${createdAlert.id}`)
3535
.set('kbn-xsrf', 'foo')
36-
.expect(200);
36+
.expect(204, '');
3737
await esArchiver.unload('actions/basic');
3838
});
3939

x-pack/test/api_integration/apis/alerting/enable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default function createEnableAlertTests({
3333
await supertest
3434
.delete(`/api/alert/${createdAlert.id}`)
3535
.set('kbn-xsrf', 'foo')
36-
.expect(200);
36+
.expect(204, '');
3737
await esArchiver.unload('actions/basic');
3838
});
3939

0 commit comments

Comments
 (0)