-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Adapter.clear.test.ts
43 lines (37 loc) · 1.23 KB
/
Adapter.clear.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import type { CacheInterface } from '@soluble/cache-interop';
import { Guards } from '@soluble/cache-interop';
import { getTestAdapters } from '../setup/getTestAdapters';
const adapters = getTestAdapters();
describe.each(adapters)('Adapter: %s', (name, adapterFactory) => {
let cache: CacheInterface;
beforeAll(async () => {
cache = await adapterFactory();
});
afterEach(async () => {
await cache.clear();
});
afterAll(async () => {
if (Guards.isConnectedCache(cache)) {
await cache.getConnection().quit();
}
});
describe('Adapter.clear()', () => {
describe('when no value in cache', () => {
it('should return true', async () => {
expect(await cache.clear()).toStrictEqual(true);
});
});
describe('when some values are in cache', () => {
it('should return true and delete the values', async () => {
await cache.setMultiple([
['k1', 'val1'],
['k2', 'val2'],
]);
expect((await cache.getMultiple(['k1', 'k2'])).size).toStrictEqual(2);
expect(await cache.clear()).toStrictEqual(true);
expect((await cache.get('k1')).data).toBeNull();
expect((await cache.get('k2')).data).toBeNull();
});
});
});
});