@@ -294,15 +294,34 @@ describe('SSEClientTransport', () => {
294294 expect ( lastServerRequest . headers . authorization ) . toBe ( authToken ) ;
295295 } ) ;
296296
297- it ( 'passes custom headers to fetch requests' , async ( ) => {
298- const customHeaders = {
299- Authorization : 'Bearer test-token' ,
300- 'X-Custom-Header' : 'custom-value'
301- } ;
302-
297+ it . each ( [
298+ {
299+ description : 'plain object headers' ,
300+ headers : {
301+ Authorization : 'Bearer test-token' ,
302+ 'X-Custom-Header' : 'custom-value'
303+ }
304+ } ,
305+ {
306+ description : 'Headers object' ,
307+ headers : ( ( ) : HeadersInit => {
308+ const h = new Headers ( ) ;
309+ h . set ( 'Authorization' , 'Bearer test-token' ) ;
310+ h . set ( 'X-Custom-Header' , 'custom-value' ) ;
311+ return h ;
312+ } ) ( )
313+ } ,
314+ {
315+ description : 'array of tuples' ,
316+ headers : ( ( ) : HeadersInit => [
317+ [ 'Authorization' , 'Bearer test-token' ] ,
318+ [ 'X-Custom-Header' , 'custom-value' ]
319+ ] ) ( )
320+ }
321+ ] ) ( 'passes custom headers to fetch requests ($description)' , async ( { headers } ) => {
303322 transport = new SSEClientTransport ( resourceBaseUrl , {
304323 requestInit : {
305- headers : customHeaders
324+ headers
306325 }
307326 } ) ;
308327
@@ -335,8 +354,8 @@ describe('SSEClientTransport', () => {
335354 ) ;
336355
337356 const calledHeaders = ( global . fetch as Mock ) . mock . calls [ 0 ] [ 1 ] . headers ;
338- expect ( calledHeaders . get ( 'Authorization' ) ) . toBe ( customHeaders . Authorization ) ;
339- expect ( calledHeaders . get ( 'X-Custom-Header' ) ) . toBe ( customHeaders [ 'X-Custom-Header' ] ) ;
357+ expect ( calledHeaders . get ( 'Authorization' ) ) . toBe ( 'Bearer test-token' ) ;
358+ expect ( calledHeaders . get ( 'X-Custom-Header' ) ) . toBe ( 'custom-value' ) ;
340359 expect ( calledHeaders . get ( 'content-type' ) ) . toBe ( 'application/json' ) ;
341360 } finally {
342361 // Restore original fetch
@@ -345,36 +364,6 @@ describe('SSEClientTransport', () => {
345364 } ) ;
346365 } ) ;
347366
348- it . each ( [
349- {
350- description : "plain object headers" ,
351- headers : {
352- Authorization : "Bearer test-token" ,
353- "X-Custom-Header" : "custom-value" ,
354- } ,
355- } ,
356- {
357- description : "Headers object" ,
358- headers : ( ( ) : HeadersInit => {
359- const h = new Headers ( ) ;
360- h . set ( "Authorization" , "Bearer test-token" ) ;
361- h . set ( "X-Custom-Header" , "custom-value" ) ;
362- return h ;
363- } ) ( ) ,
364- } ,
365- {
366- description : "array of tuples" ,
367- headers : ( ( ) : HeadersInit => ( [
368- [ "Authorization" , "Bearer test-token" ] ,
369- [ "X-Custom-Header" , "custom-value" ] ,
370- ] ) ) ( ) ,
371- } ,
372- ] ) ( "passes custom headers to fetch requests ($description)" , async ( { headers } ) => {
373- transport = new SSEClientTransport ( resourceBaseUrl , {
374- requestInit : {
375- headers,
376- } ,
377- } ) ;
378367 describe ( 'auth handling' , ( ) => {
379368 const authServerMetadataUrls = [ '/.well-known/oauth-authorization-server' , '/.well-known/openid-configuration' ] ;
380369
@@ -430,49 +419,6 @@ describe('SSEClientTransport', () => {
430419 }
431420 } ) ;
432421
433- await transport . send ( message ) ;
434-
435- // Verify fetch was called with correct headers
436- expect ( global . fetch ) . toHaveBeenCalledWith (
437- expect . any ( URL ) ,
438- expect . objectContaining ( {
439- headers : expect . any ( Headers ) ,
440- } ) ,
441- ) ;
442-
443- const calledHeaders = ( global . fetch as jest . Mock ) . mock . calls [ 0 ] [ 1 ]
444- . headers ;
445- expect ( calledHeaders . get ( "Authorization" ) ) . toBe ( "Bearer test-token" ) ;
446- expect ( calledHeaders . get ( "X-Custom-Header" ) ) . toBe ( "custom-value" ) ;
447- expect ( calledHeaders . get ( "content-type" ) ) . toBe ( "application/json" ) ;
448- } finally {
449- // Restore original fetch
450- global. fetch = originalFetch ;
451- }
452- } ) ;
453- } ) ;
454-
455- describe ( "auth handling" , ( ) => {
456- const authServerMetadataUrls = [
457- "/.well-known/oauth-authorization-server" ,
458- "/.well-known/openid-configuration" ,
459- ] ;
460-
461- let mockAuthProvider : jest . Mocked < OAuthClientProvider > ;
462-
463- beforeEach ( ( ) => {
464- mockAuthProvider = {
465- get redirectUrl ( ) { return "http://localhost/callback" ; } ,
466- get clientMetadata ( ) { return { redirect_uris : [ "http://localhost/callback" ] } ; } ,
467- clientInformation : jest . fn ( ( ) => ( { client_id : "test-client-id" , client_secret : "test-client-secret" } ) ) ,
468- tokens : jest . fn ( ) ,
469- saveTokens : jest . fn ( ) ,
470- redirectToAuthorization : jest . fn ( ) ,
471- saveCodeVerifier : jest . fn ( ) ,
472- codeVerifier : jest . fn ( ) ,
473- invalidateCredentials : jest . fn ( ) ,
474- } ;
475- } ) ;
476422 await transport . start ( ) ;
477423
478424 expect ( lastServerRequest . headers . authorization ) . toBe ( 'Bearer test-token' ) ;
0 commit comments