44import { QueryClient } from '@tanstack/react-query'
55import { beforeEach , describe , expect , it , vi } from 'vitest'
66
7- const { mockGetUserSettings , mockExecute, mockAuthenticate } = vi . hoisted ( ( ) => ( {
8- mockGetUserSettings : vi . fn ( ) ,
7+ const { mockGetCurrentUserSettings , mockExecute, mockAuthenticate } = vi . hoisted ( ( ) => ( {
8+ mockGetCurrentUserSettings : vi . fn ( ) ,
99 mockExecute : vi . fn ( ) ,
1010 mockAuthenticate : vi . fn ( ) ,
1111} ) )
1212
13- vi . mock ( '@/lib/users/queries ' , ( ) => ( {
14- getUserSettings : mockGetUserSettings ,
13+ vi . mock ( '@/lib/users/application/read-current-user ' , ( ) => ( {
14+ getCurrentUserSettingsUseCase : { execute : mockGetCurrentUserSettings } ,
1515} ) )
1616
1717vi . mock ( '@/lib/credential-groups/application/manage-groups' , ( ) => ( {
@@ -21,17 +21,22 @@ vi.mock('@/lib/credential-groups/application/manage-groups', () => ({
2121vi . mock ( '@/lib/api/server/routes/internal-json-route' , ( ) => ( {
2222 internalSessionAuth : { authenticate : mockAuthenticate } ,
2323} ) )
24+ vi . mock ( '@/lib/api/server/routes' , ( ) => ( {
25+ internalSessionAuth : { authenticate : mockAuthenticate } ,
26+ } ) )
2427
25- import {
26- prefetchGeneralSettings ,
27- SECTION_PREFETCHERS ,
28- } from '@/app/workspace/[workspaceId]/settings/[section]/prefetch'
29- import { generalSettingsKeys } from '@/hooks/queries/general-settings'
28+ import { SECTION_PREFETCHERS } from '@/app/workspace/[workspaceId]/settings/[section]/prefetch'
29+ import { generalSettingsKeys } from '@/hooks/queries/general-settings-data'
3030import { credentialGroupKeys } from '@/hooks/queries/utils/credential-group-queries'
3131
32- describe ( 'prefetchGeneralSettings' , ( ) => {
33- it ( 'uses the authenticated viewer id supplied by the route' , async ( ) => {
34- mockGetUserSettings . mockResolvedValue ( {
32+ describe ( 'general settings prefetch' , ( ) => {
33+ beforeEach ( ( ) => {
34+ vi . clearAllMocks ( )
35+ mockAuthenticate . mockResolvedValue ( { kind : 'session' , userId : 'viewer-a' , sessionId : 's1' } )
36+ } )
37+
38+ it ( 'hydrates through the current-user application operation and response contract' , async ( ) => {
39+ mockGetCurrentUserSettings . mockResolvedValue ( {
3540 autoConnect : true ,
3641 superUserModeEnabled : false ,
3742 mothershipEnvironment : 'prod' ,
@@ -47,9 +52,12 @@ describe('prefetchGeneralSettings', () => {
4752 } )
4853 const queryClient = new QueryClient ( )
4954
50- await prefetchGeneralSettings ( queryClient , 'viewer -a')
55+ await SECTION_PREFETCHERS . general ?. ( queryClient , { workspaceId : 'workspace -a' } )
5156
52- expect ( mockGetUserSettings ) . toHaveBeenCalledWith ( 'viewer-a' )
57+ expect ( mockGetCurrentUserSettings ) . toHaveBeenCalledWith ( {
58+ principal : { kind : 'session' , userId : 'viewer-a' , sessionId : 's1' } ,
59+ input : { } ,
60+ } )
5361 expect ( queryClient . getQueryData ( generalSettingsKeys . settings ( ) ) ) . toMatchObject ( {
5462 theme : 'system' ,
5563 telemetryEnabled : true ,
@@ -82,7 +90,6 @@ describe('credential-groups prefetch', () => {
8290
8391 await SECTION_PREFETCHERS [ 'credential-groups' ] ?.( queryClient , {
8492 workspaceId : 'w1' ,
85- userId : 'u1' ,
8693 } )
8794
8895 expect ( mockExecute ) . toHaveBeenCalledWith ( {
@@ -106,7 +113,6 @@ describe('credential-groups prefetch', () => {
106113
107114 await SECTION_PREFETCHERS [ 'credential-groups' ] ?.( queryClient , {
108115 workspaceId : 'w1' ,
109- userId : 'u1' ,
110116 } )
111117
112118 expect ( queryClient . getQueryData ( credentialGroupKeys . list ( 'w1' ) ) ) . toBeUndefined ( )
@@ -118,7 +124,6 @@ describe('credential-groups prefetch', () => {
118124
119125 await SECTION_PREFETCHERS [ 'credential-groups' ] ?.( queryClient , {
120126 workspaceId : 'w1' ,
121- userId : 'u1' ,
122127 } )
123128
124129 expect ( mockExecute ) . not . toHaveBeenCalled ( )
0 commit comments