@@ -742,31 +742,6 @@ describe('ParseUser', () => {
742742 spy . mockRestore ( ) ;
743743 } ) ;
744744
745- it ( 'can pass sessionToken on save' , async ( ) => {
746- ParseUser . enableUnsafeCurrentUser ( ) ;
747- ParseUser . _clearCache ( ) ;
748- CoreManager . setRESTController ( {
749- request ( ) {
750- return Promise . resolve ( {
751- objectId : 'uid5' ,
752- sessionToken : 'r:123abc' ,
753- authData : {
754- anonymous : {
755- id : 'anonymousId' ,
756- }
757- }
758- } , 200 ) ;
759- } ,
760- ajax ( ) { }
761- } ) ;
762- const user = await AnonymousUtils . logIn ( ) ;
763- user . set ( 'field' , 'hello' ) ;
764- jest . spyOn ( user , 'getSessionToken' ) ;
765-
766- await user . save ( ) ;
767- expect ( user . getSessionToken ) . toHaveBeenCalledTimes ( 2 ) ;
768- } ) ;
769-
770745 it ( 'can destroy anonymous user on logout' , async ( ) => {
771746 ParseUser . enableUnsafeCurrentUser ( ) ;
772747 ParseUser . _clearCache ( ) ;
@@ -792,6 +767,31 @@ describe('ParseUser', () => {
792767 expect ( user . destroy ) . toHaveBeenCalledTimes ( 1 ) ;
793768 } ) ;
794769
770+ it ( 'can unlink' , async ( ) => {
771+ const provider = AnonymousUtils . _getAuthProvider ( ) ;
772+ ParseUser . _registerAuthenticationProvider ( provider ) ;
773+ const user = new ParseUser ( ) ;
774+ jest . spyOn ( user , '_linkWith' ) ;
775+ user . _unlinkFrom ( provider ) ;
776+ expect ( user . _linkWith ) . toHaveBeenCalledTimes ( 1 ) ;
777+ expect ( user . _linkWith ) . toHaveBeenCalledWith ( provider , { authData : null } , undefined ) ;
778+ } ) ;
779+
780+ it ( 'can unlink with options' , async ( ) => {
781+ const provider = AnonymousUtils . _getAuthProvider ( ) ;
782+ ParseUser . _registerAuthenticationProvider ( provider ) ;
783+ const user = new ParseUser ( ) ;
784+ jest . spyOn ( user , '_linkWith' )
785+ . mockImplementationOnce ( ( authProvider , authData , saveOptions ) => {
786+ expect ( authProvider ) . toEqual ( provider ) ;
787+ expect ( authData ) . toEqual ( { authData : null } ) ;
788+ expect ( saveOptions ) . toEqual ( { useMasterKey : true } ) ;
789+ return Promise . resolve ( ) ;
790+ } ) ;
791+ user . _unlinkFrom ( provider . getAuthType ( ) , { useMasterKey : true } ) ;
792+ expect ( user . _linkWith ) . toHaveBeenCalledTimes ( 1 ) ;
793+ } ) ;
794+
795795 it ( 'can destroy anonymous user when login new user' , async ( ) => {
796796 ParseUser . enableUnsafeCurrentUser ( ) ;
797797 ParseUser . _clearCache ( ) ;
@@ -876,4 +876,44 @@ describe('ParseUser', () => {
876876 done ( ) ;
877877 } ) ;
878878 } ) ;
879+
880+ it ( 'can linkWith options' , async ( ) => {
881+ ParseUser . _clearCache ( ) ;
882+ CoreManager . setRESTController ( {
883+ request ( method , path , body , options ) {
884+ expect ( options ) . toEqual ( { useMasterKey : true } ) ;
885+ return Promise . resolve ( {
886+ objectId : 'uid5' ,
887+ sessionToken : 'r:123abc' ,
888+ authData : {
889+ test : {
890+ id : 'id' ,
891+ access_token : 'access_token'
892+ }
893+ }
894+ } , 200 ) ;
895+ } ,
896+ ajax ( ) { }
897+ } ) ;
898+ const provider = {
899+ authenticate ( options ) {
900+ if ( options . success ) {
901+ options . success ( this , {
902+ id : 'id' ,
903+ access_token : 'access_token'
904+ } ) ;
905+ }
906+ } ,
907+ restoreAuthentication ( ) { } ,
908+ getAuthType ( ) {
909+ return 'test' ;
910+ } ,
911+ deauthenticate ( ) { }
912+ } ;
913+
914+ const user = new ParseUser ( ) ;
915+ await user . _linkWith ( provider , null , { useMasterKey : true } ) ;
916+
917+ expect ( user . get ( 'authData' ) ) . toEqual ( { test : { id : 'id' , access_token : 'access_token' } } ) ;
918+ } ) ;
879919} ) ;
0 commit comments