@@ -2,9 +2,9 @@ import { describe, expect, it } from 'vitest';
22import { lruCache } from './lruCache' ;
33
44describe ( 'inMemoryCacheProvider' , ( ) => {
5- it ( 'returns null for missing keys' , ( ) => {
5+ it ( 'returns undefined for missing keys' , ( ) => {
66 const cache = lruCache ( ) ;
7- expect ( cache . get ( 'db:collection:missing' ) ) . toBeNull ( ) ;
7+ expect ( cache . get ( 'db:collection:missing' ) ) . toBeUndefined ( ) ;
88 } ) ;
99
1010 it ( 'set then get returns the stored document' , ( ) => {
@@ -19,28 +19,29 @@ describe('inMemoryCacheProvider', () => {
1919 cache . set ( 'db:collection:x' , { _id : 'x' } ) ;
2020 expect ( cache . get ( 'db:collection:x' ) ) . toBeDefined ( ) ;
2121 await new Promise ( ( r ) => setTimeout ( r , 100 ) ) ;
22- expect ( cache . get ( 'db:collection:x' ) ) . toBeNull ( ) ;
22+ expect ( cache . get ( 'db:collection:x' ) ) . toBeUndefined ( ) ;
2323 } ) ;
2424
2525 it ( 'delete removes a cached entry' , ( ) => {
2626 const cache = lruCache ( ) ;
2727 cache . set ( 'db:collection:a' , { _id : 'a' } ) ;
2828 cache . delete ( 'db:collection:a' ) ;
29- expect ( cache . get ( 'db:collection:a' ) ) . toBeNull ( ) ;
29+ expect ( cache . get ( 'db:collection:a' ) ) . toBeUndefined ( ) ;
3030 } ) ;
3131
32- it ( 'getMany returns documents for found keys and nothing for missing' , ( ) => {
32+ it ( 'getMany returns documents for found keys and undefined for missing' , ( ) => {
3333 const cache = lruCache ( ) ;
3434 cache . set ( 'db:collection:k1' , { _id : 'k1' } ) ;
3535 cache . set ( 'db:collection:k2' , { _id : 'k2' } ) ;
3636 const results = cache . getMany ( [
3737 'db:collection:k1' ,
3838 'db:collection:missing' ,
3939 'db:collection:k2' ,
40- ] ) as ( Record < string , unknown > | null | undefined ) [ ] ;
41- expect ( results ) . toHaveLength ( 2 ) ; // Only returns found entries
40+ ] ) as ( Record < string , unknown > | undefined ) [ ] ;
41+ expect ( results ) . toHaveLength ( 3 ) ;
4242 expect ( results [ 0 ] ) . toEqual ( { _id : 'k1' } ) ;
43- expect ( results [ 1 ] ) . toEqual ( { _id : 'k2' } ) ;
43+ expect ( results [ 1 ] ) . toBeUndefined ( ) ;
44+ expect ( results [ 2 ] ) . toEqual ( { _id : 'k2' } ) ;
4445 } ) ;
4546
4647 it ( 'setMany stores multiple documents retrievable via get' , ( ) => {
@@ -61,8 +62,8 @@ describe('inMemoryCacheProvider', () => {
6162 { key : 'db:collection:c' , value : { _id : 'c' } } ,
6263 ] ) ;
6364 cache . deleteMany ( [ 'db:collection:a' , 'db:collection:b' ] ) ;
64- expect ( cache . get ( 'db:collection:a' ) ) . toBeNull ( ) ;
65- expect ( cache . get ( 'db:collection:b' ) ) . toBeNull ( ) ;
65+ expect ( cache . get ( 'db:collection:a' ) ) . toBeUndefined ( ) ;
66+ expect ( cache . get ( 'db:collection:b' ) ) . toBeUndefined ( ) ;
6667 expect ( cache . get ( 'db:collection:c' ) ) . toEqual ( { _id : 'c' } ) ;
6768 } ) ;
6869
@@ -73,8 +74,8 @@ describe('inMemoryCacheProvider', () => {
7374 { key : 'db:collection:b' , value : { _id : 'b' } } ,
7475 ] ) ;
7576 cache . clear ( ) ;
76- expect ( cache . get ( 'db:collection:a' ) ) . toBeNull ( ) ;
77- expect ( cache . get ( 'db:collection:b' ) ) . toBeNull ( ) ;
77+ expect ( cache . get ( 'db:collection:a' ) ) . toBeUndefined ( ) ;
78+ expect ( cache . get ( 'db:collection:b' ) ) . toBeUndefined ( ) ;
7879 } ) ;
7980
8081 it ( 'respects max — LRU entry is evicted when full' , ( ) => {
@@ -85,7 +86,7 @@ describe('inMemoryCacheProvider', () => {
8586 cache . set ( 'db:collection:c' , { _id : 'c' } ) ;
8687 expect ( cache . get ( 'db:collection:a' ) ) . toBeDefined ( ) ;
8788 expect ( cache . get ( 'db:collection:c' ) ) . toBeDefined ( ) ;
88- expect ( cache . get ( 'db:collection:b' ) ) . toBeNull ( ) ;
89+ expect ( cache . get ( 'db:collection:b' ) ) . toBeUndefined ( ) ;
8990 } ) ;
9091
9192 it ( 'returns values synchronously (not wrapped in Promises)' , ( ) => {
0 commit comments