mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 02:09:32 -04:00
Create unit test for registerBuiltInActionTypes and move common code (#45648)
* Create unit test for registerBuiltInActionTypes and move common code
This commit is contained in:
parent
68ffe7e18b
commit
c6e78599e8
6 changed files with 82 additions and 162 deletions
|
@ -9,13 +9,9 @@ jest.mock('./lib/send_email', () => ({
|
||||||
}));
|
}));
|
||||||
|
|
||||||
import { ActionType, ActionTypeExecutorOptions } from '../types';
|
import { ActionType, ActionTypeExecutorOptions } from '../types';
|
||||||
import { ActionsConfigurationUtilities } from '../actions_config';
|
import { validateConfig, validateSecrets, validateParams } from '../lib';
|
||||||
import { ActionTypeRegistry } from '../action_type_registry';
|
|
||||||
import { encryptedSavedObjectsMock } from '../../../encrypted_saved_objects/server/plugin.mock';
|
|
||||||
import { taskManagerMock } from '../../../task_manager/task_manager.mock';
|
|
||||||
import { validateParams, validateConfig, validateSecrets } from '../lib';
|
|
||||||
import { SavedObjectsClientMock } from '../../../../../../src/core/server/mocks';
|
import { SavedObjectsClientMock } from '../../../../../../src/core/server/mocks';
|
||||||
import { registerBuiltInActionTypes } from './index';
|
import { createActionTypeRegistry } from './index.test';
|
||||||
import { sendEmail } from './lib/send_email';
|
import { sendEmail } from './lib/send_email';
|
||||||
import { ActionParamsType, ActionTypeConfigType, ActionTypeSecretsType } from './email';
|
import { ActionParamsType, ActionTypeConfigType, ActionTypeSecretsType } from './email';
|
||||||
|
|
||||||
|
@ -23,12 +19,6 @@ const sendEmailMock = sendEmail as jest.Mock;
|
||||||
|
|
||||||
const ACTION_TYPE_ID = '.email';
|
const ACTION_TYPE_ID = '.email';
|
||||||
const NO_OP_FN = () => {};
|
const NO_OP_FN = () => {};
|
||||||
const MOCK_KIBANA_CONFIG_UTILS: ActionsConfigurationUtilities = {
|
|
||||||
isWhitelistedHostname: _ => true,
|
|
||||||
isWhitelistedUri: _ => true,
|
|
||||||
ensureWhitelistedHostname: _ => {},
|
|
||||||
ensureWhitelistedUri: _ => {},
|
|
||||||
};
|
|
||||||
|
|
||||||
const services = {
|
const services = {
|
||||||
log: NO_OP_FN,
|
log: NO_OP_FN,
|
||||||
|
@ -36,27 +26,10 @@ const services = {
|
||||||
savedObjectsClient: SavedObjectsClientMock.create(),
|
savedObjectsClient: SavedObjectsClientMock.create(),
|
||||||
};
|
};
|
||||||
|
|
||||||
function getServices() {
|
|
||||||
return services;
|
|
||||||
}
|
|
||||||
|
|
||||||
let actionTypeRegistry: ActionTypeRegistry;
|
|
||||||
let actionType: ActionType;
|
let actionType: ActionType;
|
||||||
|
|
||||||
const mockEncryptedSavedObjectsPlugin = encryptedSavedObjectsMock.create();
|
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
actionTypeRegistry = new ActionTypeRegistry({
|
const actionTypeRegistry = createActionTypeRegistry();
|
||||||
getServices,
|
|
||||||
isSecurityEnabled: true,
|
|
||||||
taskManager: taskManagerMock.create(),
|
|
||||||
encryptedSavedObjectsPlugin: mockEncryptedSavedObjectsPlugin,
|
|
||||||
spaceIdToNamespace: jest.fn().mockReturnValue(undefined),
|
|
||||||
getBasePath: jest.fn().mockReturnValue(undefined),
|
|
||||||
});
|
|
||||||
|
|
||||||
registerBuiltInActionTypes(actionTypeRegistry, MOCK_KIBANA_CONFIG_UTILS);
|
|
||||||
|
|
||||||
actionType = actionTypeRegistry.get(ACTION_TYPE_ID);
|
actionType = actionTypeRegistry.get(ACTION_TYPE_ID);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -64,12 +37,6 @@ beforeEach(() => {
|
||||||
jest.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('action is registered', () => {
|
|
||||||
test('gets registered with builtin actions', () => {
|
|
||||||
expect(actionTypeRegistry.has(ACTION_TYPE_ID)).toEqual(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('actionTypeRegistry.get() works', () => {
|
describe('actionTypeRegistry.get() works', () => {
|
||||||
test('action type static data is as expected', () => {
|
test('action type static data is as expected', () => {
|
||||||
expect(actionType.id).toEqual(ACTION_TYPE_ID);
|
expect(actionType.id).toEqual(ACTION_TYPE_ID);
|
||||||
|
|
|
@ -9,23 +9,13 @@ jest.mock('./lib/send_email', () => ({
|
||||||
}));
|
}));
|
||||||
|
|
||||||
import { ActionType, ActionTypeExecutorOptions } from '../types';
|
import { ActionType, ActionTypeExecutorOptions } from '../types';
|
||||||
import { ActionsConfigurationUtilities } from '../actions_config';
|
|
||||||
import { ActionTypeRegistry } from '../action_type_registry';
|
|
||||||
import { encryptedSavedObjectsMock } from '../../../encrypted_saved_objects/server/plugin.mock';
|
|
||||||
import { taskManagerMock } from '../../../task_manager/task_manager.mock';
|
|
||||||
import { validateConfig, validateParams } from '../lib';
|
import { validateConfig, validateParams } from '../lib';
|
||||||
import { SavedObjectsClientMock } from '../../../../../../src/core/server/mocks';
|
import { SavedObjectsClientMock } from '../../../../../../src/core/server/mocks';
|
||||||
import { registerBuiltInActionTypes } from './index';
|
import { createActionTypeRegistry } from './index.test';
|
||||||
import { ActionParamsType, ActionTypeConfigType } from './es_index';
|
import { ActionParamsType, ActionTypeConfigType } from './es_index';
|
||||||
|
|
||||||
const ACTION_TYPE_ID = '.index';
|
const ACTION_TYPE_ID = '.index';
|
||||||
const NO_OP_FN = () => {};
|
const NO_OP_FN = () => {};
|
||||||
const MOCK_KIBANA_CONFIG_UTILS: ActionsConfigurationUtilities = {
|
|
||||||
isWhitelistedHostname: _ => true,
|
|
||||||
isWhitelistedUri: _ => true,
|
|
||||||
ensureWhitelistedHostname: _ => {},
|
|
||||||
ensureWhitelistedUri: _ => {},
|
|
||||||
};
|
|
||||||
|
|
||||||
const services = {
|
const services = {
|
||||||
log: NO_OP_FN,
|
log: NO_OP_FN,
|
||||||
|
@ -33,27 +23,10 @@ const services = {
|
||||||
savedObjectsClient: SavedObjectsClientMock.create(),
|
savedObjectsClient: SavedObjectsClientMock.create(),
|
||||||
};
|
};
|
||||||
|
|
||||||
function getServices() {
|
|
||||||
return services;
|
|
||||||
}
|
|
||||||
|
|
||||||
let actionTypeRegistry: ActionTypeRegistry;
|
|
||||||
let actionType: ActionType;
|
let actionType: ActionType;
|
||||||
|
|
||||||
const mockEncryptedSavedObjectsPlugin = encryptedSavedObjectsMock.create();
|
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
actionTypeRegistry = new ActionTypeRegistry({
|
const actionTypeRegistry = createActionTypeRegistry();
|
||||||
getServices,
|
|
||||||
isSecurityEnabled: true,
|
|
||||||
taskManager: taskManagerMock.create(),
|
|
||||||
encryptedSavedObjectsPlugin: mockEncryptedSavedObjectsPlugin,
|
|
||||||
spaceIdToNamespace: jest.fn().mockReturnValue(undefined),
|
|
||||||
getBasePath: jest.fn().mockReturnValue(undefined),
|
|
||||||
});
|
|
||||||
|
|
||||||
registerBuiltInActionTypes(actionTypeRegistry, MOCK_KIBANA_CONFIG_UTILS);
|
|
||||||
|
|
||||||
actionType = actionTypeRegistry.get(ACTION_TYPE_ID);
|
actionType = actionTypeRegistry.get(ACTION_TYPE_ID);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -61,12 +34,6 @@ beforeEach(() => {
|
||||||
jest.resetAllMocks();
|
jest.resetAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('action is registered', () => {
|
|
||||||
test('gets registered with builtin actions', () => {
|
|
||||||
expect(actionTypeRegistry.has(ACTION_TYPE_ID)).toEqual(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('actionTypeRegistry.get() works', () => {
|
describe('actionTypeRegistry.get() works', () => {
|
||||||
test('action type static data is as expected', () => {
|
test('action type static data is as expected', () => {
|
||||||
expect(actionType.id).toEqual(ACTION_TYPE_ID);
|
expect(actionType.id).toEqual(ACTION_TYPE_ID);
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||||
|
* or more contributor license agreements. Licensed under the Elastic License;
|
||||||
|
* you may not use this file except in compliance with the Elastic License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { ActionsConfigurationUtilities } from '../actions_config';
|
||||||
|
import { ActionTypeRegistry } from '../action_type_registry';
|
||||||
|
import { encryptedSavedObjectsMock } from '../../../encrypted_saved_objects/server/plugin.mock';
|
||||||
|
import { taskManagerMock } from '../../../task_manager/task_manager.mock';
|
||||||
|
import { SavedObjectsClientMock } from '../../../../../../src/core/server/mocks';
|
||||||
|
import { registerBuiltInActionTypes } from './index';
|
||||||
|
|
||||||
|
const ACTION_TYPE_IDS = ['.index', '.email', '.pagerduty', '.server-log', '.slack', '.webhook'];
|
||||||
|
const NO_OP_FN = () => {};
|
||||||
|
const MOCK_KIBANA_CONFIG_UTILS: ActionsConfigurationUtilities = {
|
||||||
|
isWhitelistedHostname: _ => true,
|
||||||
|
isWhitelistedUri: _ => true,
|
||||||
|
ensureWhitelistedHostname: _ => {},
|
||||||
|
ensureWhitelistedUri: _ => {},
|
||||||
|
};
|
||||||
|
|
||||||
|
const services = {
|
||||||
|
log: NO_OP_FN,
|
||||||
|
callCluster: jest.fn(),
|
||||||
|
savedObjectsClient: SavedObjectsClientMock.create(),
|
||||||
|
};
|
||||||
|
|
||||||
|
function getServices() {
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
|
const mockEncryptedSavedObjectsPlugin = encryptedSavedObjectsMock.create();
|
||||||
|
|
||||||
|
export function createActionTypeRegistry(): ActionTypeRegistry {
|
||||||
|
const actionTypeRegistry = new ActionTypeRegistry({
|
||||||
|
getServices,
|
||||||
|
isSecurityEnabled: true,
|
||||||
|
taskManager: taskManagerMock.create(),
|
||||||
|
encryptedSavedObjectsPlugin: mockEncryptedSavedObjectsPlugin,
|
||||||
|
spaceIdToNamespace: jest.fn().mockReturnValue(undefined),
|
||||||
|
getBasePath: jest.fn().mockReturnValue(undefined),
|
||||||
|
});
|
||||||
|
registerBuiltInActionTypes(actionTypeRegistry, MOCK_KIBANA_CONFIG_UTILS);
|
||||||
|
return actionTypeRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.resetAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('action is registered', () => {
|
||||||
|
test('gets registered with builtin actions', () => {
|
||||||
|
const actionTypeRegistry = createActionTypeRegistry();
|
||||||
|
ACTION_TYPE_IDS.forEach(ACTION_TYPE_ID =>
|
||||||
|
expect(actionTypeRegistry.has(ACTION_TYPE_ID)).toEqual(true)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
|
@ -9,25 +9,15 @@ jest.mock('./lib/post_pagerduty', () => ({
|
||||||
}));
|
}));
|
||||||
|
|
||||||
import { ActionType, Services, ActionTypeExecutorOptions } from '../types';
|
import { ActionType, Services, ActionTypeExecutorOptions } from '../types';
|
||||||
import { ActionsConfigurationUtilities } from '../actions_config';
|
|
||||||
import { ActionTypeRegistry } from '../action_type_registry';
|
|
||||||
import { taskManagerMock } from '../../../task_manager/task_manager.mock';
|
|
||||||
import { encryptedSavedObjectsMock } from '../../../encrypted_saved_objects/server/plugin.mock';
|
|
||||||
import { validateConfig, validateSecrets, validateParams } from '../lib';
|
import { validateConfig, validateSecrets, validateParams } from '../lib';
|
||||||
import { SavedObjectsClientMock } from '../../../../../../src/core/server/mocks';
|
import { SavedObjectsClientMock } from '../../../../../../src/core/server/mocks';
|
||||||
import { postPagerduty } from './lib/post_pagerduty';
|
import { postPagerduty } from './lib/post_pagerduty';
|
||||||
import { registerBuiltInActionTypes } from './index';
|
import { createActionTypeRegistry } from './index.test';
|
||||||
|
|
||||||
const postPagerdutyMock = postPagerduty as jest.Mock;
|
const postPagerdutyMock = postPagerduty as jest.Mock;
|
||||||
|
|
||||||
const ACTION_TYPE_ID = '.pagerduty';
|
const ACTION_TYPE_ID = '.pagerduty';
|
||||||
const NO_OP_FN = () => {};
|
const NO_OP_FN = () => {};
|
||||||
const MOCK_KIBANA_CONFIG_UTILS: ActionsConfigurationUtilities = {
|
|
||||||
isWhitelistedHostname: _ => true,
|
|
||||||
isWhitelistedUri: _ => true,
|
|
||||||
ensureWhitelistedHostname: _ => {},
|
|
||||||
ensureWhitelistedUri: _ => {},
|
|
||||||
};
|
|
||||||
|
|
||||||
const services: Services = {
|
const services: Services = {
|
||||||
log: NO_OP_FN,
|
log: NO_OP_FN,
|
||||||
|
@ -35,25 +25,10 @@ const services: Services = {
|
||||||
savedObjectsClient: SavedObjectsClientMock.create(),
|
savedObjectsClient: SavedObjectsClientMock.create(),
|
||||||
};
|
};
|
||||||
|
|
||||||
function getServices(): Services {
|
|
||||||
return services;
|
|
||||||
}
|
|
||||||
|
|
||||||
let actionType: ActionType;
|
let actionType: ActionType;
|
||||||
let actionTypeRegistry: ActionTypeRegistry;
|
|
||||||
|
|
||||||
const mockEncryptedSavedObjectsPlugin = encryptedSavedObjectsMock.create();
|
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
actionTypeRegistry = new ActionTypeRegistry({
|
const actionTypeRegistry = createActionTypeRegistry();
|
||||||
getServices,
|
|
||||||
isSecurityEnabled: true,
|
|
||||||
taskManager: taskManagerMock.create(),
|
|
||||||
encryptedSavedObjectsPlugin: mockEncryptedSavedObjectsPlugin,
|
|
||||||
spaceIdToNamespace: jest.fn().mockReturnValue(undefined),
|
|
||||||
getBasePath: jest.fn().mockReturnValue(undefined),
|
|
||||||
});
|
|
||||||
registerBuiltInActionTypes(actionTypeRegistry, MOCK_KIBANA_CONFIG_UTILS);
|
|
||||||
actionType = actionTypeRegistry.get(ACTION_TYPE_ID);
|
actionType = actionTypeRegistry.get(ACTION_TYPE_ID);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -61,12 +36,6 @@ beforeEach(() => {
|
||||||
services.log = NO_OP_FN;
|
services.log = NO_OP_FN;
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('action registation', () => {
|
|
||||||
test('should be successful', () => {
|
|
||||||
expect(actionTypeRegistry.has(ACTION_TYPE_ID)).toEqual(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('get()', () => {
|
describe('get()', () => {
|
||||||
test('should return correct action type', () => {
|
test('should return correct action type', () => {
|
||||||
expect(actionType.id).toEqual(ACTION_TYPE_ID);
|
expect(actionType.id).toEqual(ACTION_TYPE_ID);
|
||||||
|
|
|
@ -5,23 +5,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ActionType, Services } from '../types';
|
import { ActionType, Services } from '../types';
|
||||||
import { ActionsConfigurationUtilities } from '../actions_config';
|
|
||||||
import { ActionTypeRegistry } from '../action_type_registry';
|
|
||||||
import { taskManagerMock } from '../../../task_manager/task_manager.mock';
|
|
||||||
import { encryptedSavedObjectsMock } from '../../../encrypted_saved_objects/server/plugin.mock';
|
|
||||||
import { validateParams } from '../lib';
|
import { validateParams } from '../lib';
|
||||||
import { SavedObjectsClientMock } from '../../../../../../src/core/server/mocks';
|
import { SavedObjectsClientMock } from '../../../../../../src/core/server/mocks';
|
||||||
|
import { createActionTypeRegistry } from './index.test';
|
||||||
import { registerBuiltInActionTypes } from './index';
|
|
||||||
|
|
||||||
const ACTION_TYPE_ID = '.server-log';
|
const ACTION_TYPE_ID = '.server-log';
|
||||||
const NO_OP_FN = () => {};
|
const NO_OP_FN = () => {};
|
||||||
const MOCK_KIBANA_CONFIG_UTILS: ActionsConfigurationUtilities = {
|
|
||||||
isWhitelistedHostname: _ => true,
|
|
||||||
isWhitelistedUri: _ => true,
|
|
||||||
ensureWhitelistedHostname: _ => {},
|
|
||||||
ensureWhitelistedUri: _ => {},
|
|
||||||
};
|
|
||||||
|
|
||||||
const services: Services = {
|
const services: Services = {
|
||||||
log: NO_OP_FN,
|
log: NO_OP_FN,
|
||||||
|
@ -29,52 +18,26 @@ const services: Services = {
|
||||||
savedObjectsClient: SavedObjectsClientMock.create(),
|
savedObjectsClient: SavedObjectsClientMock.create(),
|
||||||
};
|
};
|
||||||
|
|
||||||
function getServices(): Services {
|
let actionType: ActionType;
|
||||||
return services;
|
|
||||||
}
|
|
||||||
|
|
||||||
let actionTypeRegistry: ActionTypeRegistry;
|
|
||||||
|
|
||||||
const mockEncryptedSavedObjectsPlugin = encryptedSavedObjectsMock.create();
|
|
||||||
|
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
actionTypeRegistry = new ActionTypeRegistry({
|
const actionTypeRegistry = createActionTypeRegistry();
|
||||||
getServices,
|
actionType = actionTypeRegistry.get(ACTION_TYPE_ID);
|
||||||
isSecurityEnabled: true,
|
expect(actionType).toBeTruthy();
|
||||||
taskManager: taskManagerMock.create(),
|
|
||||||
encryptedSavedObjectsPlugin: mockEncryptedSavedObjectsPlugin,
|
|
||||||
spaceIdToNamespace: jest.fn().mockReturnValue(undefined),
|
|
||||||
getBasePath: jest.fn().mockReturnValue(undefined),
|
|
||||||
});
|
|
||||||
registerBuiltInActionTypes(actionTypeRegistry, MOCK_KIBANA_CONFIG_UTILS);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
services.log = NO_OP_FN;
|
services.log = NO_OP_FN;
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('action is registered', () => {
|
|
||||||
test('gets registered with builtin actions', () => {
|
|
||||||
expect(actionTypeRegistry.has(ACTION_TYPE_ID)).toEqual(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('get()', () => {
|
describe('get()', () => {
|
||||||
test('returns action type', () => {
|
test('returns action type', () => {
|
||||||
const actionType = actionTypeRegistry.get(ACTION_TYPE_ID);
|
|
||||||
expect(actionType.id).toEqual(ACTION_TYPE_ID);
|
expect(actionType.id).toEqual(ACTION_TYPE_ID);
|
||||||
expect(actionType.name).toEqual('server-log');
|
expect(actionType.name).toEqual('server-log');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('validateParams()', () => {
|
describe('validateParams()', () => {
|
||||||
let actionType: ActionType;
|
|
||||||
|
|
||||||
beforeAll(() => {
|
|
||||||
actionType = actionTypeRegistry.get(ACTION_TYPE_ID);
|
|
||||||
expect(actionType).toBeTruthy();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should validate and pass when params is valid', () => {
|
test('should validate and pass when params is valid', () => {
|
||||||
expect(validateParams(actionType, { message: 'a message' })).toEqual({
|
expect(validateParams(actionType, { message: 'a message' })).toEqual({
|
||||||
message: 'a message',
|
message: 'a message',
|
||||||
|
@ -123,7 +86,6 @@ describe('execute()', () => {
|
||||||
const mockLog = jest.fn().mockResolvedValueOnce({ success: true });
|
const mockLog = jest.fn().mockResolvedValueOnce({ success: true });
|
||||||
|
|
||||||
services.log = mockLog;
|
services.log = mockLog;
|
||||||
const actionType = actionTypeRegistry.get(ACTION_TYPE_ID);
|
|
||||||
const id = 'some-id';
|
const id = 'some-id';
|
||||||
await actionType.executor({
|
await actionType.executor({
|
||||||
id,
|
id,
|
||||||
|
|
|
@ -7,7 +7,10 @@
|
||||||
import { getActionType } from './webhook';
|
import { getActionType } from './webhook';
|
||||||
import { validateConfig, validateSecrets, validateParams } from '../lib';
|
import { validateConfig, validateSecrets, validateParams } from '../lib';
|
||||||
import { ActionsConfigurationUtilities } from '../actions_config';
|
import { ActionsConfigurationUtilities } from '../actions_config';
|
||||||
|
import { ActionType } from '../types';
|
||||||
|
import { createActionTypeRegistry } from './index.test';
|
||||||
|
|
||||||
|
const ACTION_TYPE_ID = '.webhook';
|
||||||
const configUtilsMock: ActionsConfigurationUtilities = {
|
const configUtilsMock: ActionsConfigurationUtilities = {
|
||||||
isWhitelistedHostname: _ => true,
|
isWhitelistedHostname: _ => true,
|
||||||
isWhitelistedUri: _ => true,
|
isWhitelistedUri: _ => true,
|
||||||
|
@ -15,9 +18,15 @@ const configUtilsMock: ActionsConfigurationUtilities = {
|
||||||
ensureWhitelistedUri: _ => {},
|
ensureWhitelistedUri: _ => {},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let actionType: ActionType;
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
const actionTypeRegistry = createActionTypeRegistry();
|
||||||
|
actionType = actionTypeRegistry.get(ACTION_TYPE_ID);
|
||||||
|
});
|
||||||
|
|
||||||
describe('actionType', () => {
|
describe('actionType', () => {
|
||||||
test('exposes the action as `webhook` on its Id and Name', () => {
|
test('exposes the action as `webhook` on its Id and Name', () => {
|
||||||
const actionType = getActionType(configUtilsMock);
|
|
||||||
expect(actionType.id).toEqual('.webhook');
|
expect(actionType.id).toEqual('.webhook');
|
||||||
expect(actionType.name).toEqual('webhook');
|
expect(actionType.name).toEqual('webhook');
|
||||||
});
|
});
|
||||||
|
@ -25,7 +34,6 @@ describe('actionType', () => {
|
||||||
|
|
||||||
describe('secrets validation', () => {
|
describe('secrets validation', () => {
|
||||||
test('succeeds when secrets is valid', () => {
|
test('succeeds when secrets is valid', () => {
|
||||||
const actionType = getActionType(configUtilsMock);
|
|
||||||
const secrets: Record<string, any> = {
|
const secrets: Record<string, any> = {
|
||||||
user: 'bob',
|
user: 'bob',
|
||||||
password: 'supersecret',
|
password: 'supersecret',
|
||||||
|
@ -35,7 +43,6 @@ describe('secrets validation', () => {
|
||||||
|
|
||||||
test('fails when secret password is omitted', () => {
|
test('fails when secret password is omitted', () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
const actionType = getActionType(configUtilsMock);
|
|
||||||
validateSecrets(actionType, { user: 'bob' });
|
validateSecrets(actionType, { user: 'bob' });
|
||||||
}).toThrowErrorMatchingInlineSnapshot(
|
}).toThrowErrorMatchingInlineSnapshot(
|
||||||
`"error validating action type secrets: [password]: expected value of type [string] but got [undefined]"`
|
`"error validating action type secrets: [password]: expected value of type [string] but got [undefined]"`
|
||||||
|
@ -44,7 +51,6 @@ describe('secrets validation', () => {
|
||||||
|
|
||||||
test('fails when secret user is omitted', () => {
|
test('fails when secret user is omitted', () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
const actionType = getActionType(configUtilsMock);
|
|
||||||
validateSecrets(actionType, {});
|
validateSecrets(actionType, {});
|
||||||
}).toThrowErrorMatchingInlineSnapshot(
|
}).toThrowErrorMatchingInlineSnapshot(
|
||||||
`"error validating action type secrets: [user]: expected value of type [string] but got [undefined]"`
|
`"error validating action type secrets: [user]: expected value of type [string] but got [undefined]"`
|
||||||
|
@ -59,7 +65,6 @@ describe('config validation', () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
test('config validation passes when only required fields are provided', () => {
|
test('config validation passes when only required fields are provided', () => {
|
||||||
const actionType = getActionType(configUtilsMock);
|
|
||||||
const config: Record<string, any> = {
|
const config: Record<string, any> = {
|
||||||
url: 'http://mylisteningserver:9200/endpoint',
|
url: 'http://mylisteningserver:9200/endpoint',
|
||||||
};
|
};
|
||||||
|
@ -70,7 +75,6 @@ describe('config validation', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('config validation passes when valid methods are provided', () => {
|
test('config validation passes when valid methods are provided', () => {
|
||||||
const actionType = getActionType(configUtilsMock);
|
|
||||||
['post', 'put'].forEach(method => {
|
['post', 'put'].forEach(method => {
|
||||||
const config: Record<string, any> = {
|
const config: Record<string, any> = {
|
||||||
url: 'http://mylisteningserver:9200/endpoint',
|
url: 'http://mylisteningserver:9200/endpoint',
|
||||||
|
@ -84,7 +88,6 @@ describe('config validation', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should validate and throw error when method on config is invalid', () => {
|
test('should validate and throw error when method on config is invalid', () => {
|
||||||
const actionType = getActionType(configUtilsMock);
|
|
||||||
const config: Record<string, any> = {
|
const config: Record<string, any> = {
|
||||||
url: 'http://mylisteningserver:9200/endpoint',
|
url: 'http://mylisteningserver:9200/endpoint',
|
||||||
method: 'https',
|
method: 'https',
|
||||||
|
@ -99,7 +102,6 @@ describe('config validation', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('config validation passes when a url is specified', () => {
|
test('config validation passes when a url is specified', () => {
|
||||||
const actionType = getActionType(configUtilsMock);
|
|
||||||
const config: Record<string, any> = {
|
const config: Record<string, any> = {
|
||||||
url: 'http://mylisteningserver:9200/endpoint',
|
url: 'http://mylisteningserver:9200/endpoint',
|
||||||
};
|
};
|
||||||
|
@ -110,7 +112,6 @@ describe('config validation', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('config validation passes when valid headers are provided', () => {
|
test('config validation passes when valid headers are provided', () => {
|
||||||
const actionType = getActionType(configUtilsMock);
|
|
||||||
const config: Record<string, any> = {
|
const config: Record<string, any> = {
|
||||||
url: 'http://mylisteningserver:9200/endpoint',
|
url: 'http://mylisteningserver:9200/endpoint',
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -124,7 +125,6 @@ describe('config validation', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should validate and throw error when headers on config is invalid', () => {
|
test('should validate and throw error when headers on config is invalid', () => {
|
||||||
const actionType = getActionType(configUtilsMock);
|
|
||||||
const config: Record<string, any> = {
|
const config: Record<string, any> = {
|
||||||
url: 'http://mylisteningserver:9200/endpoint',
|
url: 'http://mylisteningserver:9200/endpoint',
|
||||||
headers: 'application/json',
|
headers: 'application/json',
|
||||||
|
@ -139,8 +139,6 @@ describe('config validation', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('config validation passes when kibana config whitelists the url', () => {
|
test('config validation passes when kibana config whitelists the url', () => {
|
||||||
const actionType = getActionType(configUtilsMock);
|
|
||||||
|
|
||||||
const config: Record<string, any> = {
|
const config: Record<string, any> = {
|
||||||
url: 'http://mylisteningserver.com:9200/endpoint',
|
url: 'http://mylisteningserver.com:9200/endpoint',
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -155,7 +153,7 @@ describe('config validation', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('config validation returns an error if the specified URL isnt whitelisted', () => {
|
test('config validation returns an error if the specified URL isnt whitelisted', () => {
|
||||||
const actionType = getActionType({
|
actionType = getActionType({
|
||||||
...configUtilsMock,
|
...configUtilsMock,
|
||||||
ensureWhitelistedUri: _ => {
|
ensureWhitelistedUri: _ => {
|
||||||
throw new Error(`target url is not whitelisted`);
|
throw new Error(`target url is not whitelisted`);
|
||||||
|
@ -179,13 +177,11 @@ describe('config validation', () => {
|
||||||
|
|
||||||
describe('params validation', () => {
|
describe('params validation', () => {
|
||||||
test('param validation passes when no fields are provided as none are required', () => {
|
test('param validation passes when no fields are provided as none are required', () => {
|
||||||
const actionType = getActionType(configUtilsMock);
|
|
||||||
const params: Record<string, any> = {};
|
const params: Record<string, any> = {};
|
||||||
expect(validateParams(actionType, params)).toEqual({});
|
expect(validateParams(actionType, params)).toEqual({});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('params validation passes when a valid body is provided', () => {
|
test('params validation passes when a valid body is provided', () => {
|
||||||
const actionType = getActionType(configUtilsMock);
|
|
||||||
const params: Record<string, any> = {
|
const params: Record<string, any> = {
|
||||||
body: 'count: {{ctx.payload.hits.total}}',
|
body: 'count: {{ctx.payload.hits.total}}',
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue