11import { SplitsCacheInLocal } from '../SplitsCacheInLocal' ;
22import { KeyBuilderCS } from '../../KeyBuilderCS' ;
3- import { loggerMock } from '../../../logger/__tests__/sdkLogger.mock' ;
43import { splitWithUserTT , splitWithAccountTT , splitWithAccountTTAndUsesSegments , something , somethingElse , featureFlagOne , featureFlagTwo , featureFlagThree , featureFlagWithEmptyFS , featureFlagWithoutFS } from '../../__tests__/testUtils' ;
54import { ISplit } from '../../../dtos/types' ;
65import { _Set } from '../../../utils/lang/sets' ;
6+ import { fullSettings } from '../../../utils/settingsValidation/__tests__/settings.mocks' ;
7+
78
89test ( 'SPLIT CACHE / LocalStorage' , ( ) => {
9- const cache = new SplitsCacheInLocal ( loggerMock , new KeyBuilderCS ( 'SPLITIO' , 'user' ) ) ;
10+ const cache = new SplitsCacheInLocal ( fullSettings , new KeyBuilderCS ( 'SPLITIO' , 'user' ) ) ;
1011
1112 cache . clear ( ) ;
1213
@@ -45,7 +46,7 @@ test('SPLIT CACHE / LocalStorage', () => {
4546} ) ;
4647
4748test ( 'SPLIT CACHE / LocalStorage / Get Keys' , ( ) => {
48- const cache = new SplitsCacheInLocal ( loggerMock , new KeyBuilderCS ( 'SPLITIO' , 'user' ) ) ;
49+ const cache = new SplitsCacheInLocal ( fullSettings , new KeyBuilderCS ( 'SPLITIO' , 'user' ) ) ;
4950
5051 cache . addSplit ( 'lol1' , something ) ;
5152 cache . addSplit ( 'lol2' , somethingElse ) ;
@@ -57,7 +58,7 @@ test('SPLIT CACHE / LocalStorage / Get Keys', () => {
5758} ) ;
5859
5960test ( 'SPLIT CACHE / LocalStorage / Add Splits' , ( ) => {
60- const cache = new SplitsCacheInLocal ( loggerMock , new KeyBuilderCS ( 'SPLITIO' , 'user' ) ) ;
61+ const cache = new SplitsCacheInLocal ( fullSettings , new KeyBuilderCS ( 'SPLITIO' , 'user' ) ) ;
6162
6263 cache . addSplits ( [
6364 [ 'lol1' , something ] ,
@@ -71,7 +72,7 @@ test('SPLIT CACHE / LocalStorage / Add Splits', () => {
7172} ) ;
7273
7374test ( 'SPLIT CACHE / LocalStorage / trafficTypeExists and ttcache tests' , ( ) => {
74- const cache = new SplitsCacheInLocal ( loggerMock , new KeyBuilderCS ( 'SPLITIO' , 'user' ) ) ;
75+ const cache = new SplitsCacheInLocal ( fullSettings , new KeyBuilderCS ( 'SPLITIO' , 'user' ) ) ;
7576
7677 cache . addSplits ( [ // loop of addSplit
7778 [ 'split1' , splitWithUserTT ] ,
@@ -109,7 +110,7 @@ test('SPLIT CACHE / LocalStorage / trafficTypeExists and ttcache tests', () => {
109110} ) ;
110111
111112test ( 'SPLIT CACHE / LocalStorage / killLocally' , ( ) => {
112- const cache = new SplitsCacheInLocal ( loggerMock , new KeyBuilderCS ( 'SPLITIO' , 'user' ) ) ;
113+ const cache = new SplitsCacheInLocal ( fullSettings , new KeyBuilderCS ( 'SPLITIO' , 'user' ) ) ;
113114 cache . addSplit ( 'lol1' , something ) ;
114115 cache . addSplit ( 'lol2' , somethingElse ) ;
115116 const initialChangeNumber = cache . getChangeNumber ( ) ;
@@ -141,7 +142,7 @@ test('SPLIT CACHE / LocalStorage / killLocally', () => {
141142} ) ;
142143
143144test ( 'SPLIT CACHE / LocalStorage / usesSegments' , ( ) => {
144- const cache = new SplitsCacheInLocal ( loggerMock , new KeyBuilderCS ( 'SPLITIO' , 'user' ) ) ;
145+ const cache = new SplitsCacheInLocal ( fullSettings , new KeyBuilderCS ( 'SPLITIO' , 'user' ) ) ;
145146
146147 expect ( cache . usesSegments ( ) ) . toBe ( true ) ; // true initially, until data is synchronized
147148 cache . setChangeNumber ( 1 ) ; // to indicate that data has been synced.
@@ -164,7 +165,15 @@ test('SPLIT CACHE / LocalStorage / usesSegments', () => {
164165
165166test ( 'SPLIT CACHE / LocalStorage / flag set cache tests' , ( ) => {
166167 // @ts -ignore
167- const cache = new SplitsCacheInLocal ( loggerMock , new KeyBuilderCS ( 'SPLITIO' , 'user' ) , undefined , { groupedFilters : { bySet : [ 'o' , 'n' , 'e' , 'x' ] } } ) ;
168+ const cache = new SplitsCacheInLocal ( {
169+ ...fullSettings ,
170+ sync : { // @ts -expect-error
171+ __splitFiltersValidation : {
172+ groupedFilters : { bySet : [ 'o' , 'n' , 'e' , 'x' ] , byName : [ ] , byPrefix : [ ] } ,
173+ queryString : '&sets=e,n,o,x' ,
174+ }
175+ }
176+ } , new KeyBuilderCS ( 'SPLITIO' , 'user' ) ) ;
168177 const emptySet = new _Set ( [ ] ) ;
169178
170179 cache . addSplits ( [
@@ -204,7 +213,7 @@ test('SPLIT CACHE / LocalStorage / flag set cache tests', () => {
204213
205214// if FlagSets are not defined, it should store all FlagSets in memory.
206215test ( 'SPLIT CACHE / LocalStorage / flag set cache tests without filters' , ( ) => {
207- const cacheWithoutFilters = new SplitsCacheInLocal ( loggerMock , new KeyBuilderCS ( 'SPLITIO' , 'user' ) ) ;
216+ const cacheWithoutFilters = new SplitsCacheInLocal ( fullSettings , new KeyBuilderCS ( 'SPLITIO' , 'user' ) ) ;
208217 const emptySet = new _Set ( [ ] ) ;
209218
210219 cacheWithoutFilters . addSplits ( [
@@ -221,9 +230,8 @@ test('SPLIT CACHE / LocalStorage / flag set cache tests without filters', () =>
221230 expect ( cacheWithoutFilters . getNamesByFlagSets ( [ 'y' ] ) ) . toEqual ( [ emptySet ] ) ;
222231 expect ( cacheWithoutFilters . getNamesByFlagSets ( [ 'o' , 'n' , 'e' ] ) ) . toEqual ( [ new _Set ( [ 'ff_one' , 'ff_two' ] ) , new _Set ( [ 'ff_one' ] ) , new _Set ( [ 'ff_one' , 'ff_three' ] ) ] ) ;
223232
224- // Validate that the cache is cleared when calling `clear` method
225- localStorage . setItem ( 'something' , 'something' ) ;
233+ // Validate that the feature flag cache is cleared when calling `clear` method
226234 cacheWithoutFilters . clear ( ) ;
227- expect ( localStorage . length ) . toBe ( 1 ) ; // only 'something ' should remain in localStorage
228- expect ( localStorage . getItem ( localStorage . key ( 0 ) ! ) ) . toBe ( 'something ' ) ;
235+ expect ( localStorage . length ) . toBe ( 1 ) ; // only 'SPLITIO.hash ' should remain in localStorage
236+ expect ( localStorage . key ( 0 ) ) . toBe ( 'SPLITIO.hash ' ) ;
229237} ) ;
0 commit comments