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 1
1
import request from 'supertest-as-promised' ;
2
2
import httpStatus from 'http-status' ;
3
+ import jwt from 'jsonwebtoken' ;
3
4
import chai , { expect } from 'chai' ;
4
5
import app from '../../index' ;
5
6
7
+ const config = require ( '../../config/env' ) ;
8
+ const should = require ( 'chai' ) . should ( ) ;
9
+
6
10
chai . config . includeStack = true ;
7
11
8
12
describe ( '## AUTH APIs' , ( ) => {
@@ -12,16 +16,20 @@ describe('## AUTH APIs', () => {
12
16
} ;
13
17
let jwtToken ;
14
18
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 ) => {
17
21
request ( app )
18
22
. post ( '/api/auth/login' )
19
23
. send ( user )
20
24
. expect ( httpStatus . OK )
21
25
. 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
+ } ) ;
25
33
} )
26
34
. catch ( done ) ;
27
35
} ) ;
You can’t perform that action at this time.
0 commit comments