@@ -78,6 +78,44 @@ it('call loader for missing entries', async () => {
7878 expect ( loader ) . toBeCalledWith ( [ 'faa' ] )
7979} )
8080
81+ it ( 'verify entries per callback' , async ( ) => {
82+ const { api } = await setupApi ( { cacheValues : { foo : 'FOO' , bar : 'BAR' } } )
83+
84+ const expire = jest . fn ( o => o . data === 'FOO' )
85+
86+ const value = api . get ( [ 'foo' , 'bar' ] , undefined , expire , 'obj' )
87+
88+ expect ( expire ) . toBeCalledTimes ( 2 )
89+ expect ( expire ) . toHaveBeenNthCalledWith ( 1 , expect . objectContaining ( { data : 'FOO' } ) )
90+ expect ( expire ) . toHaveBeenNthCalledWith ( 2 , expect . objectContaining ( { data : 'BAR' } ) )
91+ expect ( value ) . toEqual ( {
92+ foo : expect . objectContaining ( { data : 'FOO' , valid : false } ) ,
93+ bar : expect . objectContaining ( { data : 'BAR' , valid : true } ) ,
94+ } )
95+ } )
96+
97+ it ( 'verify entries per age' , async ( ) => {
98+ const { api } = await setupApi ( {
99+ cacheObjects : {
100+ faa : { data : 'a' , meta : { date : new Date ( ) } } ,
101+ fee : { data : 'b' , meta : { date : ( new Date ( ) ) . toString ( ) } } ,
102+ fii : { data : 'c' , meta : { date : undefined } } ,
103+ foo : { data : 'd' , meta : { date : new Date ( '2001-02-03T04:05:06Z' ) } } ,
104+ fuu : { data : 'e' , meta : { date : '2001-02-03T04:05:06Z' } } ,
105+ } ,
106+ } )
107+
108+ const value = api . get ( [ 'faa' , 'fee' , 'fii' , 'foo' , 'fuu' ] , undefined , 10000 , 'obj' )
109+
110+ expect ( value ) . toEqual ( {
111+ 'faa' : expect . objectContaining ( { data : 'a' , valid : true } ) ,
112+ 'fee' : expect . objectContaining ( { data : 'b' , valid : true } ) ,
113+ 'fii' : expect . objectContaining ( { data : 'c' , valid : true } ) ,
114+ 'foo' : expect . objectContaining ( { data : 'd' , valid : false } ) ,
115+ 'fuu' : expect . objectContaining ( { data : 'e' , valid : false } ) ,
116+ } )
117+ } )
118+
81119it ( 'call loader for expired (per callback) entries' , async ( ) => {
82120 const { cache, rerender, api } = await setupApi ( { cacheValues : { foo : 'bar' } , idbValues : { fuu : 'baz' } } )
83121 const loader = jest . fn ( ( ) => {
0 commit comments