@@ -158,7 +158,7 @@ describe('LDClient', () => {
158
158
requests [ 0 ] . respond ( 404 ) ;
159
159
} ) ;
160
160
161
- it ( 'should not fetch flag settings since bootstrap is provided' , ( ) => {
161
+ it ( 'should not fetch flag settings if bootstrap is provided' , ( ) => {
162
162
LDClient . initialize ( envName , user , {
163
163
bootstrap : { } ,
164
164
} ) ;
@@ -167,6 +167,38 @@ describe('LDClient', () => {
167
167
expect ( / s d k \/ e v a l / . test ( settingsRequest . url ) ) . toEqual ( false ) ;
168
168
} ) ;
169
169
170
+ it ( 'sets flag values from bootstrap object with old format' , ( ) => {
171
+ const client = LDClient . initialize ( envName , user , {
172
+ bootstrap : { foo : 'bar' } ,
173
+ } ) ;
174
+
175
+ expect ( client . variation ( 'foo' ) ) . toEqual ( 'bar' ) ;
176
+ } ) ;
177
+
178
+ it ( 'logs warning when bootstrap object uses old format' , ( ) => {
179
+ LDClient . initialize ( envName , user , {
180
+ bootstrap : { foo : 'bar' } ,
181
+ } ) ;
182
+
183
+ expect ( warnSpy ) . toHaveBeenCalledWith ( messages . bootstrapOldFormat ( ) ) ;
184
+ } ) ;
185
+
186
+ it ( 'sets flag values from bootstrap object with new format' , ( ) => {
187
+ const client = LDClient . initialize ( envName , user , {
188
+ bootstrap : { foo : 'bar' , $flagsState : { foo : { version : 1 } } } ,
189
+ } ) ;
190
+
191
+ expect ( client . variation ( 'foo' ) ) . toEqual ( 'bar' ) ;
192
+ } ) ;
193
+
194
+ it ( 'does not log warning when bootstrap object uses new format' , ( ) => {
195
+ LDClient . initialize ( envName , user , {
196
+ bootstrap : { foo : 'bar' , $flagsState : { foo : { version : 1 } } } ,
197
+ } ) ;
198
+
199
+ expect ( warnSpy ) . not . toHaveBeenCalled ( ) ;
200
+ } ) ;
201
+
170
202
it ( 'should contain package version' , ( ) => {
171
203
// Arrange
172
204
const version = LDClient . version ;
@@ -420,13 +452,15 @@ describe('LDClient', () => {
420
452
expect ( e . user ) . toEqual ( user ) ;
421
453
}
422
454
423
- function expectFeatureEvent ( e , key , value , variation , version , defaultVal ) {
455
+ function expectFeatureEvent ( e , key , value , variation , version , defaultVal , trackEvents , debugEventsUntilDate ) {
424
456
expect ( e . kind ) . toEqual ( 'feature' ) ;
425
457
expect ( e . key ) . toEqual ( key ) ;
426
458
expect ( e . value ) . toEqual ( value ) ;
427
459
expect ( e . variation ) . toEqual ( variation ) ;
428
460
expect ( e . version ) . toEqual ( version ) ;
429
461
expect ( e . default ) . toEqual ( defaultVal ) ;
462
+ expect ( e . trackEvents ) . toEqual ( trackEvents ) ;
463
+ expect ( e . debugEventsUntilDate ) . toEqual ( debugEventsUntilDate ) ;
430
464
}
431
465
432
466
it ( 'sends an identify event at startup' , done => {
@@ -513,6 +547,32 @@ describe('LDClient', () => {
513
547
514
548
server . respond ( ) ;
515
549
} ) ;
550
+
551
+ it ( 'can get metadata for events from bootstrap object' , done => {
552
+ const ep = stubEventProcessor ( ) ;
553
+ const bootstrapData = {
554
+ foo : 'bar' ,
555
+ $flagsState : {
556
+ foo : {
557
+ variation : 1 ,
558
+ version : 2 ,
559
+ trackEvents : true ,
560
+ debugEventsUntilDate : 1000 ,
561
+ } ,
562
+ } ,
563
+ } ;
564
+ const client = LDClient . initialize ( envName , user , { eventProcessor : ep , bootstrap : bootstrapData } ) ;
565
+
566
+ client . on ( 'ready' , ( ) => {
567
+ client . variation ( 'foo' , 'x' ) ;
568
+
569
+ expect ( ep . events . length ) . toEqual ( 2 ) ;
570
+ expectIdentifyEvent ( ep . events [ 0 ] , user ) ;
571
+ expectFeatureEvent ( ep . events [ 1 ] , 'foo' , 'bar' , 1 , 2 , 'x' , true , 1000 ) ;
572
+
573
+ done ( ) ;
574
+ } ) ;
575
+ } ) ;
516
576
} ) ;
517
577
518
578
describe ( 'event listening' , ( ) => {
0 commit comments