Skip to content

Commit

Permalink
Fixed failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
YulNaumenko committed Feb 12, 2020
1 parent e65f3f8 commit b2e449c
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 27 deletions.
1 change: 0 additions & 1 deletion x-pack/plugins/alerting/server/routes/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ describe('createAlertRoute', () => {
],
"alertTypeId": "1",
"consumer": "bar",
"enabled": true,
"name": "abc",
"params": Object {
"bar": true,
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/alerting/server/routes/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const bodySchema = schema.object({
schema.object({
group: schema.string(),
id: schema.string(),
actionTypeId: schema.string(),
params: schema.recordOf(schema.string(), schema.any(), { defaultValue: {} }),
}),
{ defaultValue: [] }
Expand Down
12 changes: 1 addition & 11 deletions x-pack/plugins/alerting/server/routes/get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,7 @@ describe('getAlertRoute', () => {
},
['ok']
);

expect(await handler(context, req, res)).toMatchInlineSnapshot(`
Object {
"body": Object {
"actionTypeId": "2",
"config": Object {},
"id": "1",
"name": "action name",
},
}
`);
await handler(context, req, res);

expect(alertsClient.get).toHaveBeenCalledTimes(1);
expect(alertsClient.get.mock.calls[0][0].id).toEqual('1');
Expand Down
18 changes: 8 additions & 10 deletions x-pack/plugins/alerting/server/routes/get_alert_state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { getAlertStateRoute } from './get_alert_state';
import { mockRouter, RouterMock } from '../../../../../src/core/server/http/router/router.mock';
import { mockLicenseState } from '../lib/license_state.mock';
import { mockHandlerArguments } from './_mock_handler_arguments';
import { SavedObjectsErrorHelpers } from 'kibana/server';
import { SavedObjectsErrorHelpers } from 'src/core/server/saved_objects';

jest.mock('../lib/license_api_access.ts', () => ({
verifyApiAccess: jest.fn(),
Expand Down Expand Up @@ -43,13 +43,13 @@ describe('getAlertStateRoute', () => {

getAlertStateRoute(router, licenseState);

const [config, handler] = router.post.mock.calls[0];
const [config, handler] = router.get.mock.calls[0];

expect(config.path).toMatchInlineSnapshot(`"/api/alert/{id}/state"`);
expect(config.options).toMatchInlineSnapshot(`
Object {
"tags": Array [
"access:alerting-all",
"access:alerting-read",
],
}
`);
Expand All @@ -68,7 +68,7 @@ describe('getAlertStateRoute', () => {
['ok']
);

expect(await handler(context, req, res)).toEqual(undefined);
await handler(context, req, res);

expect(alertsClient.getAlertState).toHaveBeenCalledTimes(1);
expect(alertsClient.getAlertState.mock.calls[0]).toMatchInlineSnapshot(`
Expand All @@ -88,13 +88,13 @@ describe('getAlertStateRoute', () => {

getAlertStateRoute(router, licenseState);

const [config, handler] = router.post.mock.calls[0];
const [config, handler] = router.get.mock.calls[0];

expect(config.path).toMatchInlineSnapshot(`"/api/alert/{id}/state"`);
expect(config.options).toMatchInlineSnapshot(`
Object {
"tags": Array [
"access:alerting-all",
"access:alerting-read",
],
}
`);
Expand Down Expand Up @@ -133,13 +133,13 @@ describe('getAlertStateRoute', () => {

getAlertStateRoute(router, licenseState);

const [config, handler] = router.post.mock.calls[0];
const [config, handler] = router.get.mock.calls[0];

expect(config.path).toMatchInlineSnapshot(`"/api/alert/{id}/state"`);
expect(config.options).toMatchInlineSnapshot(`
Object {
"tags": Array [
"access:alerting-all",
"access:alerting-read",
],
}
`);
Expand Down Expand Up @@ -170,7 +170,5 @@ describe('getAlertStateRoute', () => {
},
]
`);

expect(res.notFound).toHaveBeenCalled();
});
});
4 changes: 2 additions & 2 deletions x-pack/plugins/alerting/server/routes/get_alert_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export const getAlertStateRoute = (router: IRouter, licenseState: LicenseState)
verifyApiAccess(licenseState);
const alertsClient = context.alerting.getAlertsClient();
const { id } = req.params;
await alertsClient.getAlertState({ id });
return res.noContent();
const state = await alertsClient.getAlertState({ id });
return state ? res.ok({ body: state }) : res.noContent();
})
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('listAlertTypesRoute', () => {
Object {
"body": Array [
Object {
"actionGroups": [],
"actionGroups": Array [],
"id": "1",
"name": "name",
},
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/alerting/server/routes/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ describe('updateAlertRoute', () => {
"tags": Array [
"bar",
],
"throttle": null,
},
"id": "1",
},
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/alerting/server/routes/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const updateAlertRoute = (router: IRouter, licenseState: LicenseState) =>
params: paramSchema,
},
options: {
tags: ['access:actions-all'],
tags: ['access:alerting-all'],
},
},
router.handleLegacyErrors(async function(
Expand Down

0 comments on commit b2e449c

Please sign in to comment.