@@ -23,26 +23,21 @@ interface Response {
2323
2424async function makeRequest ( options : RequestOptions , data : any = null ) : Promise < Response > {
2525 const url = `https://${ options . hostname } :${ options . port } ${ options . path } ` ;
26- const fetchOptions : any = {
26+ const fetchOptions : RequestInit = { // Changed from any to RequestInit
27+ method : options . method , // Explicitly set the method
2728 headers : {
2829 'Content-Type' : 'application/json'
2930 } ,
3031 body : data ? JSON . stringify ( data ) : undefined ,
31- ...options
3232 } ;
3333
34- try {
35- const res = await fetch ( url , fetchOptions ) ;
36- const responseBody = await res . json ( ) ;
37- return {
38- statusCode : res . status ,
39- headers : res . headers ,
40- body : responseBody
41- } ;
42- } catch ( error ) {
43- // console.log(error);
44- throw error ;
45- }
34+ const response = await fetch ( url , fetchOptions ) ;
35+ const responseBody = await response . json ( ) ;
36+ return {
37+ statusCode : response . status ,
38+ headers : response . headers as Headers ,
39+ body : responseBody
40+ } ;
4641}
4742
4843const testConfig : Config = {
@@ -81,8 +76,7 @@ describe('CanhazDB Server Tests', async () => {
8176 hostname : 'localhost' ,
8277 port : 3000 ,
8378 path : '/users' ,
84- method : 'POST' ,
85- rejectUnauthorized : false
79+ method : 'POST'
8680 } , { name : 'John Doe' , age : 30 } ) ;
8781
8882 assert . equal ( response . statusCode , 200 ) ;
@@ -97,8 +91,7 @@ describe('CanhazDB Server Tests', async () => {
9791 hostname : 'localhost' ,
9892 port : 3000 ,
9993 path : '/users' ,
100- method : 'POST' ,
101- rejectUnauthorized : false
94+ method : 'POST'
10295 } , { name : 'Jane Doe' , age : 25 } ) ;
10396
10497 const documentId = createResponse . body . documentId ;
@@ -144,8 +137,7 @@ describe('CanhazDB Server Tests', async () => {
144137 hostname : 'localhost' ,
145138 port : 3000 ,
146139 path : `/users/${ documentId } ` ,
147- method : 'GET' ,
148- rejectUnauthorized : false
140+ method : 'GET'
149141 } ) ;
150142
151143 assert . equal ( getResponse . body . name , 'Bob Smith' ) ;
@@ -158,8 +150,7 @@ describe('CanhazDB Server Tests', async () => {
158150 hostname : 'localhost' ,
159151 port : 3000 ,
160152 path : '/users' ,
161- method : 'POST' ,
162- rejectUnauthorized : false
153+ method : 'POST'
163154 } , { name : 'Alice Johnson' , age : 35 } ) ;
164155
165156 const documentId = createResponse . body . documentId ;
@@ -169,8 +160,7 @@ describe('CanhazDB Server Tests', async () => {
169160 hostname : 'localhost' ,
170161 port : 3000 ,
171162 path : `/users/${ documentId } ` ,
172- method : 'DELETE' ,
173- rejectUnauthorized : false
163+ method : 'DELETE'
174164 } ) ;
175165
176166 assert . equal ( response . statusCode , 200 ) ;
@@ -182,8 +172,7 @@ describe('CanhazDB Server Tests', async () => {
182172 hostname : 'localhost' ,
183173 port : 3000 ,
184174 path : `/users/${ documentId } ` ,
185- method : 'GET' ,
186- rejectUnauthorized : false
175+ method : 'GET'
187176 } ) ;
188177
189178 assert . deepEqual ( getResponse . body , { error : 'Document not found' } ) ;
@@ -237,8 +226,7 @@ describe('CanhazDB Server Tests', async () => {
237226 hostname : 'localhost' ,
238227 port : 3000 ,
239228 path : '' ,
240- method : 'GET' ,
241- rejectUnauthorized : false
229+ method : 'GET'
242230 } ) ;
243231 assert . equal ( response . statusCode , 400 ) ;
244232 assert . equal ( response . body . error , 'Collection name is required' ) ;
@@ -249,8 +237,7 @@ describe('CanhazDB Server Tests', async () => {
249237 hostname : 'localhost' ,
250238 port : 3000 ,
251239 path : '/' ,
252- method : 'GET' ,
253- rejectUnauthorized : false
240+ method : 'GET'
254241 } ) ;
255242 assert . equal ( response . statusCode , 400 ) ;
256243 assert . equal ( response . body . error , 'Collection name is required' ) ;
0 commit comments