Skip to content

Commit

Permalink
test:fix
Browse files Browse the repository at this point in the history
  • Loading branch information
XVincentX committed Jul 11, 2019
1 parent a071b25 commit 7419c0d
Showing 1 changed file with 36 additions and 11 deletions.
47 changes: 36 additions & 11 deletions packages/http/src/validator/__tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,55 @@ describe('HttpValidator', () => {
input: { method: 'get', url: { path: '/' } },
config: { mock: { dynamic: false }, validate: { request: { body: true } } },
}),
).toEqual([mockError]);
).toEqual([]);

expect(resolveValidationConfigModule.resolveRequestValidationConfig).toHaveBeenCalled();
expect(httpBodyValidator.validate).toHaveBeenCalledWith(undefined, [], undefined);
expect(httpBodyValidator.validate).not.toHaveBeenCalled();
expect(httpHeadersValidator.validate).not.toHaveBeenCalled();
expect(httpQueryValidator.validate).not.toHaveBeenCalled();
};

describe('request is not set', () => {
it('validates body', test());
it('does not try to validate the body', test());
});

describe('request is set', () => {
describe('request.body is not set', () => {
it('validates body', test({ request: { path: [], headers: [], query: [], cookie: [] } }));
it('does not try to validate the body', test({ request: { path: [], headers: [], query: [], cookie: [] } }));
});

describe('request.body is set', () => {
it(
'validates body',
test({
request: { body: { contents: [] }, path: [], query: [], headers: [], cookie: [] },
}),
);
describe('request body is not required', () => {
it(
'does not try to validate the body',
test({
request: { body: { contents: [] }, path: [], query: [], headers: [], cookie: [] },
}),
);
});

describe('request body is required', () => {
it('tries to validate the body', () => {
expect(
httpValidator.validateInput({
resource: Object.assign({
method: 'get',
path: '/',
id: '1',
request: {},
responses: [{ code: '200' }],
}),
input: { method: 'get', url: { path: '/' } },
config: { mock: { dynamic: false }, validate: { request: { body: true } } },
}),
).toEqual([mockError]);

expect(resolveValidationConfigModule.resolveRequestValidationConfig).toHaveBeenCalled();
expect(httpBodyValidator.validate).toHaveBeenCalled();
expect(httpHeadersValidator.validate).not.toHaveBeenCalled();
expect(httpQueryValidator.validate).not.toHaveBeenCalled();
});
});
});
});
});
Expand Down Expand Up @@ -196,7 +221,7 @@ describe('HttpValidator', () => {

describe('output is set', () => {
describe('body validation is enabled', () => {
it('validates body', async () => {
it('validates the body', async () => {
jest
.spyOn(resolveValidationConfigModule, 'resolveResponseValidationConfig')
.mockReturnValueOnce({ headers: false, body: true });
Expand Down

0 comments on commit 7419c0d

Please sign in to comment.