From 1857368860fe430d29030952f01a448d870efcbc Mon Sep 17 00:00:00 2001 From: "coderabbitai[bot]" <136622811+coderabbitai[bot]@users.noreply.github.com> Date: Fri, 9 May 2025 21:32:10 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20CodeRabbit=20Chat:=20Add=20tests?= =?UTF-8?q?=20to=20src/=5F=5Ftests=5F=5F/RESTController-test.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/__tests__/RESTController-test.js | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/__tests__/RESTController-test.js b/src/__tests__/RESTController-test.js index f3c3b7817..bfdf553d3 100644 --- a/src/__tests__/RESTController-test.js +++ b/src/__tests__/RESTController-test.js @@ -434,3 +434,39 @@ describe('RESTController', () => { }); }); }); + it('follows HTTP redirects for batch requests when using a custom SERVER_URL', async () => { + // Configure a reverse-proxy style SERVER_URL + CoreManager.set('SERVER_URL', 'http://test.host/api'); + + // Prepare a minimal batch payload + const batchData = { + requests: [{ + method: 'POST', + path: '/classes/TestObject', + body: { foo: 'bar' } + }] + }; + + // First response: 301 redirect to /parse/batch; second: successful response + mockFetch( + [ + { status: 301, response: {} }, + { status: 200, response: { success: true } } + ], + { location: 'http://test.host/parse/batch' } + ); + + // Issue the batch request + const result = await RESTController.request('POST', 'batch', batchData); + + // We expect two fetch calls: one to the original URL, then one to the Location header + expect(fetch.mock.calls.length).toBe(2); + expect(fetch.mock.calls[0][0]).toEqual('http://test.host/api/batch'); + expect(fetch.mock.calls[1][0]).toEqual('http://test.host/parse/batch'); + + // The final result should be the JSON from the second (successful) response + expect(result).toEqual({ success: true }); + + // Clean up the custom SERVER_URL + CoreManager.set('SERVER_URL', undefined); + });