Skip to content

Commit

Permalink
removed consumer from api route
Browse files Browse the repository at this point in the history
  • Loading branch information
gmmorris committed Mar 2, 2020
1 parent 73111e5 commit 62036f3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 37 deletions.
14 changes: 7 additions & 7 deletions x-pack/plugins/alerting/server/routes/navigation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('getAlertNavigationRoute', () => {
},
},
],
consumer: 'bar',
consumer: 'test-consumer',
name: 'abc',
tags: ['foo'],
enabled: true,
Expand Down Expand Up @@ -79,7 +79,7 @@ describe('getAlertNavigationRoute', () => {
getAlertNavigationRoute(router, licenseState, alertTypeRegistry, alertNavigationRegistry);
const [config, handler] = router.get.mock.calls[0];

expect(config.path).toMatchInlineSnapshot(`"/api/alert/{id}/consumer/{consumer}/navigation"`);
expect(config.path).toMatchInlineSnapshot(`"/api/alert/{id}/navigation"`);
expect(config.options).toMatchInlineSnapshot(`
Object {
"tags": Array [
Expand All @@ -103,7 +103,7 @@ describe('getAlertNavigationRoute', () => {
const [context, req, res] = mockHandlerArguments(
{ alertsClient },
{
params: { id: '1', consumer: 'siem' },
params: { id: '1' },
},
['ok']
);
Expand All @@ -113,7 +113,7 @@ describe('getAlertNavigationRoute', () => {
expect(alertsClient.get.mock.calls[0][0].id).toEqual('1');

expect(alertTypeRegistry.get).toHaveBeenCalledWith('testAlertType');
expect(alertNavigationRegistry.get).toHaveBeenCalledWith('siem', mockedAlertType);
expect(alertNavigationRegistry.get).toHaveBeenCalledWith('test-consumer', mockedAlertType);

expect(res.ok).toHaveBeenCalledWith({
body: {
Expand All @@ -131,7 +131,7 @@ describe('getAlertNavigationRoute', () => {
getAlertNavigationRoute(router, licenseState, alertTypeRegistry, alertNavigationRegistry);
const [config, handler] = router.get.mock.calls[0];

expect(config.path).toMatchInlineSnapshot(`"/api/alert/{id}/consumer/{consumer}/navigation"`);
expect(config.path).toMatchInlineSnapshot(`"/api/alert/{id}/navigation"`);
expect(config.options).toMatchInlineSnapshot(`
Object {
"tags": Array [
Expand All @@ -153,7 +153,7 @@ describe('getAlertNavigationRoute', () => {
const [context, req, res] = mockHandlerArguments(
{ alertsClient },
{
params: { id: '1', consumer: 'siem' },
params: { id: '1' },
},
['ok']
);
Expand All @@ -163,7 +163,7 @@ describe('getAlertNavigationRoute', () => {
expect(alertsClient.get.mock.calls[0][0].id).toEqual('1');

expect(alertTypeRegistry.get).toHaveBeenCalledWith('testAlertType');
expect(alertNavigationRegistry.get).toHaveBeenCalledWith('siem', mockedAlertType);
expect(alertNavigationRegistry.get).toHaveBeenCalledWith('test-consumer', mockedAlertType);

expect(res.ok).toHaveBeenCalledWith({
body: {
Expand Down
7 changes: 3 additions & 4 deletions x-pack/plugins/alerting/server/routes/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { AlertTypeRegistry } from '../alert_type_registry';

const paramSchema = schema.object({
id: schema.string(),
consumer: schema.string(),
});

export const getAlertNavigationRoute = (
Expand All @@ -30,7 +29,7 @@ export const getAlertNavigationRoute = (
) => {
router.get(
{
path: `/api/alert/{id}/consumer/{consumer}/navigation`,
path: `/api/alert/{id}/navigation`,
validate: {
params: paramSchema,
},
Expand All @@ -44,11 +43,11 @@ export const getAlertNavigationRoute = (
res: KibanaResponseFactory
): Promise<IKibanaResponse<any>> {
verifyApiAccess(licenseState);
const { id, consumer } = req.params;
const { id } = req.params;
const alertsClient = context.alerting.getAlertsClient();
const alert = await alertsClient.get({ id });
const alertType = alertTypeRegistry.get(alert.alertTypeId);
const navigationHandler = alertNavigationRegistry.get(consumer, alertType);
const navigationHandler = alertNavigationRegistry.get(alert.consumer, alertType);
const state = navigationHandler(alert, alertType);
return res.ok({
body: typeof state === 'string' ? { url: state } : { state },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ export default function alertNavigationTests({ getService }: FtrProviderContext)
objectRemover.add(space.id, createdAlert.id, 'alert');

const response = await supertestWithoutAuth
.get(
`${getUrlPrefix(space.id)}/api/alert/${
createdAlert.id
}/consumer/${consumer}/navigation`
)
.get(`${getUrlPrefix(space.id)}/api/alert/${createdAlert.id}/navigation`)
.auth(user.username, user.password);

switch (scenario.id) {
Expand Down Expand Up @@ -96,11 +92,7 @@ export default function alertNavigationTests({ getService }: FtrProviderContext)
objectRemover.add(space.id, createdAlert.id, 'alert');

const response = await supertestWithoutAuth
.get(
`${getUrlPrefix('other')}/api/alert/${
createdAlert.id
}/consumer/${consumer}/navigation`
)
.get(`${getUrlPrefix('other')}/api/alert/${createdAlert.id}/navigation`)
.auth(user.username, user.password);

expect(response.statusCode).to.eql(404);
Expand Down Expand Up @@ -129,7 +121,7 @@ export default function alertNavigationTests({ getService }: FtrProviderContext)

it(`should handle get alert request appropriately when alert doesn't exist`, async () => {
const response = await supertestWithoutAuth
.get(`${getUrlPrefix(space.id)}/api/alert/1/consumer/${consumer}/navigation`)
.get(`${getUrlPrefix(space.id)}/api/alert/1/navigation`)
.auth(user.username, user.password);

switch (scenario.id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ export default function createGetTests({ getService }: FtrProviderContext) {
objectRemover.add(Spaces.space1.id, createdAlert.id, 'alert');

const response = await supertest.get(
`${getUrlPrefix(Spaces.space1.id)}/api/alert/${
createdAlert.id
}/consumer/${consumer}/navigation`
`${getUrlPrefix(Spaces.space1.id)}/api/alert/${createdAlert.id}/navigation`
);

expect(response.statusCode).to.eql(200);
Expand All @@ -53,11 +51,7 @@ export default function createGetTests({ getService }: FtrProviderContext) {
objectRemover.add(Spaces.space1.id, createdAlert.id, 'alert');

await supertest
.get(
`${getUrlPrefix(Spaces.other.id)}/api/alert/${
createdAlert.id
}/consumer/${consumer}/navigation`
)
.get(`${getUrlPrefix(Spaces.other.id)}/api/alert/${createdAlert.id}/navigation`)
.expect(404, {
statusCode: 404,
error: 'Not Found',
Expand All @@ -66,13 +60,11 @@ export default function createGetTests({ getService }: FtrProviderContext) {
});

it(`should handle get alert navigation request appropriately when alert doesn't exist`, async () => {
await supertest
.get(`${getUrlPrefix(Spaces.space1.id)}/api/alert/1/consumer/${consumer}/navigation`)
.expect(404, {
statusCode: 404,
error: 'Not Found',
message: 'Saved object [alert/1] not found',
});
await supertest.get(`${getUrlPrefix(Spaces.space1.id)}/api/alert/1/navigation`).expect(404, {
statusCode: 404,
error: 'Not Found',
message: 'Saved object [alert/1] not found',
});
});
});
}

0 comments on commit 62036f3

Please sign in to comment.