Skip to content

Commit

Permalink
fix(types): fix typecasting
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandryackovlev committed Aug 10, 2020
1 parent d452812 commit e1c51c9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
28 changes: 14 additions & 14 deletions src/middleware/isAuthenticated.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,21 @@ describe('isAuthenticated', () => {
name: 'authKey',
} as OpenAPIV3.SecuritySchemeObject;

expect(
checkAuthByType(securityScheme, {
query: {
authKey: 'test',
},
} as express.Request)
).toBe(false);
const query: unknown = {
query: {
authKey: 'test',
},
};

expect(
checkAuthByType(securityScheme, {
query: {
someOtherKey: 'test',
},
} as express.Request)
).toBe(true);
expect(checkAuthByType(securityScheme, query as express.Request)).toBe(false);

const wrongQuery: unknown = {
query: {
someOtherKey: 'test',
},
};

expect(checkAuthByType(securityScheme, wrongQuery as express.Request)).toBe(true);
});

it('should check auth for the apiKey security type in cookies', () => {
Expand Down
4 changes: 3 additions & 1 deletion src/middleware/validateBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ const validateBody = (
return next();
}

const bodySchema = res.locals.operation.getBodySchema(req.get('content-type'));
const bodySchema = res.locals.operation.getBodySchema(
req.get('content-type') || 'application/json'
);

if (Object.keys(req.body).length && !bodySchema) {
return res.status(400).json({
Expand Down

0 comments on commit e1c51c9

Please sign in to comment.