@@ -3,7 +3,7 @@ import { it, expect, vi, describe, beforeEach } from 'vitest'
33import { DialogFormRemoteMcp } from '../dialog-form-remote-mcp'
44import userEvent from '@testing-library/user-event'
55import { Dialog } from '@/common/components/ui/dialog'
6- import { server as mswServer } from '@/common/mocks/node'
6+ import { server as mswServer , recordRequests } from '@/common/mocks/node'
77import { http , HttpResponse } from 'msw'
88import { QueryClient , QueryClientProvider } from '@tanstack/react-query'
99import { mswEndpoint } from '@/common/mocks/customHandlers'
@@ -166,15 +166,14 @@ describe('DialogFormRemoteMcp', () => {
166166 const user = userEvent . setup ( { delay : null } )
167167 const mockCheckServerStatus = vi . fn ( )
168168 const mockOnOpenChange = vi . fn ( )
169- let recordedRequest : Request | null = null
169+ const rec = recordRequests ( )
170170
171171 mockUseCheckServerStatus . mockReturnValue ( {
172172 checkServerStatus : mockCheckServerStatus ,
173173 } )
174174
175175 mswServer . use (
176- http . post ( mswEndpoint ( '/api/v1beta/workloads' ) , async ( { request } ) => {
177- recordedRequest = request . clone ( )
176+ http . post ( mswEndpoint ( '/api/v1beta/workloads' ) , ( ) => {
178177 return HttpResponse . json (
179178 { name : 'test-remote-server' , status : 'running' } ,
180179 { status : 201 }
@@ -216,31 +215,31 @@ describe('DialogFormRemoteMcp', () => {
216215 await user . click ( screen . getByRole ( 'button' , { name : 'Install server' } ) )
217216
218217 await waitFor ( ( ) => {
219- expect ( recordedRequest ) . not . toBeNull ( )
218+ const workloadCall = rec . recordedRequests . find (
219+ ( r ) => r . method === 'POST' && r . pathname === '/api/v1beta/workloads'
220+ )
221+ expect ( workloadCall ) . toBeDefined ( )
222+ expect ( workloadCall ?. payload ) . toEqual (
223+ expect . objectContaining ( {
224+ url : 'https://api.example.com/mcp' ,
225+ name : 'test-remote-server' ,
226+ oauth_config : expect . objectContaining ( {
227+ authorize_url : '' ,
228+ callback_port : 8888 ,
229+ client_id : '' ,
230+ issuer : '' ,
231+ oauth_params : { } ,
232+ scopes : [ ] ,
233+ skip_browser : false ,
234+ token_url : '' ,
235+ use_pkce : true ,
236+ } ) ,
237+ transport : 'streamable-http' ,
238+ group : 'default' ,
239+ } )
240+ )
220241 } )
221242
222- expect ( recordedRequest ) . not . toBeNull ( )
223- const requestBody = await recordedRequest ! . json ( )
224- expect ( requestBody ) . toEqual (
225- expect . objectContaining ( {
226- url : 'https://api.example.com/mcp' ,
227- name : 'test-remote-server' ,
228- oauth_config : expect . objectContaining ( {
229- authorize_url : '' ,
230- callback_port : 8888 ,
231- client_id : '' ,
232- issuer : '' ,
233- oauth_params : { } ,
234- scopes : [ ] ,
235- skip_browser : false ,
236- token_url : '' ,
237- use_pkce : true ,
238- } ) ,
239- transport : 'streamable-http' ,
240- group : 'default' ,
241- } )
242- )
243-
244243 await waitFor ( ( ) => {
245244 expect ( mockCheckServerStatus ) . toHaveBeenCalled ( )
246245 expect ( mockOnOpenChange ) . toHaveBeenCalled ( )
@@ -254,11 +253,10 @@ describe('DialogFormRemoteMcp', () => {
254253 'submits Issuer URL when auth type is %s' ,
255254 async ( authOptionLabel , expectedAuthType ) => {
256255 const user = userEvent . setup ( { delay : null } )
257- let recordedRequest : Request | null = null
256+ const rec = recordRequests ( )
258257
259258 mswServer . use (
260- http . post ( mswEndpoint ( '/api/v1beta/workloads' ) , async ( { request } ) => {
261- recordedRequest = request . clone ( )
259+ http . post ( mswEndpoint ( '/api/v1beta/workloads' ) , ( ) => {
262260 return HttpResponse . json (
263261 { name : 'issuer-enabled-server' , status : 'running' } ,
264262 { status : 201 }
@@ -325,32 +323,31 @@ describe('DialogFormRemoteMcp', () => {
325323 await user . click ( screen . getByRole ( 'button' , { name : 'Install server' } ) )
326324
327325 await waitFor ( ( ) => {
328- expect ( recordedRequest ) . not . toBeNull ( )
329- } )
330-
331- expect ( recordedRequest ) . not . toBeNull ( )
332- const requestBody = await recordedRequest ! . json ( )
333- expect ( requestBody ) . toEqual (
334- expect . objectContaining ( {
335- name : 'issuer-enabled-server' ,
336- url : 'https://api.example.com/mcp' ,
337- transport : 'streamable-http' ,
338- group : 'default' ,
339- oauth_config : expect . objectContaining ( {
340- issuer : issuerValue ,
341- callback_port : 7777 ,
342- scopes : [ ] ,
343- } ) ,
344- } )
345- )
346-
347- // Verify client_id is set for OIDC
348- if ( expectedAuthType === 'oidc' ) {
349- expect ( requestBody . oauth_config ) . toHaveProperty (
350- 'client_id' ,
351- 'oidc-client-id'
326+ const workloadCall = rec . recordedRequests . find (
327+ ( r ) => r . method === 'POST' && r . pathname === '/api/v1beta/workloads'
352328 )
353- }
329+ expect ( workloadCall ) . toBeDefined ( )
330+ expect ( workloadCall ?. payload ) . toEqual (
331+ expect . objectContaining ( {
332+ name : 'issuer-enabled-server' ,
333+ url : 'https://api.example.com/mcp' ,
334+ transport : 'streamable-http' ,
335+ group : 'default' ,
336+ oauth_config : expect . objectContaining ( {
337+ issuer : issuerValue ,
338+ callback_port : 7777 ,
339+ scopes : [ ] ,
340+ } ) ,
341+ } )
342+ )
343+
344+ if ( expectedAuthType === 'oidc' ) {
345+ expect (
346+ ( workloadCall ?. payload as { oauth_config : { client_id : string } } )
347+ . oauth_config
348+ ) . toHaveProperty ( 'client_id' , 'oidc-client-id' )
349+ }
350+ } )
354351 }
355352 )
356353
@@ -383,7 +380,7 @@ describe('DialogFormRemoteMcp', () => {
383380 const user = userEvent . setup ( { delay : null } )
384381 const mockCheckServerStatus = vi . fn ( )
385382 const mockOnOpenChange = vi . fn ( )
386- let recordedRequest : Request | null = null
383+ const rec = recordRequests ( )
387384
388385 mockUseCheckServerStatus . mockReturnValue ( {
389386 checkServerStatus : mockCheckServerStatus ,
@@ -409,16 +406,12 @@ describe('DialogFormRemoteMcp', () => {
409406 group : 'default' ,
410407 } )
411408 } ) ,
412- http . patch (
413- mswEndpoint ( '/api/v1beta/workloads/:name' ) ,
414- async ( { request } ) => {
415- recordedRequest = request . clone ( )
416- return HttpResponse . json ( {
417- name : 'existing-server' ,
418- status : 'running' ,
419- } )
420- }
421- )
409+ http . patch ( mswEndpoint ( '/api/v1beta/workloads/:name' ) , ( ) => {
410+ return HttpResponse . json ( {
411+ name : 'existing-server' ,
412+ status : 'running' ,
413+ } )
414+ } )
422415 )
423416
424417 renderWithProviders (
@@ -449,19 +442,19 @@ describe('DialogFormRemoteMcp', () => {
449442 await user . click ( screen . getByRole ( 'button' , { name : / u p d a t e s e r v e r / i } ) )
450443
451444 await waitFor ( ( ) => {
452- expect ( recordedRequest ) . not . toBeNull ( )
445+ const patchCall = rec . recordedRequests . find (
446+ ( r ) => r . method === 'PATCH' && r . pathname . includes ( '/workloads/' )
447+ )
448+ expect ( patchCall ) . toBeDefined ( )
449+ expect ( patchCall ?. payload ) . toEqual (
450+ expect . objectContaining ( {
451+ name : 'existing-server' ,
452+ url : 'https://new-api.example.com' ,
453+ transport : 'streamable-http' ,
454+ } )
455+ )
453456 } )
454457
455- expect ( recordedRequest ) . not . toBeNull ( )
456- const requestBody = await recordedRequest ! . json ( )
457- expect ( requestBody ) . toEqual (
458- expect . objectContaining ( {
459- name : 'existing-server' ,
460- url : 'https://new-api.example.com' ,
461- transport : 'streamable-http' ,
462- } )
463- )
464-
465458 await waitFor ( ( ) => {
466459 expect ( mockCheckServerStatus ) . toHaveBeenCalled ( )
467460 expect ( mockOnOpenChange ) . toHaveBeenCalled ( )
0 commit comments