Skip to content

Commit

Permalink
recover from Cleanup actions plugin PR
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuellr committed May 30, 2019
1 parent 2f04427 commit 8f44b79
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { ActionTypeService } from '../../action_type_service';
import { ActionTypeRegistry } from '../../action_type_registry';

import { registerBuiltInActionTypes } from '../index';

Expand All @@ -15,11 +15,11 @@ const services = {
log: NO_OP_FN,
};

let actionTypeService: ActionTypeService;
let actionTypeRegistry: ActionTypeRegistry;

beforeAll(() => {
actionTypeService = new ActionTypeService({ services });
registerBuiltInActionTypes(actionTypeService);
actionTypeRegistry = new ActionTypeRegistry({ services });
registerBuiltInActionTypes(actionTypeRegistry);
});

beforeEach(() => {
Expand All @@ -28,48 +28,48 @@ beforeEach(() => {

describe('action is registered', () => {
test('gets registered with builtin actions', () => {
expect(actionTypeService.has(ACTION_TYPE_ID)).toEqual(true);
expect(actionTypeRegistry.has(ACTION_TYPE_ID)).toEqual(true);
});
});

describe('get()', () => {
test('returns action type', () => {
const actionType = actionTypeService.get(ACTION_TYPE_ID);
const actionType = actionTypeRegistry.get(ACTION_TYPE_ID);
expect(actionType.id).toEqual(ACTION_TYPE_ID);
expect(actionType.name).toEqual('server-log');
});
});

describe('validateParams()', () => {
test('should validate and pass when params is valid', () => {
actionTypeService.validateParams(ACTION_TYPE_ID, { message: 'a message' });
actionTypeService.validateParams(ACTION_TYPE_ID, {
actionTypeRegistry.validateParams(ACTION_TYPE_ID, { message: 'a message' });
actionTypeRegistry.validateParams(ACTION_TYPE_ID, {
message: 'a message',
tags: ['info', 'blorg'],
});
});

test('should validate and throw error when params is invalid', () => {
expect(() => {
actionTypeService.validateParams(ACTION_TYPE_ID, {});
actionTypeRegistry.validateParams(ACTION_TYPE_ID, {});
}).toThrowErrorMatchingInlineSnapshot(
`"child \\"message\\" fails because [\\"message\\" is required]"`
);

expect(() => {
actionTypeService.validateParams(ACTION_TYPE_ID, { message: 1 });
actionTypeRegistry.validateParams(ACTION_TYPE_ID, { message: 1 });
}).toThrowErrorMatchingInlineSnapshot(
`"child \\"message\\" fails because [\\"message\\" must be a string]"`
);

expect(() => {
actionTypeService.validateParams(ACTION_TYPE_ID, { message: 'x', tags: 2 });
actionTypeRegistry.validateParams(ACTION_TYPE_ID, { message: 'x', tags: 2 });
}).toThrowErrorMatchingInlineSnapshot(
`"child \\"tags\\" fails because [\\"tags\\" must be an array]"`
);

expect(() => {
actionTypeService.validateParams(ACTION_TYPE_ID, { message: 'x', tags: [2] });
actionTypeRegistry.validateParams(ACTION_TYPE_ID, { message: 'x', tags: [2] });
}).toThrowErrorMatchingInlineSnapshot(
`"child \\"tags\\" fails because [\\"tags\\" at position 0 fails because [\\"0\\" must be a string]]"`
);
Expand All @@ -81,7 +81,7 @@ describe('execute()', () => {
const mockLog = jest.fn().mockResolvedValueOnce({ success: true });

services.log = mockLog;
await actionTypeService.execute({
await actionTypeRegistry.execute({
id: ACTION_TYPE_ID,
actionTypeConfig: {},
params: { message: 'message text here', tags: ['tag1', 'tag2'] },
Expand Down
8 changes: 4 additions & 4 deletions x-pack/plugins/actions/server/builtin_action_types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { ActionTypeService } from '../action_type_service';
import { ActionTypeRegistry } from '../action_type_registry';

import { actionType as serverLogActionType } from '././server_log';
import { actionType as serverLogActionType } from './server_log';

export function registerBuiltInActionTypes(actionTypeService: ActionTypeService) {
actionTypeService.register(serverLogActionType);
export function registerBuiltInActionTypes(actionTypeRegistry: ActionTypeRegistry) {
actionTypeRegistry.register(serverLogActionType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import Joi from 'joi';

import { ActionType, ExecutorOptions } from '../action_type_service';
import { ActionType, ExecutorOptions } from '../action_type_registry';

const DEFAULT_TAGS = ['info', 'alerting'];

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/actions/server/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function init(server: Legacy.Server) {
},
});

registerBuiltInActionTypes(actionTypeService);
registerBuiltInActionTypes(actionTypeRegistry);

// Routes
createRoute(server);
Expand Down

0 comments on commit 8f44b79

Please sign in to comment.