@@ -289,7 +289,7 @@ describe('DefaultOdpManager', () => {
289
289
290
290
it ( 'fetches qualified segments correctly for both fs_user_id and vuid from segmentManager' , async ( ) => {
291
291
const segmentManager = getMockOdpSegmentManager ( ) ;
292
- segmentManager . fetchQualifiedSegments . mockImplementation ( ( key : ODP_USER_KEY , ... arg ) => {
292
+ segmentManager . fetchQualifiedSegments . mockImplementation ( ( key : ODP_USER_KEY ) => {
293
293
if ( key === ODP_USER_KEY . FS_USER_ID ) {
294
294
return Promise . resolve ( [ 'fs1' , 'fs2' ] ) ;
295
295
}
@@ -567,180 +567,70 @@ describe('DefaultOdpManager', () => {
567
567
expect ( data . get ( 'device_type' ) ) . toEqual ( 'phone' ) ;
568
568
expect ( data . get ( 'model' ) ) . toEqual ( 'model' ) ;
569
569
} ) ;
570
-
571
- // it('should call eventManager.identifyUser with correct parameters when identifyUser is called', async () => {
572
- // const odpIntegrationConfig: OdpIntegratedConfig = {
573
- // integrated: true,
574
- // odpConfig: new OdpConfig(keyA, hostA, pixelA, segmentsA)
575
- // };
576
-
577
- // const odpManager = testOdpManager({
578
- // odpIntegrationConfig,
579
- // segmentManager,
580
- // eventManager,
581
- // logger,
582
- // vuidEnabled: true,
583
- // });
584
-
585
- // await odpManager.onReady();
586
-
587
- // const userId = 'user123';
588
- // const vuid = 'vuid_123';
589
-
590
- // odpManager.identifyUser(userId, vuid);
591
- // const [userIdArg, vuidArg] = capture(mockEventManager.identifyUser).byCallIndex(0);
592
- // expect(userIdArg).toEqual(userId);
593
- // expect(vuidArg).toEqual(vuid);
594
-
595
- // odpManager.identifyUser(userId);
596
- // const [userIdArg2, vuidArg2] = capture(mockEventManager.identifyUser).byCallIndex(1);
597
- // expect(userIdArg2).toEqual(userId);
598
- // expect(vuidArg2).toEqual(undefined);
599
-
600
- // odpManager.identifyUser(vuid);
601
- // const [userIdArg3, vuidArg3] = capture(mockEventManager.identifyUser).byCallIndex(2);
602
- // expect(userIdArg3).toEqual(undefined);
603
- // expect(vuidArg3).toEqual(vuid);
604
- // });
605
-
606
- // it('should send event with correct parameters', async () => {
607
- // const odpIntegrationConfig: OdpIntegratedConfig = {
608
- // integrated: true,
609
- // odpConfig: new OdpConfig(keyA, hostA, pixelA, segmentsA)
610
- // };
611
-
612
- // const odpManager = testOdpManager({
613
- // odpIntegrationConfig,
614
- // segmentManager,
615
- // eventManager,
616
- // logger,
617
- // vuidEnabled: true,
618
- // });
619
-
620
- // await odpManager.onReady();
621
-
622
- // const identifiers = new Map([['email', '[email protected] ']]);
623
- // const data = new Map([['key1', 'value1'], ['key2', 'value2']]);
624
-
625
- // odpManager.sendEvent({
626
- // action: 'action',
627
- // type: 'type',
628
- // identifiers,
629
- // data,
630
- // });
631
-
632
- // const [event] = capture(mockEventManager.sendEvent).byCallIndex(0);
633
- // expect(event.action).toEqual('action');
634
- // expect(event.type).toEqual('type');
635
- // expect(event.identifiers).toEqual(identifiers);
636
- // expect(event.data).toEqual(data);
637
-
638
- // // should use `fullstack` as type if empty string is provided
639
- // odpManager.sendEvent({
640
- // type: '',
641
- // action: 'action',
642
- // identifiers,
643
- // data,
644
- // });
645
570
646
- // const [event2] = capture(mockEventManager.sendEvent).byCallIndex(1);
647
- // expect(event2.action).toEqual('action');
648
- // expect(event2.type).toEqual('fullstack');
649
- // expect(event2.identifiers).toEqual(identifiers);
650
- // });
651
-
652
-
653
- // it('should throw an error if event action is empty string and not call eventManager', async () => {
654
- // const odpIntegrationConfig: OdpIntegratedConfig = {
655
- // integrated: true,
656
- // odpConfig: new OdpConfig(keyA, hostA, pixelA, segmentsA)
657
- // };
658
-
659
- // const odpManager = testOdpManager({
660
- // odpIntegrationConfig,
661
- // segmentManager,
662
- // eventManager,
663
- // logger,
664
- // vuidEnabled: true,
665
- // });
666
-
667
- // await odpManager.onReady();
668
-
669
- // const identifiers = new Map([['email', '[email protected] ']]);
670
- // const data = new Map([['key1', 'value1'], ['key2', 'value2']]);
671
-
672
- // const sendEvent = () => odpManager.sendEvent({
673
- // action: '',
674
- // type: 'type',
675
- // identifiers,
676
- // data,
677
- // });
571
+ it ( 'sends identified event with both fs_user_id and vuid if both parameters are provided' , async ( ) => {
572
+ const eventManager = getMockOdpEventManager ( ) ;
573
+ eventManager . onRunning . mockReturnValue ( Promise . resolve ( ) ) ;
678
574
679
- // expect(sendEvent).toThrow('ODP action is not valid');
680
- // verify(mockEventManager.sendEvent(anything())).never();
681
- // });
575
+ const mockSendEvents = vi . mocked ( eventManager . sendEvent as OdpEventManager [ 'sendEvent' ] ) ;
682
576
683
- // it('should throw an error if event data is invalid', async () => {
684
- // const odpIntegrationConfig: OdpIntegratedConfig = {
685
- // integrated: true,
686
- // odpConfig: new OdpConfig(keyA, hostA, pixelA, segmentsA)
687
- // };
577
+ const odpManager = new DefaultOdpManager ( {
578
+ segmentManager : getMockOdpSegmentManager ( ) ,
579
+ eventManager,
580
+ } ) ;
688
581
689
- // const odpManager = testOdpManager({
690
- // odpIntegrationConfig,
691
- // segmentManager,
692
- // eventManager,
693
- // logger,
694
- // vuidEnabled: true,
695
- // });
582
+ odpManager . start ( ) ;
583
+ odpManager . updateConfig ( { integrated : true , odpConfig : config } ) ;
584
+ await odpManager . onRunning ( ) ;
696
585
697
- // await odpManager.onReady();
586
+ odpManager . identifyUser ( 'user' , 'vuid_a' ) ;
587
+ expect ( mockSendEvents ) . toHaveBeenCalledOnce ( ) ;
588
+ const { identifiers } = mockSendEvents . mock . calls [ 0 ] [ 0 ] ;
589
+ expect ( identifiers ) . toEqual ( new Map ( [ [ 'fs_user_id' , 'user' ] , [ 'vuid' , 'vuid_a' ] ] ) ) ;
590
+ } ) ;
698
591
699
- // const identifiers = new Map([['email', '[email protected] ']]);
700
- // const data = new Map([['key1', {}]]);
592
+ it ( 'sends identified event when called with just fs_user_id in first parameter' , async ( ) => {
593
+ const eventManager = getMockOdpEventManager ( ) ;
594
+ eventManager . onRunning . mockReturnValue ( Promise . resolve ( ) ) ;
701
595
702
- // const sendEvent = () => odpManager.sendEvent({
703
- // action: 'action',
704
- // type: 'type',
705
- // identifiers,
706
- // data,
707
- // });
596
+ const mockSendEvents = vi . mocked ( eventManager . sendEvent as OdpEventManager [ 'sendEvent' ] ) ;
708
597
709
- // expect(sendEvent).toThrow(ERROR_MESSAGES.ODP_INVALID_DATA);
710
- // verify(mockEventManager.sendEvent(anything())).never();
711
- // });
598
+ const odpManager = new DefaultOdpManager ( {
599
+ segmentManager : getMockOdpSegmentManager ( ) ,
600
+ eventManager,
601
+ } ) ;
712
602
713
- // it('should fetch qualified segments correctly for both fs_user_id and vuid', async () => {
714
- // const userId = 'user123' ;
715
- // const vuid = 'vuid_123' ;
603
+ odpManager . start ( ) ;
604
+ odpManager . updateConfig ( { integrated : true , odpConfig : config } ) ;
605
+ await odpManager . onRunning ( ) ;
716
606
717
- // when(mockSegmentManager.fetchQualifiedSegments(ODP_USER_KEY.FS_USER_ID, userId, anything()))
718
- // .thenResolve(['fs1', 'fs2']);
607
+ odpManager . identifyUser ( 'user' ) ;
608
+ expect ( mockSendEvents ) . toHaveBeenCalledOnce ( ) ;
609
+ const { identifiers } = mockSendEvents . mock . calls [ 0 ] [ 0 ] ;
610
+ expect ( identifiers ) . toEqual ( new Map ( [ [ 'fs_user_id' , 'user' ] ] ) ) ;
611
+ } ) ;
719
612
720
- // when(mockSegmentManager.fetchQualifiedSegments(ODP_USER_KEY.VUID, vuid, anything()))
721
- // .thenResolve(['vuid1', 'vuid2']);
613
+ it ( 'sends identified event when called with just vuid in first parameter' , async ( ) => {
614
+ const eventManager = getMockOdpEventManager ( ) ;
615
+ eventManager . onRunning . mockReturnValue ( Promise . resolve ( ) ) ;
722
616
723
- // const odpIntegrationConfig: OdpIntegratedConfig = {
724
- // integrated: true,
725
- // odpConfig: new OdpConfig(keyA, hostA, pixelA, segmentsA)
726
- // };
617
+ const mockSendEvents = vi . mocked ( eventManager . sendEvent as OdpEventManager [ 'sendEvent' ] ) ;
727
618
728
- // const odpManager = testOdpManager({
729
- // odpIntegrationConfig,
730
- // segmentManager: instance(mockSegmentManager),
731
- // eventManager,
732
- // logger,
733
- // vuidEnabled: true,
734
- // });
619
+ const odpManager = new DefaultOdpManager ( {
620
+ segmentManager : getMockOdpSegmentManager ( ) ,
621
+ eventManager,
622
+ } ) ;
735
623
736
- // await odpManager.onReady();
624
+ odpManager . start ( ) ;
625
+ odpManager . updateConfig ( { integrated : true , odpConfig : config } ) ;
626
+ await odpManager . onRunning ( ) ;
737
627
738
- // const fsSegments = await odpManager.fetchQualifiedSegments(userId);
739
- // expect(fsSegments).toEqual(['fs1', 'fs2']);
628
+ odpManager . identifyUser ( 'vuid_a' ) ;
629
+ expect ( mockSendEvents ) . toHaveBeenCalledOnce ( ) ;
630
+ const { identifiers } = mockSendEvents . mock . calls [ 0 ] [ 0 ] ;
631
+ expect ( identifiers ) . toEqual ( new Map ( [ [ 'vuid' , 'vuid_a' ] ] ) ) ;
632
+ } ) ;
740
633
741
- // const vuidSegments = await odpManager.fetchQualifiedSegments(vuid);
742
- // expect(vuidSegments).toEqual(['vuid1', 'vuid2']);
743
- // });
744
634
745
635
746
636
// it('should stop itself and eventManager if stop is called', async () => {
@@ -766,70 +656,5 @@ describe('DefaultOdpManager', () => {
766
656
// });
767
657
768
658
769
-
770
- // it('should drop relevant calls and log error when odpIntegrationConfig is not available', async () => {
771
- // const odpManager = testOdpManager({
772
- // odpIntegrationConfig: undefined,
773
- // segmentManager,
774
- // eventManager,
775
- // logger,
776
- // vuidEnabled: true,
777
- // });
778
-
779
- // const segments = await odpManager.fetchQualifiedSegments('vuid_user1', []);
780
- // verify(mockLogger.log(LogLevel.ERROR, ERROR_MESSAGES.ODP_CONFIG_NOT_AVAILABLE)).once();
781
- // expect(segments).toBeNull();
782
-
783
- // odpManager.identifyUser('vuid_user1');
784
- // verify(mockLogger.log(LogLevel.ERROR, ERROR_MESSAGES.ODP_CONFIG_NOT_AVAILABLE)).twice();
785
- // verify(mockEventManager.identifyUser(anything(), anything())).never();
786
-
787
- // const identifiers = new Map([['email', '[email protected] ']]);
788
- // const data = new Map([['key1', {}]]);
789
-
790
- // odpManager.sendEvent({
791
- // action: 'action',
792
- // type: 'type',
793
- // identifiers,
794
- // data,
795
- // });
796
-
797
- // verify(mockLogger.log(LogLevel.ERROR, ERROR_MESSAGES.ODP_CONFIG_NOT_AVAILABLE)).thrice();
798
- // verify(mockEventManager.sendEvent(anything())).never();
799
-
800
- // });
801
-
802
- // it('should drop relevant calls and log error when odp is not integrated', async () => {
803
- // const odpManager = testOdpManager({
804
- // odpIntegrationConfig: { integrated: false },
805
- // segmentManager,
806
- // eventManager,
807
- // logger,
808
- // vuidEnabled: true,
809
- // });
810
-
811
- // await odpManager.onReady();
812
-
813
- // const segments = await odpManager.fetchQualifiedSegments('vuid_user1', []);
814
- // verify(mockLogger.log(LogLevel.ERROR, ERROR_MESSAGES.ODP_NOT_INTEGRATED)).once();
815
- // expect(segments).toBeNull();
816
-
817
- // odpManager.identifyUser('vuid_user1');
818
- // verify(mockLogger.log(LogLevel.INFO, ERROR_MESSAGES.ODP_NOT_INTEGRATED)).once();
819
- // verify(mockEventManager.identifyUser(anything(), anything())).never();
820
-
821
- // const identifiers = new Map([['email', '[email protected] ']]);
822
- // const data = new Map([['key1', {}]]);
823
-
824
- // odpManager.sendEvent({
825
- // action: 'action',
826
- // type: 'type',
827
- // identifiers,
828
- // data,
829
- // });
830
-
831
- // verify(mockLogger.log(LogLevel.ERROR, ERROR_MESSAGES.ODP_NOT_INTEGRATED)).twice();
832
- // verify(mockEventManager.sendEvent(anything())).never();
833
- // });
834
659
} ) ;
835
660
0 commit comments