-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMySegmentsCacheInLocal.spec.ts
More file actions
38 lines (31 loc) · 1.49 KB
/
MySegmentsCacheInLocal.spec.ts
File metadata and controls
38 lines (31 loc) · 1.49 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
import { MySegmentsCacheInLocal } from '../MySegmentsCacheInLocal';
import { KeyBuilderCS, myLargeSegmentsKeyBuilder } from '../../KeyBuilderCS';
import { loggerMock } from '../../../logger/__tests__/sdkLogger.mock';
test('SEGMENT CACHE / in LocalStorage', () => {
const caches = [
new MySegmentsCacheInLocal(loggerMock, new KeyBuilderCS('SPLITIO', 'user')),
new MySegmentsCacheInLocal(loggerMock, myLargeSegmentsKeyBuilder('SPLITIO', 'user'))
];
caches.forEach(cache => {
cache.clear();
expect(cache.resetSegments({ k: [{ n: 'mocked-segment' }, { n: 'mocked-segment-2' }], cn: 123 })).toBe(true);
expect(cache.getChangeNumber()).toBe(123);
expect(cache.resetSegments({ k: [{ n: 'mocked-segment' }, { n: 'mocked-segment-2' }] })).toBe(false);
expect(cache.getChangeNumber()).toBe(-1);
expect(cache.isInSegment('mocked-segment')).toBe(true);
expect(cache.getKeysCount()).toBe(1);
});
caches.forEach(cache => {
// @ts-expect-error
cache.resetSegments({
added: [],
removed: ['mocked-segment']
});
expect(cache.isInSegment('mocked-segment')).toBe(false);
expect(cache.getKeysCount()).toBe(1);
});
expect(localStorage.getItem('SPLITIO.user.segment.mocked-segment-2')).toBe('1');
expect(localStorage.getItem('SPLITIO.user.segment.mocked-segment')).toBe(null);
expect(localStorage.getItem('SPLITIO.user.largeSegment.mocked-segment-2')).toBe('1');
expect(localStorage.getItem('SPLITIO.user.largeSegment.mocked-segment')).toBe(null);
});