Skip to content

Commit

Permalink
Fixing pagerduty timestamp validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ymao1 committed Nov 12, 2020
1 parent 51567dc commit c144d02
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,40 @@ 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 null', () => {
expect(validateParams(actionType, {})).toEqual({});

const params = {
eventAction: 'trigger',
dedupKey: 'a dedupKey',
summary: 'a summary',
source: 'a source',
severity: 'critical',
timestamp: null,
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 @@ -86,7 +86,7 @@ const ParamsSchema = schema.object(

function validateParams(paramsObject: unknown): string | void {
const { timestamp, eventAction, dedupKey } = paramsObject as ActionParamsType;
if (timestamp != null) {
if (timestamp != null && timestamp.length > 0) {
try {
const date = Date.parse(timestamp);
if (isNaN(date)) {
Expand Down

0 comments on commit c144d02

Please sign in to comment.