@@ -249,7 +249,8 @@ describe('Optimizely', () => {
249
249
let projectConfig : any ;
250
250
let optimizely : any ;
251
251
let decisionService : any ;
252
- let notificationSpy : any ;
252
+ let flagNotificationSpy : any ;
253
+ let activateNotificationSpy : any ;
253
254
let eventProcessor : any ;
254
255
255
256
beforeEach ( ( ) => {
@@ -282,10 +283,16 @@ describe('Optimizely', () => {
282
283
decisionService = optimizely . decisionService ;
283
284
284
285
// Setup notification spy
285
- notificationSpy = vi . fn ( ) ;
286
+ flagNotificationSpy = vi . fn ( ) ;
286
287
optimizely . notificationCenter . addNotificationListener (
287
288
NOTIFICATION_TYPES . DECISION ,
288
- notificationSpy
289
+ flagNotificationSpy
290
+ ) ;
291
+
292
+ activateNotificationSpy = vi . fn ( ) ;
293
+ optimizely . notificationCenter . addNotificationListener (
294
+ NOTIFICATION_TYPES . ACTIVATE ,
295
+ activateNotificationSpy
289
296
) ;
290
297
} ) ;
291
298
@@ -408,7 +415,7 @@ describe('Optimizely', () => {
408
415
expect ( decision . ruleKey ) . toBe ( 'holdout_test_key' ) ;
409
416
410
417
// Verify decision notification was sent
411
- expect ( notificationSpy ) . toHaveBeenCalledWith ( {
418
+ expect ( flagNotificationSpy ) . toHaveBeenCalledWith ( {
412
419
type : DECISION_NOTIFICATION_TYPES . FLAG ,
413
420
userId : 'test_user' ,
414
421
attributes : { country : 'US' } ,
@@ -422,6 +429,14 @@ describe('Optimizely', () => {
422
429
decisionEventDispatched : true ,
423
430
} ) ,
424
431
} ) ;
432
+
433
+ expect ( activateNotificationSpy ) . toHaveBeenCalledWith ( expect . objectContaining ( {
434
+ experiment : null ,
435
+ holdout : projectConfig . holdouts [ 0 ] ,
436
+ userId : 'test_user' ,
437
+ attributes : { country : 'US' } ,
438
+ variation : projectConfig . holdouts [ 0 ] . variations [ 0 ]
439
+ } ) ) ;
425
440
} ) ;
426
441
427
442
it ( 'should handle holdout with included flags' , async ( ) => {
@@ -455,7 +470,7 @@ describe('Optimizely', () => {
455
470
expect ( decision . variationKey ) . toBe ( 'holdout_variation_key' ) ;
456
471
457
472
// Verify notification shows holdout details
458
- expect ( notificationSpy ) . toHaveBeenCalledWith ( {
473
+ expect ( flagNotificationSpy ) . toHaveBeenCalledWith ( {
459
474
type : DECISION_NOTIFICATION_TYPES . FLAG ,
460
475
userId : 'test_user' ,
461
476
attributes : { country : 'US' } ,
@@ -465,6 +480,14 @@ describe('Optimizely', () => {
465
480
ruleKey : 'holdout_test_key' ,
466
481
} ) ,
467
482
} ) ;
483
+
484
+ expect ( activateNotificationSpy ) . toHaveBeenCalledWith ( expect . objectContaining ( {
485
+ experiment : null ,
486
+ holdout : modifiedHoldout ,
487
+ userId : 'test_user' ,
488
+ attributes : { country : 'US' } ,
489
+ variation : modifiedHoldout . variations [ 0 ]
490
+ } ) ) ;
468
491
} ) ;
469
492
470
493
it ( 'should handle holdout with excluded flags' , async ( ) => {
@@ -499,7 +522,7 @@ describe('Optimizely', () => {
499
522
expect ( decision . variationKey ) . toBe ( 'variation_3' ) ;
500
523
501
524
// Verify notification shows normal experiment details (not holdout)
502
- expect ( notificationSpy ) . toHaveBeenCalledWith ( {
525
+ expect ( flagNotificationSpy ) . toHaveBeenCalledWith ( {
503
526
type : DECISION_NOTIFICATION_TYPES . FLAG ,
504
527
userId : 'test_user' ,
505
528
attributes : { country : 'BD' , age : 80 } ,
@@ -509,6 +532,14 @@ describe('Optimizely', () => {
509
532
ruleKey : 'exp_3' ,
510
533
} ) ,
511
534
} ) ;
535
+
536
+ expect ( activateNotificationSpy ) . toHaveBeenCalledWith ( expect . objectContaining ( {
537
+ experiment : projectConfig . experimentKeyMap [ 'exp_3' ] ,
538
+ holdout : null ,
539
+ userId : 'test_user' ,
540
+ attributes : { country : 'BD' , age : 80 } ,
541
+ variation : projectConfig . variationIdMap [ '5003' ]
542
+ } ) ) ;
512
543
} ) ;
513
544
514
545
it ( 'should handle multiple holdouts with correct priority' , async ( ) => {
@@ -568,7 +599,7 @@ describe('Optimizely', () => {
568
599
expect ( decision . variationKey ) . toBe ( 'holdout_variation_key_2' ) ;
569
600
570
601
// Verify notification shows details of selected holdout
571
- expect ( notificationSpy ) . toHaveBeenCalledWith ( {
602
+ expect ( flagNotificationSpy ) . toHaveBeenCalledWith ( {
572
603
type : DECISION_NOTIFICATION_TYPES . FLAG ,
573
604
userId : 'test_user' ,
574
605
attributes : { country : 'US' } ,
@@ -578,6 +609,14 @@ describe('Optimizely', () => {
578
609
ruleKey : 'holdout_test_key_2' ,
579
610
} ) ,
580
611
} ) ;
612
+
613
+ expect ( activateNotificationSpy ) . toHaveBeenCalledWith ( expect . objectContaining ( {
614
+ experiment : null ,
615
+ holdout : holdout2 ,
616
+ userId : 'test_user' ,
617
+ attributes : { country : 'US' } ,
618
+ variation : holdout2 . variations [ 0 ]
619
+ } ) ) ;
581
620
} ) ;
582
621
583
622
it ( 'should respect sendFlagDecisions setting for holdout events - false' , async ( ) => {
@@ -744,7 +783,7 @@ describe('Optimizely', () => {
744
783
expect ( typeof decision . variables ) . toBe ( 'object' ) ;
745
784
746
785
// Verify notification includes variable information
747
- expect ( notificationSpy ) . toHaveBeenCalledWith ( {
786
+ expect ( flagNotificationSpy ) . toHaveBeenCalledWith ( {
748
787
type : DECISION_NOTIFICATION_TYPES . FLAG ,
749
788
userId : 'test_user' ,
750
789
attributes : { country : 'US' } ,
@@ -754,6 +793,14 @@ describe('Optimizely', () => {
754
793
enabled : false ,
755
794
} ) ,
756
795
} ) ;
796
+
797
+ expect ( activateNotificationSpy ) . toHaveBeenCalledWith ( expect . objectContaining ( {
798
+ experiment : null ,
799
+ holdout : projectConfig . holdouts [ 0 ] ,
800
+ userId : 'test_user' ,
801
+ attributes : { country : 'US' } ,
802
+ variation : projectConfig . holdouts [ 0 ] . variations [ 0 ]
803
+ } ) ) ;
757
804
} ) ;
758
805
759
806
it ( 'should handle disable decision event option for holdout' , async ( ) => {
0 commit comments