mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
parent
d57b5df77a
commit
40f13218aa
4 changed files with 13 additions and 13 deletions
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
import { validateSingleAction, validateRuleActionsField } from './schema';
|
||||
import { isUuidv4, getActionTypeName, validateMustache, validateActionParams } from './utils';
|
||||
import { isUuid, getActionTypeName, validateMustache, validateActionParams } from './utils';
|
||||
import { actionTypeRegistryMock } from '../../../../../../triggers_actions_ui/public/application/action_type_registry.mock';
|
||||
import { FormHook } from '../../../../shared_imports';
|
||||
jest.mock('./utils');
|
||||
|
@ -15,7 +15,7 @@ describe('stepRuleActions schema', () => {
|
|||
|
||||
describe('validateSingleAction', () => {
|
||||
it('should validate single action', () => {
|
||||
(isUuidv4 as jest.Mock).mockReturnValue(true);
|
||||
(isUuid as jest.Mock).mockReturnValue(true);
|
||||
(validateActionParams as jest.Mock).mockReturnValue([]);
|
||||
(validateMustache as jest.Mock).mockReturnValue([]);
|
||||
|
||||
|
@ -33,7 +33,7 @@ describe('stepRuleActions schema', () => {
|
|||
});
|
||||
|
||||
it('should validate single action with invalid mustache template', () => {
|
||||
(isUuidv4 as jest.Mock).mockReturnValue(true);
|
||||
(isUuid as jest.Mock).mockReturnValue(true);
|
||||
(validateActionParams as jest.Mock).mockReturnValue([]);
|
||||
(validateMustache as jest.Mock).mockReturnValue(['Message is not valid mustache template']);
|
||||
|
||||
|
@ -54,7 +54,7 @@ describe('stepRuleActions schema', () => {
|
|||
});
|
||||
|
||||
it('should validate single action with incorrect id', () => {
|
||||
(isUuidv4 as jest.Mock).mockReturnValue(false);
|
||||
(isUuid as jest.Mock).mockReturnValue(false);
|
||||
(validateMustache as jest.Mock).mockReturnValue([]);
|
||||
(validateActionParams as jest.Mock).mockReturnValue([]);
|
||||
|
||||
|
@ -117,9 +117,9 @@ describe('stepRuleActions schema', () => {
|
|||
});
|
||||
|
||||
it('should validate multiple incorrect rule actions field', () => {
|
||||
(isUuidv4 as jest.Mock).mockReturnValueOnce(false);
|
||||
(isUuid as jest.Mock).mockReturnValueOnce(false);
|
||||
(getActionTypeName as jest.Mock).mockReturnValueOnce('Slack');
|
||||
(isUuidv4 as jest.Mock).mockReturnValueOnce(true);
|
||||
(isUuid as jest.Mock).mockReturnValueOnce(true);
|
||||
(getActionTypeName as jest.Mock).mockReturnValueOnce('Pagerduty');
|
||||
(validateActionParams as jest.Mock).mockReturnValue(['Summary is required']);
|
||||
(validateMustache as jest.Mock).mockReturnValue(['Component is not valid mustache template']);
|
||||
|
|
|
@ -15,13 +15,13 @@ import {
|
|||
import { FormSchema, ValidationFunc, ERROR_CODE } from '../../../../shared_imports';
|
||||
import { ActionsStepRule } from '../../../pages/detection_engine/rules/types';
|
||||
import * as I18n from './translations';
|
||||
import { isUuidv4, getActionTypeName, validateMustache, validateActionParams } from './utils';
|
||||
import { isUuid, getActionTypeName, validateMustache, validateActionParams } from './utils';
|
||||
|
||||
export const validateSingleAction = (
|
||||
actionItem: AlertAction,
|
||||
actionTypeRegistry: ActionTypeRegistryContract
|
||||
): string[] => {
|
||||
if (!isUuidv4(actionItem.id)) {
|
||||
if (!isUuid(actionItem.id)) {
|
||||
return [I18n.NO_CONNECTOR_SELECTED];
|
||||
}
|
||||
|
||||
|
|
|
@ -5,16 +5,16 @@
|
|||
*/
|
||||
|
||||
import { actionTypeRegistryMock } from '../../../../../../triggers_actions_ui/public/application/action_type_registry.mock';
|
||||
import { isUuidv4, getActionTypeName, validateMustache, validateActionParams } from './utils';
|
||||
import { isUuid, getActionTypeName, validateMustache, validateActionParams } from './utils';
|
||||
|
||||
describe('stepRuleActions utils', () => {
|
||||
describe('isUuidv4', () => {
|
||||
it('should validate proper uuid v4 value', () => {
|
||||
expect(isUuidv4('817b8bca-91d1-4729-8ee1-3a83aaafd9d4')).toEqual(true);
|
||||
expect(isUuid('817b8bca-91d1-4729-8ee1-3a83aaafd9d4')).toEqual(true);
|
||||
});
|
||||
|
||||
it('should validate incorrect uuid v4 value', () => {
|
||||
expect(isUuidv4('ad9d4')).toEqual(false);
|
||||
expect(isUuid('ad9d4')).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -13,9 +13,9 @@ import {
|
|||
} from '../../../../../../triggers_actions_ui/public';
|
||||
import * as I18n from './translations';
|
||||
|
||||
const UUID_V4_REGEX = /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i;
|
||||
const UUID_REGEX = /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i;
|
||||
|
||||
export const isUuidv4 = (id: AlertAction['id']) => !!id.match(UUID_V4_REGEX);
|
||||
export const isUuid = (id: AlertAction['id']) => !!id.match(UUID_REGEX);
|
||||
|
||||
export const getActionTypeName = (actionTypeId: AlertAction['actionTypeId']) => {
|
||||
if (!actionTypeId) return '';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue