@@ -5,8 +5,9 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
55import { createRoot , type Root } from 'react-dom/client'
66import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest'
77
8- const mocks = vi . hoisted ( ( ) => ( { request : vi . fn ( ) } ) )
8+ const mocks = vi . hoisted ( ( ) => ( { request : vi . fn ( ) , refresh : vi . fn ( ) } ) )
99vi . mock ( '@/lib/api/client/request' , ( ) => ( { requestJson : mocks . request } ) )
10+ vi . mock ( 'next/navigation' , ( ) => ( { useRouter : ( ) => ( { refresh : mocks . refresh } ) } ) )
1011
1112import { ApiClientError } from '@/lib/api/client/errors'
1213import {
@@ -27,10 +28,11 @@ import { searchSourceKeys } from '@/hooks/queries/utils/search-source-keys'
2728
2829describe ( 'personal account disconnect' , ( ) => {
2930 it . each ( [ true , false ] ) (
30- 'refreshes this organization only after success=%s, including after unmount' ,
31+ 'clears content and refreshes the router only after success=%s, including after unmount' ,
3132 async ( success ) => {
3233 vi . stubGlobal ( 'IS_REACT_ACT_ENVIRONMENT' , true )
3334 mocks . request . mockReset ( )
35+ mocks . refresh . mockReset ( )
3436 const response = Promise . withResolvers < { success : true } > ( )
3537 mocks . request . mockReturnValue ( response . promise )
3638 const client = new QueryClient ( )
@@ -112,13 +114,22 @@ describe('personal account disconnect', () => {
112114 disconnectPersonalOrganizationAccountContract ,
113115 { params : { credentialId : 'own-credential' } }
114116 )
115- for ( const key of [ own , catalog , results , ownDocument , resultOnlyDocument , chunks ] ) {
117+ for ( const key of [
118+ own ,
119+ catalog ,
120+ results ,
121+ ownDocument ,
122+ resultOnlyDocument ,
123+ chunks ,
124+ otherDocument ,
125+ ] ) {
116126 if ( success ) expect ( client . getQueryData ( key ) ) . toBeUndefined ( )
117127 else expect ( client . getQueryData ( key ) ) . toBeDefined ( )
118128 }
119129 expect ( client . getQueryState ( people ) ?. isInvalidated ) . toBe ( success )
120130 expect ( client . getQueryState ( other ) ?. isInvalidated ) . toBe ( false )
121- for ( const key of [ otherResults , workspaceResults , otherDocument ] )
131+ expect ( mocks . refresh ) . toHaveBeenCalledTimes ( success ? 1 : 0 )
132+ for ( const key of [ otherResults , workspaceResults ] )
122133 expect ( client . getQueryData ( key ) ) . toEqual ( { content : 'previously authorized content' } )
123134 } finally {
124135 await act ( async ( ) => root . unmount ( ) )
0 commit comments