@@ -10,18 +10,23 @@ const expect = chai.expect // the assertion library in the style using the word
10
10
const should = chai . should ( ) // the same assertion library in the style using the word 'should'
11
11
12
12
// import the server
13
- const server = require ( '../app ' )
13
+ const server = require ( '../server ' )
14
14
15
15
// a group of tests related to the /protected route
16
16
describe ( 'Protected' , ( ) => {
17
+ // clean up by destroying the server when done
18
+ after ( ( ) => {
19
+ server . close ( )
20
+ } )
21
+
17
22
/**
18
23
* test the GET /protected route
19
24
*/
20
25
describe ( 'GET /protected when not logged in' , ( ) => {
21
26
// test a protected route when not logged in... passport auth should send back a 401 HTTP error
22
27
it ( 'it should return a 401 HTTP response code' , done => {
23
28
chai
24
- . request ( server )
29
+ . request ( server . app )
25
30
. get ( '/protected' )
26
31
. end ( ( err , res ) => {
27
32
res . should . have . status ( 401 ) // use 'should' to make BDD-style assertions
@@ -65,7 +70,7 @@ describe('Protected', () => {
65
70
it ( 'it should return a 200 HTTP response code' , done => {
66
71
console . log ( `DEBUG: running test` )
67
72
chai
68
- . request ( server )
73
+ . request ( server . app )
69
74
. get ( '/protected' )
70
75
. set ( 'Authorization' , `JWT ${ token } ` ) // set JWT authentication headers to simulate a logged-in user, using the token we created at top
71
76
. end ( ( err , res ) => {
@@ -76,7 +81,7 @@ describe('Protected', () => {
76
81
77
82
it ( 'it should return an object with specific properties' , done => {
78
83
chai
79
- . request ( server )
84
+ . request ( server . app )
80
85
. get ( '/protected' )
81
86
. set ( 'Authorization' , `JWT ${ token } ` ) // set JWT authentication headers to simulate a logged-in user, using the token we created at top
82
87
. end ( ( err , res ) => {
0 commit comments