Skip to content

Commit e22b286

Browse files
Update unit tests
1 parent 197469d commit e22b286

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

src/storages/inMemory/__tests__/RBSegmentsCacheSync.spec.ts renamed to src/storages/__tests__/RBSegmentsCacheSync.spec.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { RBSegmentsCacheInMemory } from '../RBSegmentsCacheInMemory';
2-
import { RBSegmentsCacheInLocal } from '../../inLocalStorage/RBSegmentsCacheInLocal';
3-
import { KeyBuilderCS } from '../../KeyBuilderCS';
4-
import { rbSegment, rbSegmentWithInSegmentMatcher } from '../../__tests__/testUtils';
5-
import { IRBSegmentsCacheSync } from '../../types';
6-
import { fullSettings } from '../../../utils/settingsValidation/__tests__/settings.mocks';
1+
import { RBSegmentsCacheInMemory } from '../inMemory/RBSegmentsCacheInMemory';
2+
import { RBSegmentsCacheInLocal } from '../inLocalStorage/RBSegmentsCacheInLocal';
3+
import { KeyBuilderCS } from '../KeyBuilderCS';
4+
import { rbSegment, rbSegmentWithInSegmentMatcher } from '../__tests__/testUtils';
5+
import { IRBSegmentsCacheSync } from '../types';
6+
import { fullSettings } from '../../utils/settingsValidation/__tests__/settings.mocks';
77

88
const cacheInMemory = new RBSegmentsCacheInMemory();
99
const cacheInLocal = new RBSegmentsCacheInLocal(fullSettings, new KeyBuilderCS('SPLITIO', 'user'));
1010

11-
describe.each([cacheInMemory, cacheInLocal])('RB SEGMENTS CACHE', (cache: IRBSegmentsCacheSync) => {
11+
describe.each([cacheInMemory, cacheInLocal])('Rule-based segments cache sync (Memory & LocalStorage)', (cache: IRBSegmentsCacheSync) => {
1212

1313
beforeEach(() => {
1414
cache.clear();
@@ -26,18 +26,26 @@ describe.each([cacheInMemory, cacheInLocal])('RB SEGMENTS CACHE', (cache: IRBSeg
2626

2727
test('update should add and remove segments correctly', () => {
2828
// Add segments
29-
const updated1 = cache.update([rbSegment, rbSegmentWithInSegmentMatcher], [], 1);
30-
expect(updated1).toBe(true);
29+
expect(cache.update([rbSegment, rbSegmentWithInSegmentMatcher], [], 1)).toBe(true);
3130
expect(cache.get(rbSegment.name)).toEqual(rbSegment);
3231
expect(cache.get(rbSegmentWithInSegmentMatcher.name)).toEqual(rbSegmentWithInSegmentMatcher);
3332
expect(cache.getChangeNumber()).toBe(1);
3433

35-
// Remove segments
36-
const updated2 = cache.update([], [rbSegment], 2);
37-
expect(updated2).toBe(true);
34+
// Remove a segment
35+
expect(cache.update([], [rbSegment], 2)).toBe(true);
3836
expect(cache.get(rbSegment.name)).toBeNull();
3937
expect(cache.get(rbSegmentWithInSegmentMatcher.name)).toEqual(rbSegmentWithInSegmentMatcher);
4038
expect(cache.getChangeNumber()).toBe(2);
39+
40+
// Remove remaining segment
41+
expect(cache.update([], [rbSegmentWithInSegmentMatcher], 3)).toBe(true);
42+
expect(cache.get(rbSegment.name)).toBeNull();
43+
expect(cache.get(rbSegmentWithInSegmentMatcher.name)).toBeNull();
44+
expect(cache.getChangeNumber()).toBe(3);
45+
46+
// No changes
47+
expect(cache.update([], [rbSegmentWithInSegmentMatcher], 4)).toBe(false);
48+
expect(cache.getChangeNumber()).toBe(4);
4149
});
4250

4351
test('contains should check for segment existence correctly', () => {
@@ -47,6 +55,8 @@ describe.each([cacheInMemory, cacheInLocal])('RB SEGMENTS CACHE', (cache: IRBSeg
4755
expect(cache.contains(new Set([rbSegment.name, rbSegmentWithInSegmentMatcher.name]))).toBe(true);
4856
expect(cache.contains(new Set(['nonexistent']))).toBe(false);
4957
expect(cache.contains(new Set([rbSegment.name, 'nonexistent']))).toBe(false);
58+
59+
cache.update([], [rbSegment, rbSegmentWithInSegmentMatcher], 2);
5060
});
5161

5262
test('usesSegments should track segments usage correctly', () => {

0 commit comments

Comments
 (0)