jsonwebtoken#SignCallback TypeScript Examples
The following examples show how to use
jsonwebtoken#SignCallback.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: user_failure.ts From api-example with MIT License | 6 votes |
describe('login', () => {
it('should return internal_server_error if jwt.sign fails with the error', async () => {
const sign = jwt.sign;
(jwt.sign as any) = (payload: string | Buffer | object,
secretOrPrivateKey: Secret,
options: SignOptions,
callback: SignCallback) => {
callback(new Error('failure'), undefined)
}
const dummy = await createDummy()
await expect(user.login(dummy.email, dummy.password)).rejects.toEqual({
error: {type: 'internal_server_error', message: 'Internal Server Error'}
})
jwt.sign = sign
})
it('should return JWT token, userId, expireAt to a valid login/password if cacheExternal rejects', async () => {
(cacheExternal.setProp as jest.Mock).mockRejectedValueOnce(new Error('connection error'));
const dummy = await createDummy()
await expect(user.login(dummy.email, dummy.password)).resolves.toEqual({
userId: dummy.userId,
token: expect.stringMatching(/^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$/),
expireAt: expect.any(Date)
})
})
})