@@ -111,8 +111,10 @@ describe('createCachingMethods', () => {
111111 it ( 'adds the right methods' , ( ) => {
112112 expect ( api . findOneById ) . toBeDefined ( )
113113 expect ( api . findManyByIds ) . toBeDefined ( )
114- expect ( api . findByFields ) . toBeDefined ( )
115114 expect ( api . deleteFromCacheById ) . toBeDefined ( )
115+
116+ expect ( api . findByFields ) . toBeDefined ( )
117+ expect ( api . deleteFromCacheByFields ) . toBeDefined ( )
116118 } )
117119
118120 it ( 'finds one with ObjectId' , async ( ) => {
@@ -249,7 +251,7 @@ describe('createCachingMethods', () => {
249251 expect ( value ) . toBeUndefined ( )
250252 } )
251253
252- it ( `deletes from cache` , async ( ) => {
254+ it ( `deletes from cache by ID ` , async ( ) => {
253255 for ( const doc of [ docs . one , docs . two , stringDoc ] ) {
254256 await api . findOneById ( doc . _id , { ttl : 1 } )
255257
@@ -263,7 +265,7 @@ describe('createCachingMethods', () => {
263265 }
264266 } )
265267
266- it ( 'deletes from DataLoader cache' , async ( ) => {
268+ it ( 'deletes from DataLoader cache by ID ' , async ( ) => {
267269 for ( const id of [ docs . one . _id , docs . two . _id , stringDoc . _id ] ) {
268270 await api . findOneById ( id )
269271 expect ( collection . find ) . toHaveBeenCalled ( )
@@ -277,6 +279,19 @@ describe('createCachingMethods', () => {
277279 expect ( collection . find ) . toHaveBeenCalled ( )
278280 }
279281 } )
282+
283+ it ( `deletes from cache by fields` , async ( ) => {
284+ const fields = { foo : 'bar' }
285+ await api . findByFields ( fields , { ttl : 1 } )
286+
287+ const valueBefore = await cache . get ( cacheKeyByFields ( fields ) )
288+ expect ( valueBefore ) . toEqual ( EJSON . stringify ( [ docs . one , docs . two ] ) )
289+
290+ await api . deleteFromCacheByFields ( fields )
291+
292+ const valueAfter = await cache . get ( cacheKeyByFields ( fields ) )
293+ expect ( valueAfter ) . toBeUndefined ( )
294+ } )
280295} )
281296
282297describe ( 'isValidObjectIdString' , ( ) => {
0 commit comments