-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSegmentsCachePluggable.spec.ts
More file actions
40 lines (27 loc) · 1.5 KB
/
SegmentsCachePluggable.spec.ts
File metadata and controls
40 lines (27 loc) · 1.5 KB
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
import { SegmentsCachePluggable } from '../SegmentsCachePluggable';
import { KeyBuilderSS } from '../../KeyBuilderSS';
import { loggerMock } from '../../../logger/__tests__/sdkLogger.mock';
import { wrapperMock } from './wrapper.mock';
import { metadata } from '../../__tests__/KeyBuilder.spec';
const keyBuilder = new KeyBuilderSS('prefix', metadata);
describe('SEGMENTS CACHE PLUGGABLE', () => {
afterEach(() => {
loggerMock.mockClear();
wrapperMock.mockClear();
});
test('isInSegment, getChangeNumber, update', async () => {
const cache = new SegmentsCachePluggable(loggerMock, keyBuilder, wrapperMock);
await cache.update('mocked-segment', ['a', 'b', 'c'], ['d'], 1);
expect(await cache.getChangeNumber('mocked-segment') === 1).toBe(true);
expect(await cache.getChangeNumber('inexistent-segment')).toBe(undefined); // -1 if the segment doesn't exist
await cache.update('mocked-segment', ['d', 'e'], [], 2);
await cache.update('mocked-segment', [], ['a', 'c'], 2);
expect(await cache.getChangeNumber('mocked-segment') === 2).toBe(true);
expect(await cache.isInSegment('mocked-segment', 'a')).toBe(false);
expect(await cache.isInSegment('mocked-segment', 'b')).toBe(true);
expect(await cache.isInSegment('mocked-segment', 'c')).toBe(false);
expect(await cache.isInSegment('mocked-segment', 'd')).toBe(true);
expect(await cache.isInSegment('mocked-segment', 'e')).toBe(true);
expect(await cache.isInSegment('inexistent-segment', 'a')).toBe(false);
});
});