|
1 | 1 | /* eslint-disable no-undef */
|
2 | 2 |
|
3 | 3 | import { RedisCache } from '@/lib/cache/RedisCache';
|
| 4 | +const Redis = require('ioredis'); |
4 | 5 |
|
5 | 6 | let cache: RedisCache;
|
6 | 7 |
|
@@ -37,27 +38,25 @@ it('determines if an item is in the cache', async () => {
|
37 | 38 | expect(await cache.has('two')).toBeFalsy();
|
38 | 39 | });
|
39 | 40 |
|
40 |
| -// it('purges expired items', () => { |
41 |
| -// cache.put('one', 1, 10); |
42 |
| -// cache.map['one'].expires = 0; |
| 41 | +it('prefixes all keys with a prefix', async () => { |
| 42 | + const testRedis = new Redis(); |
| 43 | + const customCache = new RedisCache('myprefix'); |
43 | 44 |
|
44 |
| -// cache.purge(); |
| 45 | + try { |
| 46 | + customCache.put('one', 1, 10); |
45 | 47 |
|
46 |
| -// expect(cache.map['one']).toBeUndefined(); |
47 |
| -// }); |
48 |
| - |
49 |
| -// it('purges expired entries before returning an item', async () => { |
50 |
| -// cache.put('one', 1, 10); |
51 |
| -// cache.map['one'].expires -= 15 * 1000; |
52 |
| - |
53 |
| -// expect(await cache.get('one')).toBeNull(); |
54 |
| -// expect(cache.map['one']).toBeUndefined(); |
55 |
| -// }); |
| 48 | + expect(await customCache.has('one')).toBeTruthy(); |
| 49 | + expect(await testRedis.exists('myprefix:one')).toBeTruthy(); |
| 50 | + } finally { |
| 51 | + customCache.destroy(); |
| 52 | + testRedis.disconnect(); |
| 53 | + } |
| 54 | +}); |
56 | 55 |
|
57 |
| -// it('purges expired entries before checking if an item exists', async () => { |
58 |
| -// cache.put('one', 1, 10); |
59 |
| -// cache.map['one'].expires -= 15 * 1000; |
| 56 | +it('purges expired items', () => { |
| 57 | + expect(cache.purge()).toBeTruthy(); |
| 58 | +}); |
60 | 59 |
|
61 |
| -// expect(await cache.has('one')).toBeFalsy(); |
62 |
| -// expect(cache.map['one']).toBeUndefined(); |
63 |
| -// }); |
| 60 | +it('clears items', () => { |
| 61 | + expect(cache.clear()).toBeTruthy(); |
| 62 | +}); |
0 commit comments