@@ -468,6 +468,45 @@ describe('RESTController', () => {
468468 expect ( result ) . toEqual ( { success : true } ) ;
469469
470470 // Clean up the custom SERVER_URL
471- CoreManager . set ( 'SERVER_URL' , undefined ) ;
471+ CoreManager . set ( 'SERVER_URL' , 'https://api.parse.com/1' ) ;
472+ } ) ;
473+
474+ it ( 'follows multiple HTTP redirects' , async ( ) => {
475+ // Configure a reverse-proxy style SERVER_URL
476+ CoreManager . set ( 'SERVER_URL' , 'http://test.host/api' ) ;
477+
478+ // Prepare a minimal batch payload
479+ const batchData = {
480+ requests : [ {
481+ method : 'POST' ,
482+ path : '/classes/TestObject' ,
483+ body : { foo : 'bar' }
484+ } ]
485+ } ;
486+
487+ // First response: 301 redirect to /parse/batch; second: successful response
488+ mockFetch (
489+ [
490+ { status : 301 , response : { } } ,
491+ { status : 301 , response : { } } ,
492+ { status : 200 , response : { success : true } }
493+ ] ,
494+ { location : 'http://test.host/parse/' }
495+ ) ;
496+
497+ // Issue the batch request
498+ const result = await RESTController . request ( 'POST' , 'batch' , batchData ) ;
499+
500+ // We expect three fetch calls: one to the original URL, then two to the Location header
501+ expect ( fetch . mock . calls . length ) . toBe ( 3 ) ;
502+ expect ( fetch . mock . calls [ 0 ] [ 0 ] ) . toEqual ( 'http://test.host/api/batch' ) ;
503+ expect ( fetch . mock . calls [ 1 ] [ 0 ] ) . toEqual ( 'http://test.host/parse/batch' ) ;
504+ expect ( fetch . mock . calls [ 2 ] [ 0 ] ) . toEqual ( 'http://test.host/parse/batch' ) ;
505+
506+ // The final result should be the JSON from the second (successful) response
507+ expect ( result ) . toEqual ( { success : true } ) ;
508+
509+ // Clean up the custom SERVER_URL
510+ CoreManager . set ( 'SERVER_URL' , 'https://api.parse.com/1' ) ;
472511 } ) ;
473512} ) ;
0 commit comments