@@ -4,34 +4,54 @@ import { fullSettings } from '../../utils/settingsValidation/__tests__/settings.
44import { loggerMock } from '../../logger/__tests__/sdkLogger.mock' ;
55import { IRBSegment , ISplit } from '../../dtos/types' ;
66
7- import { setRolloutPlan , getRolloutPlan } from '../dataLoader' ;
7+ import { validateRolloutPlan , setRolloutPlan , getRolloutPlan } from '../dataLoader' ;
8+
9+ const otherKey = 'otherKey' ;
10+ const expectedRolloutPlan = {
11+ splitChanges : {
12+ ff : { d : [ { name : 'split1' } ] , t : 123 , s : - 1 } ,
13+ rbs : { d : [ { name : 'rbs1' } ] , t : 321 , s : - 1 }
14+ } ,
15+ memberships : {
16+ [ fullSettings . core . key as string ] : { ms : { k : [ { n : 'segment1' } ] } , ls : { k : [ ] } } ,
17+ [ otherKey ] : { ms : { k : [ { n : 'segment1' } ] } , ls : { k : [ ] } }
18+ } ,
19+ segmentChanges : [ {
20+ name : 'segment1' ,
21+ added : [ fullSettings . core . key as string , otherKey ] ,
22+ removed : [ ] ,
23+ till : 123
24+ } ]
25+ } ;
26+
27+ describe ( 'validateRolloutPlan' , ( ) => {
28+ afterEach ( ( ) => {
29+ loggerMock . mockClear ( ) ;
30+ } ) ;
831
9- describe ( 'getRolloutPlan & setRolloutPlan (client-side)' , ( ) => {
10- const otherKey = 'otherKey' ;
32+ test ( 'valid rollout plan and mode' , ( ) => {
33+ expect ( validateRolloutPlan ( loggerMock , { mode : 'standalone' , initialRolloutPlan : expectedRolloutPlan } as any ) ) . toEqual ( expectedRolloutPlan ) ;
34+ expect ( loggerMock . error ) . not . toHaveBeenCalled ( ) ;
35+ } ) ;
36+
37+ test ( 'invalid rollout plan' , ( ) => {
38+ expect ( validateRolloutPlan ( loggerMock , { mode : 'standalone' , initialRolloutPlan : { } } as any ) ) . toBeUndefined ( ) ;
39+ expect ( loggerMock . error ) . toHaveBeenCalledWith ( 'storage: invalid rollout plan provided' ) ;
40+ } ) ;
1141
42+ test ( 'invalid mode' , ( ) => {
43+ expect ( validateRolloutPlan ( loggerMock , { mode : 'consumer' , initialRolloutPlan : expectedRolloutPlan } as any ) ) . toBeUndefined ( ) ;
44+ expect ( loggerMock . warn ) . toHaveBeenCalledWith ( 'storage: initial rollout plan is ignored in consumer mode' ) ;
45+ } ) ;
46+ } ) ;
47+
48+ describe ( 'getRolloutPlan & setRolloutPlan (client-side)' , ( ) => {
1249 // @ts -expect-error Load server-side storage
1350 const serverStorage = InMemoryStorageFactory ( { settings : fullSettings } ) ;
1451 serverStorage . splits . update ( [ { name : 'split1' } as ISplit ] , [ ] , 123 ) ;
1552 serverStorage . rbSegments . update ( [ { name : 'rbs1' } as IRBSegment ] , [ ] , 321 ) ;
1653 serverStorage . segments . update ( 'segment1' , [ fullSettings . core . key as string , otherKey ] , [ ] , 123 ) ;
1754
18- const expectedRolloutPlan = {
19- splitChanges : {
20- ff : { d : [ { name : 'split1' } ] , t : 123 , s : - 1 } ,
21- rbs : { d : [ { name : 'rbs1' } ] , t : 321 , s : - 1 }
22- } ,
23- memberships : {
24- [ fullSettings . core . key as string ] : { ms : { k : [ { n : 'segment1' } ] } , ls : { k : [ ] } } ,
25- [ otherKey ] : { ms : { k : [ { n : 'segment1' } ] } , ls : { k : [ ] } }
26- } ,
27- segmentChanges : [ {
28- name : 'segment1' ,
29- added : [ fullSettings . core . key as string , otherKey ] ,
30- removed : [ ] ,
31- till : 123
32- } ]
33- } ;
34-
3555 afterEach ( ( ) => {
3656 jest . clearAllMocks ( ) ;
3757 } ) ;
0 commit comments