@@ -7,6 +7,7 @@ import { fullSettings } from '../../../utils/settingsValidation/__tests__/settin
77
88test ( 'SPLIT CACHE / LocalStorage' , ( ) => {
99 const cache = new SplitsCacheInLocal ( fullSettings , new KeyBuilderCS ( 'SPLITIO' , 'user' ) ) ;
10+ cache . validateCache ( ) ;
1011
1112 cache . clear ( ) ;
1213
@@ -40,6 +41,7 @@ test('SPLIT CACHE / LocalStorage', () => {
4041
4142test ( 'SPLIT CACHE / LocalStorage / Get Keys' , ( ) => {
4243 const cache = new SplitsCacheInLocal ( fullSettings , new KeyBuilderCS ( 'SPLITIO' , 'user' ) ) ;
44+ cache . validateCache ( ) ;
4345
4446 cache . addSplit ( 'lol1' , something ) ;
4547 cache . addSplit ( 'lol2' , somethingElse ) ;
@@ -52,6 +54,7 @@ test('SPLIT CACHE / LocalStorage / Get Keys', () => {
5254
5355test ( 'SPLIT CACHE / LocalStorage / Add Splits' , ( ) => {
5456 const cache = new SplitsCacheInLocal ( fullSettings , new KeyBuilderCS ( 'SPLITIO' , 'user' ) ) ;
57+ cache . validateCache ( ) ;
5558
5659 cache . addSplits ( [
5760 [ 'lol1' , something ] ,
@@ -66,6 +69,7 @@ test('SPLIT CACHE / LocalStorage / Add Splits', () => {
6669
6770test ( 'SPLIT CACHE / LocalStorage / trafficTypeExists and ttcache tests' , ( ) => {
6871 const cache = new SplitsCacheInLocal ( fullSettings , new KeyBuilderCS ( 'SPLITIO' , 'user' ) ) ;
72+ cache . validateCache ( ) ;
6973
7074 cache . addSplits ( [ // loop of addSplit
7175 [ 'split1' , splitWithUserTT ] ,
@@ -104,6 +108,8 @@ test('SPLIT CACHE / LocalStorage / trafficTypeExists and ttcache tests', () => {
104108
105109test ( 'SPLIT CACHE / LocalStorage / killLocally' , ( ) => {
106110 const cache = new SplitsCacheInLocal ( fullSettings , new KeyBuilderCS ( 'SPLITIO' , 'user' ) ) ;
111+ cache . validateCache ( ) ;
112+
107113 cache . addSplit ( 'lol1' , something ) ;
108114 cache . addSplit ( 'lol2' , somethingElse ) ;
109115 const initialChangeNumber = cache . getChangeNumber ( ) ;
@@ -136,6 +142,7 @@ test('SPLIT CACHE / LocalStorage / killLocally', () => {
136142
137143test ( 'SPLIT CACHE / LocalStorage / usesSegments' , ( ) => {
138144 const cache = new SplitsCacheInLocal ( fullSettings , new KeyBuilderCS ( 'SPLITIO' , 'user' ) ) ;
145+ cache . validateCache ( ) ;
139146
140147 expect ( cache . usesSegments ( ) ) . toBe ( true ) ; // true initially, until data is synchronized
141148 cache . setChangeNumber ( 1 ) ; // to indicate that data has been synced.
@@ -167,6 +174,8 @@ test('SPLIT CACHE / LocalStorage / flag set cache tests', () => {
167174 }
168175 }
169176 } , new KeyBuilderCS ( 'SPLITIO' , 'user' ) ) ;
177+ cache . validateCache ( ) ;
178+
170179 const emptySet = new Set ( [ ] ) ;
171180
172181 cache . addSplits ( [
@@ -206,25 +215,27 @@ test('SPLIT CACHE / LocalStorage / flag set cache tests', () => {
206215
207216// if FlagSets are not defined, it should store all FlagSets in memory.
208217test ( 'SPLIT CACHE / LocalStorage / flag set cache tests without filters' , ( ) => {
209- const cacheWithoutFilters = new SplitsCacheInLocal ( fullSettings , new KeyBuilderCS ( 'SPLITIO' , 'user' ) ) ;
218+ const cache = new SplitsCacheInLocal ( fullSettings , new KeyBuilderCS ( 'SPLITIO' , 'user' ) ) ;
219+ cache . validateCache ( ) ;
220+
210221 const emptySet = new Set ( [ ] ) ;
211222
212- cacheWithoutFilters . addSplits ( [
223+ cache . addSplits ( [
213224 [ featureFlagOne . name , featureFlagOne ] ,
214225 [ featureFlagTwo . name , featureFlagTwo ] ,
215226 [ featureFlagThree . name , featureFlagThree ] ,
216227 ] ) ;
217- cacheWithoutFilters . addSplit ( featureFlagWithEmptyFS . name , featureFlagWithEmptyFS ) ;
228+ cache . addSplit ( featureFlagWithEmptyFS . name , featureFlagWithEmptyFS ) ;
218229
219- expect ( cacheWithoutFilters . getNamesByFlagSets ( [ 'o' ] ) ) . toEqual ( [ new Set ( [ 'ff_one' , 'ff_two' ] ) ] ) ;
220- expect ( cacheWithoutFilters . getNamesByFlagSets ( [ 'n' ] ) ) . toEqual ( [ new Set ( [ 'ff_one' ] ) ] ) ;
221- expect ( cacheWithoutFilters . getNamesByFlagSets ( [ 'e' ] ) ) . toEqual ( [ new Set ( [ 'ff_one' , 'ff_three' ] ) ] ) ;
222- expect ( cacheWithoutFilters . getNamesByFlagSets ( [ 't' ] ) ) . toEqual ( [ new Set ( [ 'ff_two' , 'ff_three' ] ) ] ) ;
223- expect ( cacheWithoutFilters . getNamesByFlagSets ( [ 'y' ] ) ) . toEqual ( [ emptySet ] ) ;
224- expect ( cacheWithoutFilters . getNamesByFlagSets ( [ 'o' , 'n' , 'e' ] ) ) . toEqual ( [ new Set ( [ 'ff_one' , 'ff_two' ] ) , new Set ( [ 'ff_one' ] ) , new Set ( [ 'ff_one' , 'ff_three' ] ) ] ) ;
230+ expect ( cache . getNamesByFlagSets ( [ 'o' ] ) ) . toEqual ( [ new Set ( [ 'ff_one' , 'ff_two' ] ) ] ) ;
231+ expect ( cache . getNamesByFlagSets ( [ 'n' ] ) ) . toEqual ( [ new Set ( [ 'ff_one' ] ) ] ) ;
232+ expect ( cache . getNamesByFlagSets ( [ 'e' ] ) ) . toEqual ( [ new Set ( [ 'ff_one' , 'ff_three' ] ) ] ) ;
233+ expect ( cache . getNamesByFlagSets ( [ 't' ] ) ) . toEqual ( [ new Set ( [ 'ff_two' , 'ff_three' ] ) ] ) ;
234+ expect ( cache . getNamesByFlagSets ( [ 'y' ] ) ) . toEqual ( [ emptySet ] ) ;
235+ expect ( cache . getNamesByFlagSets ( [ 'o' , 'n' , 'e' ] ) ) . toEqual ( [ new Set ( [ 'ff_one' , 'ff_two' ] ) , new Set ( [ 'ff_one' ] ) , new Set ( [ 'ff_one' , 'ff_three' ] ) ] ) ;
225236
226237 // Validate that the feature flag cache is cleared when calling `clear` method
227- cacheWithoutFilters . clear ( ) ;
238+ cache . clear ( ) ;
228239 expect ( localStorage . length ) . toBe ( 1 ) ; // only 'SPLITIO.hash' should remain in localStorage
229240 expect ( localStorage . key ( 0 ) ) . toBe ( 'SPLITIO.hash' ) ;
230241} ) ;
0 commit comments