@@ -142,6 +142,81 @@ describe("Agent", () => {
142142 timeout : 1000 ,
143143 } as any ) ;
144144 } ) ;
145+
146+ describe ( "GOT Configuration" , ( ) => {
147+ const timeout = 2000 ;
148+ const retry = 2 ;
149+
150+ beforeEach ( ( ) => {
151+ agent = new Agent ( { timeout, retry } ) ;
152+ } ) ;
153+
154+ it ( "overrides HTTP configuration for GET requests" , async ( ) => {
155+ const method : HttpVerb = "GET" ;
156+ const query = { foo : "bar" } ;
157+ const header = { baz : "quux" } ;
158+ const url = "http://www.foo.com/" ;
159+ const SUCCESS = 200 ;
160+
161+ const response : unknown = {
162+ statusCode : SUCCESS ,
163+ headers : header ,
164+ body : Buffer . from ( "{}" ) ,
165+ url,
166+ } ;
167+
168+ const stub = sinon
169+ . stub ( agent , "got" )
170+ . resolves ( response as Response < Buffer > ) ;
171+
172+ await agent . http ( { method, timeout : 1000 , url, header, query } ) ;
173+
174+ sinon . assert . calledOnce ( stub ) ;
175+ sinon . assert . calledWithExactly ( stub , url , {
176+ method,
177+ headers : header ,
178+ throwHttpErrors : false ,
179+ query,
180+ json : true ,
181+ timeout,
182+ retry,
183+ } as any ) ;
184+ } ) ;
185+
186+ it ( "overrides HTTP configuration for POST requests" , async ( ) => {
187+ const method : HttpVerb = "POST" ;
188+ const query = { foo : "bar" } ;
189+ const header = { baz : "quux" } ;
190+ const url = "http://www.foo.com/" ;
191+ const SUCCESS = 200 ;
192+ const body = { foo : "bar" } ;
193+
194+ const response : unknown = {
195+ statusCode : SUCCESS ,
196+ headers : header ,
197+ body : Buffer . from ( "{}" ) ,
198+ url,
199+ } ;
200+
201+ const stub = sinon
202+ . stub ( agent , "got" )
203+ . resolves ( response as Response < Buffer > ) ;
204+
205+ await agent . http ( { body, method, timeout : 1000 , url, header, query } ) ;
206+
207+ sinon . assert . calledOnce ( stub ) ;
208+ sinon . assert . calledWithExactly ( stub , url , {
209+ method,
210+ throwHttpErrors : false ,
211+ json : true ,
212+ body,
213+ headers : header ,
214+ query,
215+ retry,
216+ timeout,
217+ } as any ) ;
218+ } ) ;
219+ } ) ;
145220 } ) ;
146221
147222 describe ( "Error handling" , ( ) => {
0 commit comments