@@ -954,6 +954,47 @@ testCookieAndLocalStorage(() => {
954954 expect ( xhrMock . abort ) . toHaveBeenCalledTimes ( 1 ) ;
955955 } ) ;
956956 } ) ;
957+
958+ describe ( 'disconnect()' , ( ) => {
959+ test ( 'should clear cookie' , ( ) => {
960+ setUid2 ( makeIdentityV2 ( ) , useCookie ) ;
961+ uid2 . disconnect ( ) ;
962+ expect ( getUid2 ( useCookie ) ) . toBeNull ( ) ;
963+ } ) ;
964+ test ( 'should abort refresh timer' , ( ) => {
965+ uid2 . init ( {
966+ callback : callback ,
967+ identity : makeIdentityV2 ( ) ,
968+ useCookie : useCookie ,
969+ } ) ;
970+ expect ( setTimeout ) . toHaveBeenCalledTimes ( 1 ) ;
971+ expect ( clearTimeout ) . not . toHaveBeenCalled ( ) ;
972+ uid2 . disconnect ( ) ;
973+ expect ( setTimeout ) . toHaveBeenCalledTimes ( 1 ) ;
974+ expect ( clearTimeout ) . toHaveBeenCalledTimes ( 1 ) ;
975+ } ) ;
976+ test ( 'should abort refresh token request' , ( ) => {
977+ uid2 . init ( {
978+ callback : callback ,
979+ identity : makeIdentityV2 ( { refresh_from : Date . now ( ) - 100000 } ) ,
980+ useCookie : useCookie ,
981+ } ) ;
982+ expect ( xhrMock . send ) . toHaveBeenCalledTimes ( 1 ) ;
983+ expect ( xhrMock . abort ) . not . toHaveBeenCalled ( ) ;
984+ uid2 . disconnect ( ) ;
985+ expect ( xhrMock . send ) . toHaveBeenCalledTimes ( 1 ) ;
986+ expect ( xhrMock . abort ) . toHaveBeenCalledTimes ( 1 ) ;
987+ } ) ;
988+ test ( 'should switch to unavailable state' , ( ) => {
989+ uid2 . init ( {
990+ callback : callback ,
991+ identity : makeIdentityV2 ( ) ,
992+ useCookie : useCookie ,
993+ } ) ;
994+ uid2 . disconnect ( ) ;
995+ ( expect ( uid2 ) as any ) . toBeInUnavailableState ( ) ;
996+ } ) ;
997+ } ) ;
957998} ) ;
958999
9591000describe ( 'Include sdk script multiple times' , ( ) => {
0 commit comments