@@ -13,6 +13,7 @@ const loginDetails = {
13
13
14
14
password : '12345'
15
15
}
16
+ let token = ''
16
17
const createdID = [ ]
17
18
let verification = ''
18
19
let verificationForgot = ''
@@ -40,6 +41,7 @@ describe('*********** AUTH ***********', () => {
40
41
. get ( '/404url' )
41
42
. end ( ( err , res ) => {
42
43
res . should . have . status ( 404 )
44
+ res . body . should . be . an ( 'object' )
43
45
done ( )
44
46
} )
45
47
} )
@@ -53,7 +55,9 @@ describe('*********** AUTH ***********', () => {
53
55
. send ( loginDetails )
54
56
. end ( ( err , res ) => {
55
57
res . should . have . status ( 200 )
58
+ res . body . should . be . an ( 'object' )
56
59
res . body . should . have . property ( 'token' )
60
+ token = res . body . token
57
61
done ( )
58
62
} )
59
63
} )
@@ -72,6 +76,7 @@ describe('*********** AUTH ***********', () => {
72
76
. send ( user )
73
77
. end ( ( err , res ) => {
74
78
res . should . have . status ( 201 )
79
+ res . body . should . be . an ( 'object' )
75
80
res . body . should . include . keys ( 'token' , 'user' )
76
81
createdID . push ( res . body . user . _id )
77
82
verification = res . body . user . verification
@@ -107,15 +112,16 @@ describe('*********** AUTH ***********', () => {
107
112
} )
108
113
. end ( ( err , res ) => {
109
114
res . should . have . status ( 200 )
115
+ res . body . should . be . an ( 'object' )
110
116
res . body . should . include . keys ( 'email' , 'verified' )
111
117
res . body . verified . should . equal ( true )
112
118
done ( )
113
119
} )
114
120
} )
115
121
} )
116
122
117
- describe ( '/POST forgotPassword ' , ( ) => {
118
- it ( 'it should POST forgotPassword ' , done => {
123
+ describe ( '/POST forgot ' , ( ) => {
124
+ it ( 'it should POST forgot ' , done => {
119
125
chai
120
126
. request ( server )
121
127
. post ( '/forgot' )
@@ -124,15 +130,16 @@ describe('*********** AUTH ***********', () => {
124
130
} )
125
131
. end ( ( err , res ) => {
126
132
res . should . have . status ( 200 )
133
+ res . body . should . be . an ( 'object' )
127
134
res . body . should . include . keys ( 'msg' , 'verification' )
128
135
verificationForgot = res . body . verification
129
136
done ( )
130
137
} )
131
138
} )
132
139
} )
133
140
134
- describe ( '/POST resetPassword ' , ( ) => {
135
- it ( 'it should POST resetPassword ' , done => {
141
+ describe ( '/POST reset ' , ( ) => {
142
+ it ( 'it should POST reset ' , done => {
136
143
chai
137
144
. request ( server )
138
145
. post ( '/reset' )
@@ -149,6 +156,33 @@ describe('*********** AUTH ***********', () => {
149
156
} )
150
157
} )
151
158
159
+ describe ( '/POST token' , ( ) => {
160
+ it ( 'it should NOT be able to consume the route since no token was sent' , done => {
161
+ chai
162
+ . request ( server )
163
+ . post ( '/token' )
164
+ . end ( ( err , res ) => {
165
+ res . should . have . status ( 401 )
166
+ done ( )
167
+ } )
168
+ } )
169
+ it ( 'it should GET a fresh token' , done => {
170
+ chai
171
+ . request ( server )
172
+ . post ( '/token' )
173
+ . set ( 'Authorization' , `Bearer ${ token } ` )
174
+ . send ( {
175
+ token
176
+ } )
177
+ . end ( ( err , res ) => {
178
+ res . should . have . status ( 200 )
179
+ res . body . should . be . an ( 'object' )
180
+ res . body . should . have . property ( 'token' )
181
+ done ( )
182
+ } )
183
+ } )
184
+ } )
185
+
152
186
after ( ( ) => {
153
187
createdID . forEach ( id => {
154
188
User . findByIdAndRemove ( id , err => {
0 commit comments