Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/__tests__/RESTController-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,3 +434,39 @@
});
});
});
it('follows HTTP redirects for batch requests when using a custom SERVER_URL', async () => {

Check failure on line 437 in src/__tests__/RESTController-test.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 0 spaces but found 2
// Configure a reverse-proxy style SERVER_URL

Check failure on line 438 in src/__tests__/RESTController-test.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 2 spaces but found 4
CoreManager.set('SERVER_URL', 'http://test.host/api');

Check failure on line 439 in src/__tests__/RESTController-test.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 2 spaces but found 4

// Prepare a minimal batch payload

Check failure on line 441 in src/__tests__/RESTController-test.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 2 spaces but found 4
const batchData = {

Check failure on line 442 in src/__tests__/RESTController-test.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 2 spaces but found 4
requests: [{

Check failure on line 443 in src/__tests__/RESTController-test.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 4 spaces but found 6
method: 'POST',

Check failure on line 444 in src/__tests__/RESTController-test.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 6 spaces but found 8
path: '/classes/TestObject',

Check failure on line 445 in src/__tests__/RESTController-test.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 6 spaces but found 8
body: { foo: 'bar' }

Check failure on line 446 in src/__tests__/RESTController-test.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 6 spaces but found 8
}]

Check failure on line 447 in src/__tests__/RESTController-test.js

View workflow job for this annotation

GitHub Actions / Lint

Expected indentation of 4 spaces but found 6
};

// 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);
});
Loading