My serverless lambda application has custom authorizer
verify-token:
handler: app/Middleware/VerifyToken.auth
user:
handler: app/Handlers/Users.user
events:
- http:
path: user
method: get
cors: true
authorizer: verify-token
I am writing jest unit test for the user handler, but since when deployed the custom authorization is run before the user handler is executed, How do I apply the same in jest unit test so that I can apply the authorization before running the user handler test?
This is my test
const { user } = require('../../app/Handlers/Users');
/**
* Tests for get()
*/
describe('Get user', () => {
it('Get user data', async done => {
let userEvent = {
headers: {
'authorization': 'Bearer TOKEN'
}
}
// user.authorizer();
user(userEvent, null, (error, data) => {
try {
expect(data.statusCode).toBe(200);
done();
} catch (error) {
done(error);
}
});
});
});