@@ -14,6 +14,10 @@ describe('redis-dataloader', () => {
1414 key , ( err , resp ) => err ? reject ( err ) : resolve ( resp )
1515 ) ) ;
1616
17+ this . rSet = ( k , v ) => Q . Promise ( ( resolve , reject ) => redis . set (
18+ k , v , ( err , resp ) => err ? reject ( err ) : resolve ( resp )
19+ ) ) ;
20+
1721 this . keySpace = 'key-space' ;
1822 this . data = {
1923 json : { foo : 'bar' } ,
@@ -253,4 +257,40 @@ describe('redis-dataloader', () => {
253257 } ) . done ( ) ;
254258 } ) ;
255259 } ) ;
260+
261+ describe ( 'clearAllLocal' , ( ) => {
262+ it ( 'should clear all local in-memory cache' , done => {
263+ this . loader . loadMany ( [ 'json' , 'null' ] )
264+ . then ( ( ) => this . loader . clearAllLocal ( ) )
265+ . then ( ( ) => this . rSet (
266+ `${ this . keySpace } :json` , JSON . stringify ( { new : 'valeo' } )
267+ ) )
268+ . then ( ( ) => this . rSet (
269+ `${ this . keySpace } :null` , JSON . stringify ( { foo : 'bar' } )
270+ ) )
271+ . then ( ( ) => this . loader . loadMany ( [ 'null' , 'json' ] ) )
272+ . then ( data => {
273+ expect ( data ) . to . deep . equal ( [ { foo : 'bar' } , { new : 'valeo' } ] ) ;
274+ done ( ) ;
275+ } ) . done ( ) ;
276+ } ) ;
277+ } ) ;
278+
279+ describe ( 'clearLocal' , ( ) => {
280+ it ( 'should clear local cache for a specific key' , done => {
281+ this . loader . loadMany ( [ 'json' , 'null' ] )
282+ . then ( ( ) => this . loader . clearLocal ( 'json' ) )
283+ . then ( ( ) => this . rSet (
284+ `${ this . keySpace } :json` , JSON . stringify ( { new : 'valeo' } )
285+ ) )
286+ . then ( ( ) => this . rSet (
287+ `${ this . keySpace } :null` , JSON . stringify ( { foo : 'bar' } )
288+ ) )
289+ . then ( ( ) => this . loader . loadMany ( [ 'null' , 'json' ] ) )
290+ . then ( data => {
291+ expect ( data ) . to . deep . equal ( [ null , { new : 'valeo' } ] ) ;
292+ done ( ) ;
293+ } ) . done ( ) ;
294+ } ) ;
295+ } ) ;
256296} ) ;
0 commit comments