@@ -161,6 +161,7 @@ describe('.middleware {MIDDLEWARE}', function() {
161
161
jsonp : false ,
162
162
redisClient : false ,
163
163
statusCodes : { include : [ ] , exclude : [ ] } ,
164
+ events : { expire : undefined } ,
164
165
headers : { }
165
166
} )
166
167
expect ( middleware2 . options ( ) ) . to . eql ( {
@@ -171,6 +172,7 @@ describe('.middleware {MIDDLEWARE}', function() {
171
172
jsonp : false ,
172
173
redisClient : false ,
173
174
statusCodes : { include : [ ] , exclude : [ ] } ,
175
+ events : { expire : undefined } ,
174
176
headers : { }
175
177
} )
176
178
} )
@@ -184,6 +186,7 @@ describe('.middleware {MIDDLEWARE}', function() {
184
186
defaultDuration : 7200000 ,
185
187
appendKey : [ 'bar' ] ,
186
188
statusCodes : { include : [ ] , exclude : [ '400' ] } ,
189
+ events : { expire : undefined } ,
187
190
headers : {
188
191
'cache-control' : 'no-cache'
189
192
}
@@ -192,7 +195,8 @@ describe('.middleware {MIDDLEWARE}', function() {
192
195
debug : false ,
193
196
defaultDuration : 1800000 ,
194
197
appendKey : [ 'foo' ] ,
195
- statusCodes : { include : [ ] , exclude : [ '200' ] }
198
+ statusCodes : { include : [ ] , exclude : [ '200' ] } ,
199
+ events : { expire : undefined } ,
196
200
} )
197
201
expect ( middleware1 . options ( ) ) . to . eql ( {
198
202
debug : true ,
@@ -202,6 +206,7 @@ describe('.middleware {MIDDLEWARE}', function() {
202
206
jsonp : false ,
203
207
redisClient : false ,
204
208
statusCodes : { include : [ ] , exclude : [ '400' ] } ,
209
+ events : { expire : undefined } ,
205
210
headers : {
206
211
'cache-control' : 'no-cache'
207
212
}
@@ -214,6 +219,7 @@ describe('.middleware {MIDDLEWARE}', function() {
214
219
jsonp : false ,
215
220
redisClient : false ,
216
221
statusCodes : { include : [ ] , exclude : [ '200' ] } ,
222
+ events : { expire : undefined } ,
217
223
headers : { }
218
224
} )
219
225
} )
@@ -243,6 +249,7 @@ describe('.middleware {MIDDLEWARE}', function() {
243
249
jsonp : false ,
244
250
redisClient : false ,
245
251
statusCodes : { include : [ ] , exclude : [ '400' ] } ,
252
+ events : { expire : undefined } ,
246
253
headers : { }
247
254
} )
248
255
expect ( middleware2 . options ( ) ) . to . eql ( {
@@ -253,6 +260,7 @@ describe('.middleware {MIDDLEWARE}', function() {
253
260
jsonp : false ,
254
261
redisClient : false ,
255
262
statusCodes : { include : [ ] , exclude : [ '200' ] } ,
263
+ events : { expire : undefined } ,
256
264
headers : { }
257
265
} )
258
266
} )
@@ -291,6 +299,7 @@ describe('.middleware {MIDDLEWARE}', function() {
291
299
jsonp : false ,
292
300
redisClient : false ,
293
301
statusCodes : { include : [ ] , exclude : [ ] } ,
302
+ events : { expire : undefined } ,
294
303
headers : {
295
304
'cache-control' : 'no-cache'
296
305
}
@@ -303,6 +312,7 @@ describe('.middleware {MIDDLEWARE}', function() {
303
312
jsonp : false ,
304
313
redisClient : false ,
305
314
statusCodes : { include : [ ] , exclude : [ ] } ,
315
+ events : { expire : undefined } ,
306
316
headers : { }
307
317
} )
308
318
} )
@@ -392,22 +402,15 @@ describe('.middleware {MIDDLEWARE}', function() {
392
402
} )
393
403
394
404
it ( 'properly uses appendKey params' , function ( ) {
395
- var app = mockAPI . create ( '10 seconds' , { appendKey : [ 'method' , 'url' ] } )
405
+ var app = mockAPI . create ( '10 seconds' , { appendKey : [ 'method' ] } )
396
406
397
407
return request ( app )
398
408
. get ( '/api/movies' )
399
409
. expect ( 200 , movies )
400
410
. then ( assertNumRequestsProcessed ( app , 1 ) )
401
411
. then ( function ( ) {
402
- return request ( app )
403
- . get ( '/api/movies' )
404
- . set ( 'Accept' , 'application/json' )
405
- . expect ( 'Content-Type' , / j s o n / )
406
- . expect ( 200 , movies )
407
- . then ( function ( res ) {
408
- expect ( app . apicache . getIndex ( ) . all . length ) . to . equal ( 1 )
409
- expect ( app . apicache . getIndex ( ) . all [ 0 ] ) . to . equal ( '/api/movies$$appendKey=GET+/api/movies' )
410
- } )
412
+ expect ( app . apicache . getIndex ( ) . all . length ) . to . equal ( 1 )
413
+ expect ( app . apicache . getIndex ( ) . all [ 0 ] ) . to . equal ( '/api/movies$$appendKey=GET' )
411
414
} )
412
415
} )
413
416
@@ -583,6 +586,26 @@ describe('.middleware {MIDDLEWARE}', function() {
583
586
} , 25 )
584
587
} )
585
588
589
+ it ( 'executes expiration callback from globalOptions.events.expire upon entry expiration' , function ( done ) {
590
+ var callbackResponse = undefined
591
+ var cb = function ( a , b ) {
592
+ callbackResponse = b
593
+ }
594
+ var app = mockAPI . create ( 10 , { events : { expire : cb } } )
595
+
596
+ request ( app )
597
+ . get ( '/api/movies' )
598
+ . end ( function ( err , res ) {
599
+ expect ( app . apicache . getIndex ( ) . all . length ) . to . equal ( 1 )
600
+ expect ( app . apicache . getIndex ( ) . all ) . to . include ( '/api/movies' )
601
+ } )
602
+
603
+ setTimeout ( function ( ) {
604
+ expect ( app . apicache . getIndex ( ) . all ) . to . have . length ( 0 )
605
+ expect ( callbackResponse ) . to . equal ( '/api/movies' )
606
+ done ( )
607
+ } , 25 )
608
+ } )
586
609
} )
587
610
} )
588
611
} )
0 commit comments