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