@@ -638,6 +638,46 @@ describe('calls the NoIdentityAvailable event', () => {
638638 identity : null ,
639639 } ) ;
640640 } ) ;
641+ test ( 'when cstg does not succeed' , ( ) => {
642+ uid2 . init ( { } ) ;
643+ expect ( uid2 . setIdentityFromEmail ( 'a' , mocks . makeUid2CstgOption ( ) ) ) . rejects . toThrow (
644+ 'Invalid email address'
645+ ) ;
646+
647+ expect ( handler ) . toHaveBeenLastCalledWith ( EventType . NoIdentityAvailable , {
648+ identity : null ,
649+ } ) ;
650+ } ) ;
651+ test ( 'when an identity was valid but has since expired' , ( ) => {
652+ uid2 . init ( { } ) ;
653+ expect ( uid2 . setIdentityFromEmail ( 'a' , mocks . makeUid2CstgOption ( ) ) ) . rejects . toThrow (
654+ 'Invalid email address'
655+ ) ;
656+
657+ expect ( handler ) . toHaveBeenLastCalledWith ( EventType . NoIdentityAvailable , {
658+ identity : null ,
659+ } ) ;
660+ } ) ;
661+ test ( 'when identity was valid on init but has since expired' , ( ) => {
662+ const refreshFrom = Date . now ( ) + 100 ;
663+ const originalIdentity = makeIdentity ( {
664+ advertising_token : 'original_advertising_token' ,
665+ identity_expires : refreshFrom ,
666+ //refresh_from: refreshFrom,
667+ } ) ;
668+
669+ uid2 . init ( { identity : originalIdentity } ) ;
670+ expect ( handler ) . not . toHaveBeenLastCalledWith ( EventType . NoIdentityAvailable , { identity : null } ) ;
671+
672+ // set time to an expired date for this identity
673+ jest . setSystemTime ( originalIdentity . refresh_expires * 1000 + 1 ) ;
674+
675+ uid2 . isIdentityAvailable ( ) ;
676+
677+ expect ( handler ) . toHaveBeenLastCalledWith ( EventType . NoIdentityAvailable , {
678+ identity : originalIdentity ,
679+ } ) ;
680+ } ) ;
641681} ) ;
642682
643683describe ( 'does not call NoIdentityAvailable event' , ( ) => {
@@ -674,4 +714,15 @@ describe('does not call NoIdentityAvailable event', () => {
674714 identity : null ,
675715 } ) ;
676716 } ) ;
717+ test ( 'when cstg is successful' , async ( ) => {
718+ uid2 . init ( { } ) ;
719+ handler = jest . fn ( ) ;
720+ expect ( async ( ) => {
721+ await uid2 . setIdentityFromEmail ( '[email protected] ' , mocks . makeUid2CstgOption ( ) ) ; 722+ } ) . not . toThrow ( ) ;
723+
724+ expect ( handler ) . not . toHaveBeenLastCalledWith ( EventType . NoIdentityAvailable , {
725+ identity : null ,
726+ } ) ;
727+ } ) ;
677728} ) ;
0 commit comments