|
| 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