@@ -551,6 +551,49 @@ test('Should be able to define a custom cache key for request memoization', asyn
551551 t . deepEqual ( response . body , wanted )
552552} )
553553
554+ test ( 'Should correctly calculate and sort query parameters' , async ( t ) => {
555+ t . plan ( 3 )
556+
557+ const path = '/'
558+
559+ const wanted = { name : 'foo' }
560+
561+ const server = http . createServer ( ( req , res ) => {
562+ t . is ( req . method , 'GET' )
563+ t . is ( req . url , '/?a=1&b=2&z=z' )
564+ res . writeHead ( 200 , {
565+ 'content-type' : 'application/json' ,
566+ } )
567+ res . write ( JSON . stringify ( wanted ) )
568+ res . end ( )
569+ res . socket ?. unref ( )
570+ } )
571+
572+ t . teardown ( server . close . bind ( server ) )
573+
574+ server . listen ( )
575+
576+ const baseURL = `http://localhost:${ ( server . address ( ) as AddressInfo ) ?. port } `
577+
578+ const dataSource = new ( class extends HTTPDataSource {
579+ constructor ( ) {
580+ super ( baseURL )
581+ }
582+ getFoo ( ) {
583+ return this . get ( path , {
584+ query : {
585+ b : 2 ,
586+ a : 1 ,
587+ z : 'z' ,
588+ } ,
589+ } )
590+ }
591+ } ) ( )
592+
593+ let response = await dataSource . getFoo ( )
594+ t . deepEqual ( response . body , wanted )
595+ } )
596+
554597test ( 'Should call onError on request error' , async ( t ) => {
555598 t . plan ( 11 )
556599
@@ -1394,4 +1437,4 @@ test('Should be able to pass custom Undici Pool', async (t) => {
13941437 const response = await dataSource . getFoo ( )
13951438
13961439 t . deepEqual ( response . body , wanted )
1397- } )
1440+ } )
0 commit comments