@@ -5,6 +5,7 @@ import { fullSettings } from '../../../utils/settingsValidation/__tests__/settin
55import { SplitsCacheInLocal } from '../SplitsCacheInLocal' ;
66import { nearlyEqual } from '../../../__tests__/testUtils' ;
77import { MySegmentsCacheInLocal } from '../MySegmentsCacheInLocal' ;
8+ import { RBSegmentsCacheInLocal } from '../RBSegmentsCacheInLocal' ;
89
910const FULL_SETTINGS_HASH = 'dc1f9817' ;
1011
@@ -14,9 +15,11 @@ describe('validateCache', () => {
1415 const segments = new MySegmentsCacheInLocal ( fullSettings . log , keys ) ;
1516 const largeSegments = new MySegmentsCacheInLocal ( fullSettings . log , keys ) ;
1617 const splits = new SplitsCacheInLocal ( fullSettings , keys ) ;
18+ const rbSegments = new RBSegmentsCacheInLocal ( fullSettings , keys ) ;
1719
18- jest . spyOn ( splits , 'clear' ) ;
1920 jest . spyOn ( splits , 'getChangeNumber' ) ;
21+ jest . spyOn ( splits , 'clear' ) ;
22+ jest . spyOn ( rbSegments , 'clear' ) ;
2023 jest . spyOn ( segments , 'clear' ) ;
2124 jest . spyOn ( largeSegments , 'clear' ) ;
2225
@@ -26,11 +29,12 @@ describe('validateCache', () => {
2629 } ) ;
2730
2831 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 ) ;
3033
3134 expect ( logSpy ) . not . toHaveBeenCalled ( ) ;
3235
3336 expect ( splits . clear ) . not . toHaveBeenCalled ( ) ;
37+ expect ( rbSegments . clear ) . not . toHaveBeenCalled ( ) ;
3438 expect ( segments . clear ) . not . toHaveBeenCalled ( ) ;
3539 expect ( largeSegments . clear ) . not . toHaveBeenCalled ( ) ;
3640 expect ( splits . getChangeNumber ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -43,11 +47,12 @@ describe('validateCache', () => {
4347 localStorage . setItem ( keys . buildSplitsTillKey ( ) , '1' ) ;
4448 localStorage . setItem ( keys . buildHashKey ( ) , FULL_SETTINGS_HASH ) ;
4549
46- expect ( validateCache ( { } , fullSettings , keys , splits , segments , largeSegments ) ) . toBe ( true ) ;
50+ expect ( validateCache ( { } , fullSettings , keys , splits , rbSegments , segments , largeSegments ) ) . toBe ( true ) ;
4751
4852 expect ( logSpy ) . not . toHaveBeenCalled ( ) ;
4953
5054 expect ( splits . clear ) . not . toHaveBeenCalled ( ) ;
55+ expect ( rbSegments . clear ) . not . toHaveBeenCalled ( ) ;
5156 expect ( segments . clear ) . not . toHaveBeenCalled ( ) ;
5257 expect ( largeSegments . clear ) . not . toHaveBeenCalled ( ) ;
5358 expect ( splits . getChangeNumber ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -61,11 +66,12 @@ describe('validateCache', () => {
6166 localStorage . setItem ( keys . buildHashKey ( ) , FULL_SETTINGS_HASH ) ;
6267 localStorage . setItem ( keys . buildLastUpdatedKey ( ) , Date . now ( ) - 1000 * 60 * 60 * 24 * 2 + '' ) ; // 2 days ago
6368
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 ) ;
6570
6671 expect ( logSpy ) . toHaveBeenCalledWith ( 'storage:localstorage: Cache expired more than 1 days ago. Cleaning up cache' ) ;
6772
6873 expect ( splits . clear ) . toHaveBeenCalledTimes ( 1 ) ;
74+ expect ( rbSegments . clear ) . toHaveBeenCalledTimes ( 1 ) ;
6975 expect ( segments . clear ) . toHaveBeenCalledTimes ( 1 ) ;
7076 expect ( largeSegments . clear ) . toHaveBeenCalledTimes ( 1 ) ;
7177
@@ -77,11 +83,12 @@ describe('validateCache', () => {
7783 localStorage . setItem ( keys . buildSplitsTillKey ( ) , '1' ) ;
7884 localStorage . setItem ( keys . buildHashKey ( ) , FULL_SETTINGS_HASH ) ;
7985
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 ) ;
8187
8288 expect ( logSpy ) . toHaveBeenCalledWith ( 'storage:localstorage: SDK key, flags filter criteria, or flags spec version has changed. Cleaning up cache' ) ;
8389
8490 expect ( splits . clear ) . toHaveBeenCalledTimes ( 1 ) ;
91+ expect ( rbSegments . clear ) . toHaveBeenCalledTimes ( 1 ) ;
8592 expect ( segments . clear ) . toHaveBeenCalledTimes ( 1 ) ;
8693 expect ( largeSegments . clear ) . toHaveBeenCalledTimes ( 1 ) ;
8794
@@ -94,11 +101,12 @@ describe('validateCache', () => {
94101 localStorage . setItem ( keys . buildSplitsTillKey ( ) , '1' ) ;
95102 localStorage . setItem ( keys . buildHashKey ( ) , FULL_SETTINGS_HASH ) ;
96103
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 ) ;
98105
99106 expect ( logSpy ) . toHaveBeenCalledWith ( 'storage:localstorage: clearOnInit was set and cache was not cleared in the last 24 hours. Cleaning up cache' ) ;
100107
101108 expect ( splits . clear ) . toHaveBeenCalledTimes ( 1 ) ;
109+ expect ( rbSegments . clear ) . toHaveBeenCalledTimes ( 1 ) ;
102110 expect ( segments . clear ) . toHaveBeenCalledTimes ( 1 ) ;
103111 expect ( largeSegments . clear ) . toHaveBeenCalledTimes ( 1 ) ;
104112
@@ -109,15 +117,16 @@ describe('validateCache', () => {
109117 // If cache is cleared, it should not clear again until a day has passed
110118 logSpy . mockClear ( ) ;
111119 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 ) ;
113121 expect ( logSpy ) . not . toHaveBeenCalled ( ) ;
114122 expect ( localStorage . getItem ( keys . buildLastClear ( ) ) ) . toBe ( lastClear ) ; // Last clear should not have changed
115123
116124 // If a day has passed, it should clear again
117125 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 ) ;
119127 expect ( logSpy ) . toHaveBeenCalledWith ( 'storage:localstorage: clearOnInit was set and cache was not cleared in the last 24 hours. Cleaning up cache' ) ;
120128 expect ( splits . clear ) . toHaveBeenCalledTimes ( 2 ) ;
129+ expect ( rbSegments . clear ) . toHaveBeenCalledTimes ( 2 ) ;
121130 expect ( segments . clear ) . toHaveBeenCalledTimes ( 2 ) ;
122131 expect ( largeSegments . clear ) . toHaveBeenCalledTimes ( 2 ) ;
123132 expect ( nearlyEqual ( parseInt ( localStorage . getItem ( keys . buildLastClear ( ) ) as string ) , Date . now ( ) ) ) . toBe ( true ) ;
0 commit comments