Skip to content

Commit

Permalink
Reverting unnecessary changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ymao1 committed Nov 16, 2020
1 parent d8d16eb commit a0c8be0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,40 +140,6 @@ describe('validateParams()', () => {
expect(validateParams(actionType, params)).toEqual(params);
});

test('should validate and pass when params is valid and optional timestamp is empty string', () => {
expect(validateParams(actionType, {})).toEqual({});

const params = {
eventAction: 'trigger',
dedupKey: 'a dedupKey',
summary: 'a summary',
source: 'a source',
severity: 'critical',
timestamp: '',
component: 'a component',
group: 'a group',
class: 'a class',
};
expect(validateParams(actionType, params)).toEqual(params);
});

test('should validate and pass when params is valid and optional timestamp is undefined', () => {
expect(validateParams(actionType, {})).toEqual({});

const params = {
eventAction: 'trigger',
dedupKey: 'a dedupKey',
summary: 'a summary',
source: 'a source',
severity: 'critical',
timestamp: undefined,
component: 'a component',
group: 'a group',
class: 'a class',
};
expect(validateParams(actionType, params)).toEqual(params);
});

test('should validate and throw error when params is invalid', () => {
expect(() => {
validateParams(actionType, { eventAction: 'ackynollage' });
Expand Down
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 { curry, isUndefined, isEmpty, pick, omitBy } from 'lodash';
import { curry, isUndefined, pick, omitBy } from 'lodash';
import { i18n } from '@kbn/i18n';
import { schema, TypeOf } from '@kbn/config-schema';
import { postPagerduty } from './lib/post_pagerduty';
Expand Down Expand Up @@ -86,7 +86,7 @@ const ParamsSchema = schema.object(

function validateParams(paramsObject: unknown): string | void {
const { timestamp, eventAction, dedupKey } = paramsObject as ActionParamsType;
if (timestamp != null && timestamp.length > 0) {
if (timestamp != null) {
try {
const date = Date.parse(timestamp);
if (isNaN(date)) {
Expand Down Expand Up @@ -275,7 +275,7 @@ function getBodyForEventAction(actionId: string, params: ActionParamsType): Page
summary: params.summary || 'No summary provided.',
source: params.source || `Kibana Action ${actionId}`,
severity: params.severity || 'info',
...omitBy(pick(params, ['timestamp', 'component', 'group', 'class']), isUndefined || isEmpty),
...omitBy(pick(params, ['timestamp', 'component', 'group', 'class']), isUndefined),
};

return data;
Expand Down

0 comments on commit a0c8be0

Please sign in to comment.