Created
October 2, 2020 04:59
-
-
Save ANUPAMCHAUDHARY1117/b47dd23077b9cdd6557baf50df3bb798 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const app = require('../app'); | |
const jwt = require('jsonwebtoken'); | |
const request = require('supertest'); | |
const testApi = () => { | |
it('It should verify the access token and respond with status 200', async () => { | |
const jwtSpy = jest.spyOn(jwt, 'verify'); | |
jwtSpy.mockReturnValue('Some decoded token'); | |
const res = await request(app) | |
.get('/verify-access-token') | |
.set('access-token', 'somerandomjwttoken') | |
.send({}); | |
expect(res.status).toEqual(200); | |
}); | |
it('It should not verify the access token and respond with status 401', async () => { | |
const jwtSpy = jest.spyOn(jwt, 'verify'); | |
jwtSpy.mockImplementationOnce(() => { throw new Error('Invalid access token') }); | |
const res = await request(app) | |
.get('/verify-access-token') | |
.set('access-token', 'somerandomjwttoken') | |
.send({}); | |
expect(res.status).toEqual(401); | |
}); | |
}; | |
module.exports = testApi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment