@@ -5,7 +5,6 @@ var assert = require('assert');
55
66var redisCache ;
77var customRedisCache ;
8- var customRedisCache2 ;
98
109before ( function ( ) {
1110 redisCache = require ( 'cache-manager' ) . caching ( {
@@ -25,20 +24,11 @@ before(function () {
2524 ttl : config . redis . ttl ,
2625 isCacheableValue : function ( val ) {
2726 // allow undefined
28- if ( val === undefined ) return true ;
29- return redisCache . store . isCacheableValue ( val ) ;
30- }
31- } ) ;
32-
33- customRedisCache2 = require ( 'cache-manager' ) . caching ( {
34- store : redisStore ,
35- host : config . redis . host ,
36- port : config . redis . port ,
37- db : config . redis . db ,
38- ttl : config . redis . ttl ,
39- isCacheableValue : function ( val ) {
27+ if ( val === undefined )
28+ return true ;
4029 // disallow FooBarString
41- if ( val === 'FooBarString' ) return false ;
30+ else if ( val === 'FooBarString' )
31+ return false ;
4232 return redisCache . store . isCacheableValue ( val ) ;
4333 }
4434 } ) ;
@@ -92,20 +82,20 @@ describe('set', function () {
9282 done ( ) ;
9383 } ) ;
9484 } ) ;
85+ } ) ;
9586
96- it ( 'should store a null value without error' , function ( done ) {
97- redisCache . set ( 'foo2' , null , function ( err ) {
98- try {
87+ it ( 'should store a null value without error' , function ( done ) {
88+ redisCache . set ( 'foo2' , null , function ( err ) {
89+ try {
90+ assert . equal ( err , null ) ;
91+ redisCache . get ( 'foo2' , function ( err , value ) {
9992 assert . equal ( err , null ) ;
100- redisCache . get ( 'foo2' , function ( err , value ) {
101- assert . equal ( err , null ) ;
102- assert . equal ( value , null ) ;
103- done ( ) ;
104- } ) ;
105- } catch ( e ) {
106- done ( e ) ;
107- }
108- } ) ;
93+ assert . equal ( value , null ) ;
94+ done ( ) ;
95+ } ) ;
96+ } catch ( e ) {
97+ done ( e ) ;
98+ }
10999 } ) ;
110100 } ) ;
111101
@@ -130,7 +120,7 @@ describe('set', function () {
130120 } ) ;
131121 } ) ;
132122
133- it ( 'should store an undefined value if permitted by isCacheableValue' , function ( done ) {
123+ it ( 'should store an undefined value if permitted by isCacheableValue' , function ( done ) {
134124 assert ( customRedisCache . store . isCacheableValue ( undefined ) , true ) ;
135125 customRedisCache . set ( 'foo3' , undefined , function ( err ) {
136126 try {
@@ -152,8 +142,8 @@ describe('set', function () {
152142 } ) ;
153143
154144 it ( 'should not store a value disallowed by isCacheableValue' , function ( done ) {
155- assert . strictEqual ( customRedisCache2 . store . isCacheableValue ( 'FooBarString' ) , false ) ;
156- customRedisCache2 . set ( 'foobar' , 'FooBarString' , function ( err ) {
145+ assert . strictEqual ( customRedisCache . store . isCacheableValue ( 'FooBarString' ) , false ) ;
146+ customRedisCache . set ( 'foobar' , 'FooBarString' , function ( err ) {
157147 try {
158148 assert . notEqual ( err , null ) ;
159149 assert . equal ( err . message , 'value cannot be FooBarString' ) ;
@@ -341,16 +331,16 @@ describe('keys', function () {
341331} ) ;
342332
343333describe ( 'isCacheableValue' , function ( ) {
344- it ( 'should return true when the value is not null or undefined' , function ( done ) {
334+ it ( 'should return true when the value is not undefined' , function ( done ) {
345335 assert . equal ( redisCache . store . isCacheableValue ( 0 ) , true ) ;
346336 assert . equal ( redisCache . store . isCacheableValue ( 100 ) , true ) ;
347337 assert . equal ( redisCache . store . isCacheableValue ( '' ) , true ) ;
348338 assert . equal ( redisCache . store . isCacheableValue ( 'test' ) , true ) ;
339+ assert . equal ( redisCache . store . isCacheableValue ( null ) , true ) ;
349340 done ( ) ;
350341 } ) ;
351342
352- it ( 'should return false when the value is null or undefined' , function ( done ) {
353- assert . equal ( redisCache . store . isCacheableValue ( null ) , false ) ;
343+ it ( 'should return false when the value is undefined' , function ( done ) {
354344 assert . equal ( redisCache . store . isCacheableValue ( undefined ) , false ) ;
355345 done ( ) ;
356346 } ) ;
0 commit comments