Skip to content

Commit f3703d9

Browse files
committed
Added tests for noOpCache
1 parent 9a2b28d commit f3703d9

3 files changed

Lines changed: 72 additions & 6 deletions

File tree

src/packages/pongo/src/core/cache/pongoCacheWrapper.unit.spec.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ describe('pongoCacheWrapper — key prefixing', () => {
1919
const spy = vi.spyOn(provider, 'set');
2020
const wrapper = pongoCacheWrapper({ provider });
2121
wrapper.set(`${dbName}:${collectionName}:doc1`, { _id: 'doc1' });
22-
expect(spy).toHaveBeenCalledWith(
23-
'mydb:users:doc1',
24-
{ _id: 'doc1' },
25-
undefined,
26-
);
22+
expect(spy).toHaveBeenCalledWith('mydb:users:doc1', { _id: 'doc1' });
2723
});
2824

2925
it('delete prefixes key', () => {

src/packages/pongo/src/core/cache/providers/noopCache.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const noopCacheProvider: PongoCache = {
66
set: () => {},
77
update: () => {},
88
delete: () => {},
9-
getMany: () => [],
9+
getMany: (keys) => keys.map(() => undefined),
1010
setMany: () => {},
1111
updateMany: () => {},
1212
deleteMany: () => {},
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { describe, expect, it } from 'vitest';
2+
import { noopCacheProvider } from './noopCache';
3+
4+
describe('noopCacheProvider', () => {
5+
it('get always returns undefined', async () => {
6+
expect(await noopCacheProvider.get('db:collection:a')).toBeUndefined();
7+
});
8+
9+
it('set then get still returns undefined', async () => {
10+
noopCacheProvider.set('db:collection:a', { _id: 'a', name: 'Alice' });
11+
expect(await noopCacheProvider.get('db:collection:a')).toBeUndefined();
12+
});
13+
14+
it('update then get still returns undefined', async () => {
15+
noopCacheProvider.update('db:collection:a', { $set: { name: 'Alice' } });
16+
expect(await noopCacheProvider.get('db:collection:a')).toBeUndefined();
17+
});
18+
19+
it('delete does nothing', async () => {
20+
noopCacheProvider.delete('db:collection:a');
21+
expect(await noopCacheProvider.get('db:collection:a')).toBeUndefined();
22+
});
23+
24+
it('getMany returns undefined for every key', () => {
25+
noopCacheProvider.set('db:collection:k1', { _id: 'k1' });
26+
noopCacheProvider.set('db:collection:k2', { _id: 'k2' });
27+
const results = noopCacheProvider.getMany([
28+
'db:collection:k1',
29+
'db:collection:missing',
30+
'db:collection:k2',
31+
]);
32+
expect(results).toHaveLength(3);
33+
expect(results[0]).toBeUndefined();
34+
expect(results[1]).toBeUndefined();
35+
expect(results[2]).toBeUndefined();
36+
});
37+
38+
it('setMany then get still returns undefined', async () => {
39+
noopCacheProvider.setMany([
40+
{ key: 'db:collection:a', value: { _id: 'a' } },
41+
{ key: 'db:collection:b', value: { _id: 'b' } },
42+
]);
43+
expect(await noopCacheProvider.get('db:collection:a')).toBeUndefined();
44+
expect(await noopCacheProvider.get('db:collection:b')).toBeUndefined();
45+
});
46+
47+
it('updateMany does nothing', async () => {
48+
noopCacheProvider.updateMany(['db:collection:a', 'db:collection:b'], {
49+
$set: { name: 'updated' },
50+
});
51+
expect(await noopCacheProvider.get('db:collection:a')).toBeUndefined();
52+
expect(await noopCacheProvider.get('db:collection:b')).toBeUndefined();
53+
});
54+
55+
it('deleteMany does nothing', async () => {
56+
noopCacheProvider.deleteMany(['db:collection:a', 'db:collection:b']);
57+
expect(await noopCacheProvider.get('db:collection:a')).toBeUndefined();
58+
expect(await noopCacheProvider.get('db:collection:b')).toBeUndefined();
59+
});
60+
61+
it('clear does nothing', async () => {
62+
noopCacheProvider.clear();
63+
expect(await noopCacheProvider.get('db:collection:a')).toBeUndefined();
64+
});
65+
66+
it('close does nothing', async () => {
67+
noopCacheProvider.close();
68+
expect(await noopCacheProvider.get('db:collection:a')).toBeUndefined();
69+
});
70+
});

0 commit comments

Comments
 (0)