@@ -434,3 +434,39 @@ describe('RESTController', () => {
434434 } ) ;
435435 } ) ;
436436} ) ;
437+ it ( 'follows HTTP redirects for batch requests when using a custom SERVER_URL' , async ( ) => {
438+ // Configure a reverse-proxy style SERVER_URL
439+ CoreManager . set ( 'SERVER_URL' , 'http://test.host/api' ) ;
440+
441+ // Prepare a minimal batch payload
442+ const batchData = {
443+ requests : [ {
444+ method : 'POST' ,
445+ path : '/classes/TestObject' ,
446+ body : { foo : 'bar' }
447+ } ]
448+ } ;
449+
450+ // First response: 301 redirect to /parse/batch; second: successful response
451+ mockFetch (
452+ [
453+ { status : 301 , response : { } } ,
454+ { status : 200 , response : { success : true } }
455+ ] ,
456+ { location : 'http://test.host/parse/batch' }
457+ ) ;
458+
459+ // Issue the batch request
460+ const result = await RESTController . request ( 'POST' , 'batch' , batchData ) ;
461+
462+ // We expect two fetch calls: one to the original URL, then one to the Location header
463+ expect ( fetch . mock . calls . length ) . toBe ( 2 ) ;
464+ expect ( fetch . mock . calls [ 0 ] [ 0 ] ) . toEqual ( 'http://test.host/api/batch' ) ;
465+ expect ( fetch . mock . calls [ 1 ] [ 0 ] ) . toEqual ( 'http://test.host/parse/batch' ) ;
466+
467+ // The final result should be the JSON from the second (successful) response
468+ expect ( result ) . toEqual ( { success : true } ) ;
469+
470+ // Clean up the custom SERVER_URL
471+ CoreManager . set ( 'SERVER_URL' , undefined ) ;
472+ } ) ;
0 commit comments