@@ -172,7 +172,13 @@ const storage = new MockStorage()
172172 */
173173export function createMockFetch ( ) : Fetch {
174174 return async ( input : string | URL | Request , init ?: RequestInit ) : Promise < Response > => {
175- const url = input instanceof Request ? input . url : input
175+ // Handle different input types safely without assuming Request constructor exists
176+ const url =
177+ typeof input === 'string'
178+ ? input
179+ : input instanceof URL
180+ ? input . toString ( )
181+ : ( input as any ) . url || String ( input )
176182 const urlStr = url . toString ( )
177183 const endpoint = urlStr . split ( '/' ) . pop ( ) || ''
178184 const body = init ?. body ? JSON . parse ( init . body as string ) : { }
@@ -195,12 +201,30 @@ export function createMockFetch(): Fetch {
195201
196202 // Create mock Response object
197203 const responseBody = JSON . stringify ( response . error || response . data || { } )
198- return new Response ( responseBody , {
204+
205+ // Check if Response constructor is available (Node 18+, modern browsers)
206+ if ( typeof Response !== 'undefined' ) {
207+ return new Response ( responseBody , {
208+ status : response . status ,
209+ headers : {
210+ 'Content-Type' : 'application/json' ,
211+ } ,
212+ } ) as any
213+ }
214+
215+ // Fallback: Create a minimal Response-like object for older environments
216+ const mockResponse : any = {
217+ ok : response . status >= 200 && response . status < 300 ,
199218 status : response . status ,
219+ statusText : response . status === 200 ? 'OK' : 'Error' ,
200220 headers : {
201- 'Content-Type' : 'application/json' ,
221+ get : ( key : string ) => ( key . toLowerCase ( ) === 'content-type' ? 'application/json' : null ) ,
202222 } ,
203- } ) as any
223+ json : async ( ) => JSON . parse ( responseBody ) ,
224+ text : async ( ) => responseBody ,
225+ }
226+
227+ return mockResponse as Response
204228 }
205229}
206230
@@ -324,7 +348,7 @@ function handleDeleteBucket(body: any): MockResponse {
324348 return {
325349 status : 404 ,
326350 error : {
327- statusCode : 409 ,
351+ statusCode : 404 ,
328352 error : 'Not Found' ,
329353 message : `Bucket '${ vectorBucketName } ' not found` ,
330354 } ,
@@ -336,7 +360,7 @@ function handleDeleteBucket(body: any): MockResponse {
336360 return {
337361 status : 400 ,
338362 error : {
339- statusCode : 409 ,
363+ statusCode : 400 ,
340364 error : 'Bad Request' ,
341365 message : `Bucket '${ vectorBucketName } ' is not empty` ,
342366 } ,
@@ -355,7 +379,7 @@ function handleCreateIndex(body: any): MockResponse {
355379 return {
356380 status : 404 ,
357381 error : {
358- statusCode : 409 ,
382+ statusCode : 404 ,
359383 error : 'Not Found' ,
360384 message : `Bucket '${ vectorBucketName } ' not found` ,
361385 } ,
@@ -388,7 +412,7 @@ function handleGetIndex(body: any): MockResponse {
388412 return {
389413 status : 404 ,
390414 error : {
391- statusCode : 409 ,
415+ statusCode : 404 ,
392416 error : 'Not Found' ,
393417 message : `Bucket '${ vectorBucketName } ' not found` ,
394418 } ,
@@ -400,7 +424,7 @@ function handleGetIndex(body: any): MockResponse {
400424 return {
401425 status : 404 ,
402426 error : {
403- statusCode : 409 ,
427+ statusCode : 404 ,
404428 error : 'Not Found' ,
405429 message : `Index '${ indexName } ' not found` ,
406430 } ,
@@ -420,7 +444,7 @@ function handleListIndexes(body: any): MockResponse {
420444 return {
421445 status : 404 ,
422446 error : {
423- statusCode : 409 ,
447+ statusCode : 404 ,
424448 error : 'Not Found' ,
425449 message : `Bucket '${ vectorBucketName } ' not found` ,
426450 } ,
@@ -445,7 +469,7 @@ function handleDeleteIndex(body: any): MockResponse {
445469 return {
446470 status : 404 ,
447471 error : {
448- statusCode : 409 ,
472+ statusCode : 404 ,
449473 error : 'Not Found' ,
450474 message : `Bucket '${ vectorBucketName } ' not found` ,
451475 } ,
@@ -456,7 +480,7 @@ function handleDeleteIndex(body: any): MockResponse {
456480 return {
457481 status : 404 ,
458482 error : {
459- statusCode : 409 ,
483+ statusCode : 404 ,
460484 error : 'Not Found' ,
461485 message : `Index '${ indexName } ' not found` ,
462486 } ,
@@ -608,7 +632,7 @@ function handleQueryVectors(body: any): MockResponse {
608632 return {
609633 status : 404 ,
610634 error : {
611- statusCode : 409 ,
635+ statusCode : 404 ,
612636 error : 'Not Found' ,
613637 message : `Bucket '${ vectorBucketName } ' not found` ,
614638 } ,
0 commit comments