@@ -571,28 +571,29 @@ describe('calls the NoIdentityAvailable event', () => {
571
571
572
572
test ( 'when init is called for the first time with no identity' , ( ) => {
573
573
uid2 . init ( { } ) ;
574
+
574
575
expect ( handler ) . toHaveBeenLastCalledWith ( EventType . NoIdentityAvailable , { identity : null } ) ;
575
576
} ) ;
576
577
test ( 'when init is already complete and called again with no identity' , ( ) => {
577
578
uid2 . init ( { } ) ;
578
579
uid2 . init ( { } ) ;
580
+
579
581
expect ( handler ) . toHaveBeenLastCalledWith ( EventType . NoIdentityAvailable , { identity : null } ) ;
580
582
} ) ;
581
583
test ( 'when init is already complete and called again with an expired identity' , ( ) => {
582
584
uid2 . init ( { } ) ;
583
- expect ( handler ) . toHaveBeenLastCalledWith ( EventType . NoIdentityAvailable , { identity : null } ) ;
584
-
585
585
uid2 . init ( {
586
586
identity : expiredIdentity ,
587
587
} ) ;
588
+
588
589
expect ( handler ) . toHaveBeenLastCalledWith ( EventType . NoIdentityAvailable , { identity : null } ) ;
589
590
} ) ;
590
591
test ( 'when init is already complete but the existing identity is expired' , ( ) => {
591
592
uid2 . init ( {
592
593
identity : expiredIdentity ,
593
594
} ) ;
594
- expect ( handler ) . toHaveBeenLastCalledWith ( EventType . NoIdentityAvailable , { identity : null } ) ;
595
595
uid2 . init ( { } ) ;
596
+
596
597
expect ( handler ) . toHaveBeenLastCalledWith ( EventType . NoIdentityAvailable , { identity : null } ) ;
597
598
} ) ;
598
599
test ( 'when identity is expired but refreshable' , ( ) => {
@@ -611,9 +612,8 @@ describe('calls the NoIdentityAvailable event', () => {
611
612
expect ( handler ) . toHaveBeenLastCalledWith ( EventType . NoIdentityAvailable , { identity : null } ) ;
612
613
} ) ;
613
614
test ( 'when get identity returns null or get advertising token returns undefined' , ( ) => {
614
- const nullIdentity = uid2 . getIdentity ( ) ;
615
+ uid2 . getIdentity ( ) ;
615
616
616
- expect ( nullIdentity ) . toBeNull ( ) ;
617
617
expect ( handler ) . toHaveBeenLastCalledWith ( EventType . NoIdentityAvailable , { identity : null } ) ;
618
618
} ) ;
619
619
test ( 'when there is no advertising token' , ( ) => {
@@ -624,29 +624,19 @@ describe('calls the NoIdentityAvailable event', () => {
624
624
} ) ;
625
625
test ( 'when cstg does not succeed' , ( ) => {
626
626
uid2 . init ( { } ) ;
627
- expect ( uid2 . setIdentityFromEmail ( 'a' , mocks . makeUid2CstgOption ( ) ) ) . rejects . toThrow (
628
- 'Invalid email address'
629
- ) ;
630
627
631
- expect ( handler ) . toHaveBeenLastCalledWith ( EventType . NoIdentityAvailable , { identity : null } ) ;
632
- } ) ;
633
- test ( 'when an identity was valid but has since expired' , ( ) => {
634
- uid2 . init ( { } ) ;
635
628
expect ( uid2 . setIdentityFromEmail ( 'a' , mocks . makeUid2CstgOption ( ) ) ) . rejects . toThrow (
636
629
'Invalid email address'
637
630
) ;
638
-
639
631
expect ( handler ) . toHaveBeenLastCalledWith ( EventType . NoIdentityAvailable , { identity : null } ) ;
640
632
} ) ;
641
633
test ( 'when identity was valid on init but has since expired' , ( ) => {
642
- const refreshFrom = Date . now ( ) + 100 ;
643
634
const originalIdentity = makeIdentity ( {
644
635
advertising_token : 'original_advertising_token' ,
645
- identity_expires : refreshFrom ,
646
- //refresh_from: refreshFrom,
636
+ identity_expires : Date . now ( ) + 100 ,
647
637
} ) ;
648
-
649
638
uid2 . init ( { identity : originalIdentity } ) ;
639
+
650
640
expect ( handler ) . not . toHaveBeenLastCalledWith ( EventType . NoIdentityAvailable , { identity : null } ) ;
651
641
652
642
// set time to an expired date for this identity
@@ -669,6 +659,7 @@ describe('does not call NoIdentityAvailable event', () => {
669
659
test ( 'when setIdentity is run with a valid identity, should not call NoIdentityAvailable on set or get' , ( ) => {
670
660
uid2 . init ( { } ) ;
671
661
handler = jest . fn ( ) ;
662
+
672
663
uid2 . setIdentity ( validIdentity ) ;
673
664
expect ( handler ) . not . toHaveBeenLastCalledWith ( EventType . NoIdentityAvailable , { identity : null } ) ;
674
665
@@ -682,15 +673,16 @@ describe('does not call NoIdentityAvailable event', () => {
682
673
uid2 . init ( { } ) ;
683
674
let optedOutIdentity = makeIdentity ( { status : 'optout' } ) ;
684
675
uid2 . setIdentity ( optedOutIdentity ) ;
676
+
685
677
expect ( handler ) . not . toHaveBeenLastCalledWith ( EventType . NoIdentityAvailable , { identity : null } ) ;
686
678
} ) ;
687
679
test ( 'when cstg is successful' , async ( ) => {
688
680
uid2 . init ( { } ) ;
689
681
handler = jest . fn ( ) ;
682
+
690
683
expect ( async ( ) => {
691
684
await uid2 . setIdentityFromEmail ( 'test@test.com' , mocks . makeUid2CstgOption ( ) ) ;
692
685
} ) . not . toThrow ( ) ;
693
-
694
686
expect ( handler ) . not . toHaveBeenLastCalledWith ( EventType . NoIdentityAvailable , { identity : null } ) ;
695
687
} ) ;
696
688
test ( 'when identity is set with local storage and init has never been' , ( ) => {
0 commit comments