Skip to content

Commit

Permalink
test(validators): add server request validator negative test
Browse files Browse the repository at this point in the history
  • Loading branch information
duddu committed Jun 20, 2024
1 parent fe45aa0 commit 61d710b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
HSBXCallbackUrlRequiredSearchParamsKeys,
HSBXCallbackUrlSearchParams,
} from '../src/server/params';
import { createRequestValidators } from '../src/server/validators';
import { HSBShortcutStatus } from '../src/shortcut';
import { HSBUtils } from '../src/utils';

Expand Down Expand Up @@ -524,3 +525,25 @@ describe(HSBXCallbackUrlServerCommand.name, () => {
});
});
});

describe('Validators', () => {
describe(createRequestValidators.name, () => {
test('validator test should return false if condition function throws', () => {
const validatorMock = {
condition: () => {
throw new Error();
},
errorCode: 418,
errorMessage: 'errorMessageMock',
};
const validatorsMock = createRequestValidators({
hasValidMethod: validatorMock,
hasValidPathname: validatorMock,
hasValidSearchParams: validatorMock,
hasValidAuthToken: validatorMock,
});

expect(validatorsMock.map((validator) => validator.test())).toEqual(new Array(4).fill(false));
});
});
});

0 comments on commit 61d710b

Please sign in to comment.