@@ -28,8 +28,8 @@ describe('validateCache', () => {
2828 localStorage . clear ( ) ;
2929 } ) ;
3030
31- test ( 'if there is no cache, it should return false' , ( ) => {
32- expect ( validateCache ( { storage : localStorage } , fullSettings , keys , splits , rbSegments , segments , largeSegments ) ) . toBe ( false ) ;
31+ test ( 'if there is no cache, it should return false' , async ( ) => {
32+ expect ( await validateCache ( { storage : localStorage } , fullSettings , keys , splits , rbSegments , segments , largeSegments ) ) . toBe ( false ) ;
3333
3434 expect ( logSpy ) . not . toHaveBeenCalled ( ) ;
3535
@@ -43,11 +43,11 @@ describe('validateCache', () => {
4343 expect ( localStorage . getItem ( keys . buildLastClear ( ) ) ) . toBeNull ( ) ;
4444 } ) ;
4545
46- test ( 'if there is cache and it must not be cleared, it should return true' , ( ) => {
46+ test ( 'if there is cache and it must not be cleared, it should return true' , async ( ) => {
4747 localStorage . setItem ( keys . buildSplitsTillKey ( ) , '1' ) ;
4848 localStorage . setItem ( keys . buildHashKey ( ) , FULL_SETTINGS_HASH ) ;
4949
50- expect ( validateCache ( { storage : localStorage } , fullSettings , keys , splits , rbSegments , segments , largeSegments ) ) . toBe ( true ) ;
50+ expect ( await validateCache ( { storage : localStorage } , fullSettings , keys , splits , rbSegments , segments , largeSegments ) ) . toBe ( true ) ;
5151
5252 expect ( logSpy ) . not . toHaveBeenCalled ( ) ;
5353
@@ -61,12 +61,12 @@ describe('validateCache', () => {
6161 expect ( localStorage . getItem ( keys . buildLastClear ( ) ) ) . toBeNull ( ) ;
6262 } ) ;
6363
64- test ( 'if there is cache and it has expired, it should clear cache and return false' , ( ) => {
64+ test ( 'if there is cache and it has expired, it should clear cache and return false' , async ( ) => {
6565 localStorage . setItem ( keys . buildSplitsTillKey ( ) , '1' ) ;
6666 localStorage . setItem ( keys . buildHashKey ( ) , FULL_SETTINGS_HASH ) ;
6767 localStorage . setItem ( keys . buildLastUpdatedKey ( ) , Date . now ( ) - 1000 * 60 * 60 * 24 * 2 + '' ) ; // 2 days ago
6868
69- expect ( validateCache ( { expirationDays : 1 , storage : localStorage } , fullSettings , keys , splits , rbSegments , segments , largeSegments ) ) . toBe ( false ) ;
69+ expect ( await validateCache ( { storage : localStorage , expirationDays : 1 } , fullSettings , keys , splits , rbSegments , segments , largeSegments ) ) . toBe ( false ) ;
7070
7171 expect ( logSpy ) . toHaveBeenCalledWith ( 'storage:localstorage: Cache expired more than 1 days ago. Cleaning up cache' ) ;
7272
@@ -79,11 +79,11 @@ describe('validateCache', () => {
7979 expect ( nearlyEqual ( parseInt ( localStorage . getItem ( keys . buildLastClear ( ) ) as string ) , Date . now ( ) ) ) . toBe ( true ) ;
8080 } ) ;
8181
82- test ( 'if there is cache and its hash has changed, it should clear cache and return false' , ( ) => {
82+ test ( 'if there is cache and its hash has changed, it should clear cache and return false' , async ( ) => {
8383 localStorage . setItem ( keys . buildSplitsTillKey ( ) , '1' ) ;
8484 localStorage . setItem ( keys . buildHashKey ( ) , FULL_SETTINGS_HASH ) ;
8585
86- expect ( validateCache ( { storage : localStorage } , { ...fullSettings , core : { ...fullSettings . core , authorizationKey : 'another-sdk-key' } } , keys , splits , rbSegments , segments , largeSegments ) ) . toBe ( false ) ;
86+ expect ( await validateCache ( { storage : localStorage } , { ...fullSettings , core : { ...fullSettings . core , authorizationKey : 'another-sdk-key' } } , keys , splits , rbSegments , segments , largeSegments ) ) . toBe ( false ) ;
8787
8888 expect ( logSpy ) . toHaveBeenCalledWith ( 'storage:localstorage: SDK key, flags filter criteria, or flags spec version has changed. Cleaning up cache' ) ;
8989
@@ -96,12 +96,12 @@ describe('validateCache', () => {
9696 expect ( nearlyEqual ( parseInt ( localStorage . getItem ( keys . buildLastClear ( ) ) as string ) , Date . now ( ) ) ) . toBe ( true ) ;
9797 } ) ;
9898
99- test ( 'if there is cache and clearOnInit is true, it should clear cache and return false' , ( ) => {
99+ test ( 'if there is cache and clearOnInit is true, it should clear cache and return false' , async ( ) => {
100100 // Older cache version (without last clear)
101101 localStorage . setItem ( keys . buildSplitsTillKey ( ) , '1' ) ;
102102 localStorage . setItem ( keys . buildHashKey ( ) , FULL_SETTINGS_HASH ) ;
103103
104- expect ( validateCache ( { clearOnInit : true , storage : localStorage } , fullSettings , keys , splits , rbSegments , segments , largeSegments ) ) . toBe ( false ) ;
104+ expect ( await validateCache ( { storage : localStorage , clearOnInit : true } , fullSettings , keys , splits , rbSegments , segments , largeSegments ) ) . toBe ( false ) ;
105105
106106 expect ( logSpy ) . toHaveBeenCalledWith ( 'storage:localstorage: clearOnInit was set and cache was not cleared in the last 24 hours. Cleaning up cache' ) ;
107107
@@ -117,13 +117,13 @@ describe('validateCache', () => {
117117 // If cache is cleared, it should not clear again until a day has passed
118118 logSpy . mockClear ( ) ;
119119 localStorage . setItem ( keys . buildSplitsTillKey ( ) , '1' ) ;
120- expect ( validateCache ( { clearOnInit : true , storage : localStorage } , fullSettings , keys , splits , rbSegments , segments , largeSegments ) ) . toBe ( true ) ;
120+ expect ( await validateCache ( { storage : localStorage , clearOnInit : true } , fullSettings , keys , splits , rbSegments , segments , largeSegments ) ) . toBe ( true ) ;
121121 expect ( logSpy ) . not . toHaveBeenCalled ( ) ;
122122 expect ( localStorage . getItem ( keys . buildLastClear ( ) ) ) . toBe ( lastClear ) ; // Last clear should not have changed
123123
124124 // If a day has passed, it should clear again
125125 localStorage . setItem ( keys . buildLastClear ( ) , ( Date . now ( ) - 1000 * 60 * 60 * 24 - 1 ) + '' ) ;
126- expect ( validateCache ( { clearOnInit : true , storage : localStorage } , fullSettings , keys , splits , rbSegments , segments , largeSegments ) ) . toBe ( false ) ;
126+ expect ( await validateCache ( { storage : localStorage , clearOnInit : true } , fullSettings , keys , splits , rbSegments , segments , largeSegments ) ) . toBe ( false ) ;
127127 expect ( logSpy ) . toHaveBeenCalledWith ( 'storage:localstorage: clearOnInit was set and cache was not cleared in the last 24 hours. Cleaning up cache' ) ;
128128 expect ( splits . clear ) . toHaveBeenCalledTimes ( 2 ) ;
129129 expect ( rbSegments . clear ) . toHaveBeenCalledTimes ( 2 ) ;
0 commit comments