File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change 11import request from 'supertest-as-promised' ;
22import httpStatus from 'http-status' ;
3+ import jwt from 'jsonwebtoken' ;
34import chai , { expect } from 'chai' ;
45import app from '../../index' ;
56
7+ const config = require ( '../../config/env' ) ;
8+ const should = require ( 'chai' ) . should ( ) ;
9+
610chai . config . includeStack = true ;
711
812describe ( '## AUTH APIs' , ( ) => {
@@ -12,16 +16,20 @@ describe('## AUTH APIs', () => {
1216 } ;
1317 let jwtToken ;
1418
15- describe ( '# GET /api/auth/login (login to get JWT token) ' , ( ) => {
16- it ( 'should get JWT token' , ( done ) => {
19+ describe ( '# GET /api/auth/login' , ( ) => {
20+ it ( 'should get (valid) JWT token' , ( done ) => {
1721 request ( app )
1822 . post ( '/api/auth/login' )
1923 . send ( user )
2024 . expect ( httpStatus . OK )
2125 . then ( ( res ) => {
22- expect ( res . body . username ) . to . equal ( user . username ) ;
23- jwtToken = `Bearer ${ res . body . token } ` ;
24- done ( ) ;
26+ should . exist ( res . body . token ) ;
27+ jwt . verify ( res . body . token , config . jwtSecret , ( err , decoded ) => {
28+ should . not . exist ( err ) ;
29+ expect ( decoded . username ) . to . equal ( user . username ) ;
30+ jwtToken = `Bearer ${ res . body . token } ` ;
31+ done ( ) ;
32+ } ) ;
2533 } )
2634 . catch ( done ) ;
2735 } ) ;
You can’t perform that action at this time.
0 commit comments