@@ -2,6 +2,7 @@ import { SplitFactory } from '../../';
22
33import splitChangesMock1 from '../mocks/splitchanges.since.-1.json' ;
44import splitChangesMock2 from '../mocks/splitchanges.since.1457552620999.json' ;
5+ import { alwaysOnSplitInverted } from '../browserSuites/ready-from-cache.spec' ;
56
67const readyTimeout = 0.1 ;
78
@@ -55,4 +56,62 @@ export default function (fetchMock, assert) {
5556 } ) ;
5657 } ) ;
5758
59+ assert . test ( t => { // Testing when we start with initial rollout plan data (is ready from cache immediately)
60+ const testUrls = {
61+ sdk : 'https://sdk.baseurl/readinessSuite2' ,
62+ events : 'https://events.baseurl/readinessSuite2'
63+ } ;
64+
65+ fetchMock . getOnce ( testUrls . sdk + '/splitChanges?s=1.3&since=25&rbSince=-1' , { status : 200 , body : { ff : { ...splitChangesMock1 . ff , s : 25 } } } ) ;
66+ fetchMock . getOnce ( testUrls . sdk + '/segmentChanges/employees?since=100' , { status : 200 , body : { name : 'employees' , added : [ ] , removed : [ ] , since : 100 , till : 100 } } ) ;
67+ fetchMock . getOnce ( testUrls . sdk + '/segmentChanges/splitters?since=-1' , { status : 200 , body : { name : 'splitters' , added : [ ] , removed : [ ] , since : - 1 , till : 100 } } ) ;
68+ fetchMock . getOnce ( testUrls . sdk + '/segmentChanges/splitters?since=100' , { status : 200 , body : { name : 'splitters' , added : [ ] , removed : [ ] , since : 100 , till : 100 } } ) ;
69+ fetchMock . getOnce ( testUrls . sdk + '/segmentChanges/developers?since=-1' , { status : 200 , body : { name : 'developers' , added : [ ] , removed : [ ] , since : - 1 , till : 100 } } ) ;
70+ fetchMock . getOnce ( testUrls . sdk + '/segmentChanges/developers?since=100' , { status : 200 , body : { name : 'developers' , added : [ ] , removed : [ ] , since : 100 , till : 100 } } ) ;
71+ fetchMock . postOnce ( testUrls . events + '/testImpressions/bulk' , 200 ) ;
72+ fetchMock . postOnce ( testUrls . events + '/testImpressions/count' , 200 ) ;
73+
74+ const splitio = SplitFactory ( {
75+ ...baseConfig ,
76+ urls : testUrls ,
77+ initialRolloutPlan : {
78+ splitChanges : {
79+ ff : {
80+ t : 25 ,
81+ d : [ JSON . parse ( alwaysOnSplitInverted ) ]
82+ }
83+ } ,
84+ segmentChanges : [ {
85+ name : 'employees' , added : [ 'emi@split.io' ] , removed : [ ] , till : 100
86+ } ]
87+ }
88+ } ) ;
89+
90+ const client = splitio . client ( ) ;
91+
92+ t . equal ( client . __getStatus ( ) . isReadyFromCache , true , 'Client is ready from cache' ) ;
93+
94+ t . equal ( client . getTreatment ( 'nicolas@split.io' , 'always_on' ) , 'off' , 'It should evaluate treatments with data from cache. Key not in segment' ) ;
95+ t . equal ( client . getTreatment ( 'emi@split.io' , 'always_on' ) , 'on' , 'It should evaluate treatments with data from cache. Key in segment' ) ;
96+
97+ client . on ( client . Event . SDK_READY_TIMED_OUT , ( ) => {
98+ t . fail ( 'It should not timeout in this scenario.' ) ;
99+ t . end ( ) ;
100+ } ) ;
101+
102+ client . on ( client . Event . SDK_READY_FROM_CACHE , ( ) => {
103+ t . fail ( 'SDK is ready from cache immediately. SDK_READY_FROM_CACHE not emitted.' ) ;
104+ t . end ( ) ;
105+ } ) ;
106+
107+ client . on ( client . Event . SDK_READY , ( ) => {
108+ t . equal ( client . getTreatment ( 'nicolas@split.io' , 'always_on' ) , 'on' , 'It should evaluate treatments with updated data after syncing with the cloud.' ) ;
109+ t . equal ( client . getTreatment ( 'emi@split.io' , 'always_on' ) , 'on' , 'It should evaluate treatments with updated data after syncing with the cloud.' ) ;
110+
111+ splitio . destroy ( ) . then ( ( ) => {
112+ t . end ( ) ;
113+ } ) ;
114+ } ) ;
115+ } ) ;
116+
58117}
0 commit comments