@@ -453,60 +453,65 @@ describe("AuthDebugger", () => {
453453 } ) ;
454454
455455 describe ( "OAuth State Persistence" , ( ) => {
456- skipIfCI ( "should store auth state to sessionStorage before redirect in Quick OAuth Flow" , async ( ) => {
457- const updateAuthState = jest . fn ( ) ;
458-
459- // This test depends on window.location being mocked at the top of the file
456+ skipIfCI (
457+ "should store auth state to sessionStorage before redirect in Quick OAuth Flow" ,
458+ async ( ) => {
459+ const updateAuthState = jest . fn ( ) ;
460+
461+ // This test depends on window.location being mocked at the top of the file
462+
463+ // Setup mocks for OAuth flow
464+ mockStartAuthorization . mockResolvedValue ( {
465+ authorizationUrl : new URL (
466+ "https://oauth.example.com/authorize?client_id=test_client_id&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Foauth%2Fcallback%2Fdebug" ,
467+ ) ,
468+ codeVerifier : "test_verifier" ,
469+ } ) ;
460470
461- // Setup mocks for OAuth flow
462- mockStartAuthorization . mockResolvedValue ( {
463- authorizationUrl : new URL (
464- "https://oauth.example.com/authorize?client_id=test_client_id&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Foauth%2Fcallback%2Fdebug" ,
465- ) ,
466- codeVerifier : "test_verifier" ,
467- } ) ;
471+ await act ( async ( ) => {
472+ renderAuthDebugger ( {
473+ updateAuthState,
474+ authState : { ...defaultAuthState } ,
475+ } ) ;
476+ } ) ;
468477
469- await act ( async ( ) => {
470- renderAuthDebugger ( {
471- updateAuthState,
472- authState : { ...defaultAuthState } ,
478+ // Click Quick OAuth Flow
479+ await act ( async ( ) => {
480+ fireEvent . click ( screen . getByText ( "Quick OAuth Flow" ) ) ;
473481 } ) ;
474- } ) ;
475482
476- // Click Quick OAuth Flow
477- await act ( async ( ) => {
478- fireEvent . click ( screen . getByText ( "Quick OAuth Flow" ) ) ;
479- } ) ;
483+ // Wait for the flow to reach the authorization step
484+ await waitFor ( ( ) => {
485+ expect ( sessionStorage . setItem ) . toHaveBeenCalledWith (
486+ SESSION_KEYS . AUTH_DEBUGGER_STATE ,
487+ expect . stringContaining ( '"oauthStep":"authorization_code"' ) ,
488+ ) ;
489+ } ) ;
480490
481- // Wait for the flow to reach the authorization step
482- await waitFor ( ( ) => {
483- expect ( sessionStorage . setItem ) . toHaveBeenCalledWith (
484- SESSION_KEYS . AUTH_DEBUGGER_STATE ,
485- expect . stringContaining ( '"oauthStep":"authorization_code"' ) ,
491+ // Verify the stored state includes all the accumulated data
492+ const storedStateCall = (
493+ sessionStorage . setItem as jest . Mock
494+ ) . mock . calls . find (
495+ ( call ) => call [ 0 ] === SESSION_KEYS . AUTH_DEBUGGER_STATE ,
486496 ) ;
487- } ) ;
488-
489- // Verify the stored state includes all the accumulated data
490- const storedStateCall = (
491- sessionStorage . setItem as jest . Mock
492- ) . mock . calls . find ( ( call ) => call [ 0 ] === SESSION_KEYS . AUTH_DEBUGGER_STATE ) ;
493497
494- expect ( storedStateCall ) . toBeDefined ( ) ;
495- const storedState = JSON . parse ( storedStateCall ! [ 1 ] as string ) ;
498+ expect ( storedStateCall ) . toBeDefined ( ) ;
499+ const storedState = JSON . parse ( storedStateCall ! [ 1 ] as string ) ;
496500
497- expect ( storedState ) . toMatchObject ( {
498- oauthStep : "authorization_code" ,
499- authorizationUrl : expect . stringMatching (
500- / ^ h t t p s : \/ \/ o a u t h \. e x a m p l e \. c o m \/ a u t h o r i z e / ,
501- ) ,
502- oauthMetadata : expect . objectContaining ( {
503- token_endpoint : "https://oauth.example.com/token" ,
504- } ) ,
505- oauthClientInfo : expect . objectContaining ( {
506- client_id : "test_client_id" ,
507- } ) ,
508- } ) ;
509- } ) ;
501+ expect ( storedState ) . toMatchObject ( {
502+ oauthStep : "authorization_code" ,
503+ authorizationUrl : expect . stringMatching (
504+ / ^ h t t p s : \/ \/ o a u t h \. e x a m p l e \. c o m \/ a u t h o r i z e / ,
505+ ) ,
506+ oauthMetadata : expect . objectContaining ( {
507+ token_endpoint : "https://oauth.example.com/token" ,
508+ } ) ,
509+ oauthClientInfo : expect . objectContaining ( {
510+ client_id : "test_client_id" ,
511+ } ) ,
512+ } ) ;
513+ } ,
514+ ) ;
510515 } ) ;
511516
512517 describe ( "OAuth Protected Resource Metadata" , ( ) => {
0 commit comments