@@ -326,7 +326,7 @@ it("redirectToLoginPage calls into the client", async () => {
326326 return < div > Finished</ div >
327327 }
328328 render (
329- < AuthProvider authUrl = { AUTH_URL } >
329+ < AuthProvider client = { mockClient } >
330330 < Component />
331331 </ AuthProvider >
332332 )
@@ -341,7 +341,7 @@ it("redirectToSignupPage calls into the client", async () => {
341341 return < div > Finished</ div >
342342 }
343343 render (
344- < AuthProvider authUrl = { AUTH_URL } >
344+ < AuthProvider client = { mockClient } >
345345 < Component />
346346 </ AuthProvider >
347347 )
@@ -356,7 +356,7 @@ it("redirectToCreateOrgPage calls into the client", async () => {
356356 return < div > Finished</ div >
357357 }
358358 render (
359- < AuthProvider authUrl = { AUTH_URL } >
359+ < AuthProvider client = { mockClient } >
360360 < Component />
361361 </ AuthProvider >
362362 )
@@ -371,7 +371,7 @@ it("redirectToAccountPage calls into the client", async () => {
371371 return < div > Finished</ div >
372372 }
373373 render (
374- < AuthProvider authUrl = { AUTH_URL } >
374+ < AuthProvider client = { mockClient } >
375375 < Component />
376376 </ AuthProvider >
377377 )
@@ -386,7 +386,7 @@ it("redirectToOrgPage calls into the client", async () => {
386386 return < div > Finished</ div >
387387 }
388388 render (
389- < AuthProvider authUrl = { AUTH_URL } >
389+ < AuthProvider client = { mockClient } >
390390 < Component />
391391 </ AuthProvider >
392392 )
@@ -401,14 +401,49 @@ it("logout calls into the client", async () => {
401401 return < div > Finished</ div >
402402 }
403403 render (
404- < AuthProvider authUrl = { AUTH_URL } >
404+ < AuthProvider client = { mockClient } >
405405 < Component />
406406 </ AuthProvider >
407407 )
408408 await waitFor ( ( ) => screen . getByText ( "Finished" ) )
409409 expect ( mockClient . logout ) . toBeCalled ( )
410410} )
411411
412+ it ( "external client is not destroyed on unmount" , async ( ) => {
413+ const { unmount } = render (
414+ < AuthProvider client = { mockClient } >
415+ < div > Finished</ div >
416+ </ AuthProvider >
417+ )
418+ await waitFor ( ( ) => screen . getByText ( "Finished" ) )
419+ unmount ( )
420+ expect ( mockClient . destroy ) . not . toHaveBeenCalled ( )
421+ } )
422+
423+ it ( "useAuthInfo returns auth info from external client" , async ( ) => {
424+ const authenticationInfo = createAuthenticationInfo ( )
425+ mockClient . getAuthenticationInfoOrNull . mockReturnValue ( authenticationInfo )
426+
427+ const Component = ( ) => {
428+ const authInfo = useAuthInfo ( )
429+ if ( authInfo . loading ) {
430+ return < div > Loading...</ div >
431+ }
432+ expect ( authInfo . accessToken ) . toBe ( authenticationInfo . accessToken )
433+ expect ( authInfo . user ) . toStrictEqual ( authenticationInfo . user )
434+ expect ( authInfo . isLoggedIn ) . toBe ( true )
435+ return < div > Finished</ div >
436+ }
437+
438+ render (
439+ < AuthProvider client = { mockClient } >
440+ < Component />
441+ </ AuthProvider >
442+ )
443+
444+ await waitFor ( ( ) => screen . getByText ( "Finished" ) )
445+ } )
446+
412447it ( "when client logs out, authInfo is refreshed" , async ( ) => {
413448 const initialAuthInfo = createAuthenticationInfo ( )
414449 mockClient . getAuthenticationInfoOrNull . mockReturnValueOnce ( initialAuthInfo ) . mockReturnValueOnce ( null )
@@ -583,9 +618,18 @@ it("AuthProviderForTesting can be used with useAuthInfo", async () => {
583618 await waitFor ( ( ) => screen . getByText ( "Finished" ) )
584619} )
585620
621+ const AUTH_URL = "authUrl"
622+
586623function createMockClient ( ) {
587624 return {
588625 getAuthenticationInfoOrNull : jest . fn ( ) ,
626+ getAuthOptions : jest . fn ( ) . mockReturnValue ( {
627+ authUrl : AUTH_URL ,
628+ enableBackgroundTokenRefresh : true ,
629+ minSecondsBeforeRefresh : 120 ,
630+ disableRefreshOnFocus : false ,
631+ skipInitialFetch : true ,
632+ } ) ,
589633 logout : jest . fn ( ) ,
590634 redirectToSignupPage : jest . fn ( ) ,
591635 redirectToLoginPage : jest . fn ( ) ,
@@ -600,10 +644,12 @@ function createMockClient() {
600644 }
601645}
602646
603- const AUTH_URL = "authUrl"
604-
605647function expectCreateClientWasCalledCorrectly ( ) {
606- expect ( createClient ) . toHaveBeenCalledWith ( { authUrl : AUTH_URL , enableBackgroundTokenRefresh : true , skipInitialFetch : true } )
648+ expect ( createClient ) . toHaveBeenCalledWith ( {
649+ authUrl : AUTH_URL ,
650+ enableBackgroundTokenRefresh : true ,
651+ skipInitialFetch : true ,
652+ } )
607653}
608654
609655function createOrg ( ) {
0 commit comments