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' ;
7
7
8
8
const cacheInMemory = new RBSegmentsCacheInMemory ( ) ;
9
9
const cacheInLocal = new RBSegmentsCacheInLocal ( fullSettings , new KeyBuilderCS ( 'SPLITIO' , 'user' ) ) ;
10
10
11
- describe . each ( [ cacheInMemory , cacheInLocal ] ) ( 'RB SEGMENTS CACHE ' , ( cache : IRBSegmentsCacheSync ) => {
11
+ describe . each ( [ cacheInMemory , cacheInLocal ] ) ( 'Rule-based segments cache sync (Memory & LocalStorage) ' , ( cache : IRBSegmentsCacheSync ) => {
12
12
13
13
beforeEach ( ( ) => {
14
14
cache . clear ( ) ;
@@ -26,18 +26,26 @@ describe.each([cacheInMemory, cacheInLocal])('RB SEGMENTS CACHE', (cache: IRBSeg
26
26
27
27
test ( 'update should add and remove segments correctly' , ( ) => {
28
28
// Add segments
29
- const updated1 = cache . update ( [ rbSegment , rbSegmentWithInSegmentMatcher ] , [ ] , 1 ) ;
30
- expect ( updated1 ) . toBe ( true ) ;
29
+ expect ( cache . update ( [ rbSegment , rbSegmentWithInSegmentMatcher ] , [ ] , 1 ) ) . toBe ( true ) ;
31
30
expect ( cache . get ( rbSegment . name ) ) . toEqual ( rbSegment ) ;
32
31
expect ( cache . get ( rbSegmentWithInSegmentMatcher . name ) ) . toEqual ( rbSegmentWithInSegmentMatcher ) ;
33
32
expect ( cache . getChangeNumber ( ) ) . toBe ( 1 ) ;
34
33
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 ) ;
38
36
expect ( cache . get ( rbSegment . name ) ) . toBeNull ( ) ;
39
37
expect ( cache . get ( rbSegmentWithInSegmentMatcher . name ) ) . toEqual ( rbSegmentWithInSegmentMatcher ) ;
40
38
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 ) ;
41
49
} ) ;
42
50
43
51
test ( 'contains should check for segment existence correctly' , ( ) => {
@@ -47,6 +55,8 @@ describe.each([cacheInMemory, cacheInLocal])('RB SEGMENTS CACHE', (cache: IRBSeg
47
55
expect ( cache . contains ( new Set ( [ rbSegment . name , rbSegmentWithInSegmentMatcher . name ] ) ) ) . toBe ( true ) ;
48
56
expect ( cache . contains ( new Set ( [ 'nonexistent' ] ) ) ) . toBe ( false ) ;
49
57
expect ( cache . contains ( new Set ( [ rbSegment . name , 'nonexistent' ] ) ) ) . toBe ( false ) ;
58
+
59
+ cache . update ( [ ] , [ rbSegment , rbSegmentWithInSegmentMatcher ] , 2 ) ;
50
60
} ) ;
51
61
52
62
test ( 'usesSegments should track segments usage correctly' , ( ) => {
0 commit comments