@@ -5,6 +5,7 @@ import { fullSettings } from '../../../utils/settingsValidation/__tests__/settin
5
5
import { SplitsCacheInLocal } from '../SplitsCacheInLocal' ;
6
6
import { nearlyEqual } from '../../../__tests__/testUtils' ;
7
7
import { MySegmentsCacheInLocal } from '../MySegmentsCacheInLocal' ;
8
+ import { RBSegmentsCacheInLocal } from '../RBSegmentsCacheInLocal' ;
8
9
9
10
const FULL_SETTINGS_HASH = 'dc1f9817' ;
10
11
@@ -14,9 +15,11 @@ describe('validateCache', () => {
14
15
const segments = new MySegmentsCacheInLocal ( fullSettings . log , keys ) ;
15
16
const largeSegments = new MySegmentsCacheInLocal ( fullSettings . log , keys ) ;
16
17
const splits = new SplitsCacheInLocal ( fullSettings , keys ) ;
18
+ const rbSegments = new RBSegmentsCacheInLocal ( fullSettings , keys ) ;
17
19
18
- jest . spyOn ( splits , 'clear' ) ;
19
20
jest . spyOn ( splits , 'getChangeNumber' ) ;
21
+ jest . spyOn ( splits , 'clear' ) ;
22
+ jest . spyOn ( rbSegments , 'clear' ) ;
20
23
jest . spyOn ( segments , 'clear' ) ;
21
24
jest . spyOn ( largeSegments , 'clear' ) ;
22
25
@@ -26,11 +29,12 @@ describe('validateCache', () => {
26
29
} ) ;
27
30
28
31
test ( 'if there is no cache, it should return false' , ( ) => {
29
- expect ( validateCache ( { } , fullSettings , keys , splits , segments , largeSegments ) ) . toBe ( false ) ;
32
+ expect ( validateCache ( { } , fullSettings , keys , splits , rbSegments , segments , largeSegments ) ) . toBe ( false ) ;
30
33
31
34
expect ( logSpy ) . not . toHaveBeenCalled ( ) ;
32
35
33
36
expect ( splits . clear ) . not . toHaveBeenCalled ( ) ;
37
+ expect ( rbSegments . clear ) . not . toHaveBeenCalled ( ) ;
34
38
expect ( segments . clear ) . not . toHaveBeenCalled ( ) ;
35
39
expect ( largeSegments . clear ) . not . toHaveBeenCalled ( ) ;
36
40
expect ( splits . getChangeNumber ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -43,11 +47,12 @@ describe('validateCache', () => {
43
47
localStorage . setItem ( keys . buildSplitsTillKey ( ) , '1' ) ;
44
48
localStorage . setItem ( keys . buildHashKey ( ) , FULL_SETTINGS_HASH ) ;
45
49
46
- expect ( validateCache ( { } , fullSettings , keys , splits , segments , largeSegments ) ) . toBe ( true ) ;
50
+ expect ( validateCache ( { } , fullSettings , keys , splits , rbSegments , segments , largeSegments ) ) . toBe ( true ) ;
47
51
48
52
expect ( logSpy ) . not . toHaveBeenCalled ( ) ;
49
53
50
54
expect ( splits . clear ) . not . toHaveBeenCalled ( ) ;
55
+ expect ( rbSegments . clear ) . not . toHaveBeenCalled ( ) ;
51
56
expect ( segments . clear ) . not . toHaveBeenCalled ( ) ;
52
57
expect ( largeSegments . clear ) . not . toHaveBeenCalled ( ) ;
53
58
expect ( splits . getChangeNumber ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -61,11 +66,12 @@ describe('validateCache', () => {
61
66
localStorage . setItem ( keys . buildHashKey ( ) , FULL_SETTINGS_HASH ) ;
62
67
localStorage . setItem ( keys . buildLastUpdatedKey ( ) , Date . now ( ) - 1000 * 60 * 60 * 24 * 2 + '' ) ; // 2 days ago
63
68
64
- expect ( validateCache ( { expirationDays : 1 } , fullSettings , keys , splits , segments , largeSegments ) ) . toBe ( false ) ;
69
+ expect ( validateCache ( { expirationDays : 1 } , fullSettings , keys , splits , rbSegments , segments , largeSegments ) ) . toBe ( false ) ;
65
70
66
71
expect ( logSpy ) . toHaveBeenCalledWith ( 'storage:localstorage: Cache expired more than 1 days ago. Cleaning up cache' ) ;
67
72
68
73
expect ( splits . clear ) . toHaveBeenCalledTimes ( 1 ) ;
74
+ expect ( rbSegments . clear ) . toHaveBeenCalledTimes ( 1 ) ;
69
75
expect ( segments . clear ) . toHaveBeenCalledTimes ( 1 ) ;
70
76
expect ( largeSegments . clear ) . toHaveBeenCalledTimes ( 1 ) ;
71
77
@@ -77,11 +83,12 @@ describe('validateCache', () => {
77
83
localStorage . setItem ( keys . buildSplitsTillKey ( ) , '1' ) ;
78
84
localStorage . setItem ( keys . buildHashKey ( ) , FULL_SETTINGS_HASH ) ;
79
85
80
- expect ( validateCache ( { } , { ...fullSettings , core : { ...fullSettings . core , authorizationKey : 'another-sdk-key' } } , keys , splits , segments , largeSegments ) ) . toBe ( false ) ;
86
+ expect ( validateCache ( { } , { ...fullSettings , core : { ...fullSettings . core , authorizationKey : 'another-sdk-key' } } , keys , splits , rbSegments , segments , largeSegments ) ) . toBe ( false ) ;
81
87
82
88
expect ( logSpy ) . toHaveBeenCalledWith ( 'storage:localstorage: SDK key, flags filter criteria, or flags spec version has changed. Cleaning up cache' ) ;
83
89
84
90
expect ( splits . clear ) . toHaveBeenCalledTimes ( 1 ) ;
91
+ expect ( rbSegments . clear ) . toHaveBeenCalledTimes ( 1 ) ;
85
92
expect ( segments . clear ) . toHaveBeenCalledTimes ( 1 ) ;
86
93
expect ( largeSegments . clear ) . toHaveBeenCalledTimes ( 1 ) ;
87
94
@@ -94,11 +101,12 @@ describe('validateCache', () => {
94
101
localStorage . setItem ( keys . buildSplitsTillKey ( ) , '1' ) ;
95
102
localStorage . setItem ( keys . buildHashKey ( ) , FULL_SETTINGS_HASH ) ;
96
103
97
- expect ( validateCache ( { clearOnInit : true } , fullSettings , keys , splits , segments , largeSegments ) ) . toBe ( false ) ;
104
+ expect ( validateCache ( { clearOnInit : true } , fullSettings , keys , splits , rbSegments , segments , largeSegments ) ) . toBe ( false ) ;
98
105
99
106
expect ( logSpy ) . toHaveBeenCalledWith ( 'storage:localstorage: clearOnInit was set and cache was not cleared in the last 24 hours. Cleaning up cache' ) ;
100
107
101
108
expect ( splits . clear ) . toHaveBeenCalledTimes ( 1 ) ;
109
+ expect ( rbSegments . clear ) . toHaveBeenCalledTimes ( 1 ) ;
102
110
expect ( segments . clear ) . toHaveBeenCalledTimes ( 1 ) ;
103
111
expect ( largeSegments . clear ) . toHaveBeenCalledTimes ( 1 ) ;
104
112
@@ -109,15 +117,16 @@ describe('validateCache', () => {
109
117
// If cache is cleared, it should not clear again until a day has passed
110
118
logSpy . mockClear ( ) ;
111
119
localStorage . setItem ( keys . buildSplitsTillKey ( ) , '1' ) ;
112
- expect ( validateCache ( { clearOnInit : true } , fullSettings , keys , splits , segments , largeSegments ) ) . toBe ( true ) ;
120
+ expect ( validateCache ( { clearOnInit : true } , fullSettings , keys , splits , rbSegments , segments , largeSegments ) ) . toBe ( true ) ;
113
121
expect ( logSpy ) . not . toHaveBeenCalled ( ) ;
114
122
expect ( localStorage . getItem ( keys . buildLastClear ( ) ) ) . toBe ( lastClear ) ; // Last clear should not have changed
115
123
116
124
// If a day has passed, it should clear again
117
125
localStorage . setItem ( keys . buildLastClear ( ) , ( Date . now ( ) - 1000 * 60 * 60 * 24 - 1 ) + '' ) ;
118
- expect ( validateCache ( { clearOnInit : true } , fullSettings , keys , splits , segments , largeSegments ) ) . toBe ( false ) ;
126
+ expect ( validateCache ( { clearOnInit : true } , fullSettings , keys , splits , rbSegments , segments , largeSegments ) ) . toBe ( false ) ;
119
127
expect ( logSpy ) . toHaveBeenCalledWith ( 'storage:localstorage: clearOnInit was set and cache was not cleared in the last 24 hours. Cleaning up cache' ) ;
120
128
expect ( splits . clear ) . toHaveBeenCalledTimes ( 2 ) ;
129
+ expect ( rbSegments . clear ) . toHaveBeenCalledTimes ( 2 ) ;
121
130
expect ( segments . clear ) . toHaveBeenCalledTimes ( 2 ) ;
122
131
expect ( largeSegments . clear ) . toHaveBeenCalledTimes ( 2 ) ;
123
132
expect ( nearlyEqual ( parseInt ( localStorage . getItem ( keys . buildLastClear ( ) ) as string ) , Date . now ( ) ) ) . toBe ( true ) ;
0 commit comments