Merge pull request #15895 from overleaf/jpa-latexqc-fetch-backend

[latexqc] migrate backend from axios to fetch

GitOrigin-RevId: 6dc1a9ca0aa96da01229fec96d3c4b34750f4aa2
This commit is contained in:
Jakob Ackermann
2023-11-28 09:05:06 +00:00
committed by Copybot
parent 011609b345
commit 7a87bf4288
4 changed files with 75 additions and 0 deletions
@@ -7,6 +7,7 @@ const {
fetchJson,
fetchStream,
fetchNothing,
fetchRedirect,
fetchString,
RequestFailedError,
} = require('../..')
@@ -205,6 +206,36 @@ describe('fetch-utils', function () {
await expectRequestAborted(this.server.lastReq)
})
})
describe('fetchRedirect', function () {
it('returns the immediate redirect', async function () {
const body = await fetchRedirect(this.url('/redirect/1'))
expect(body).to.equal(this.url('/redirect/2'))
})
it('rejects status 200', async function () {
await expect(fetchRedirect(this.url('/hello'))).to.be.rejectedWith(
RequestFailedError
)
await expectRequestAborted(this.server.lastReq)
})
it('rejects empty redirect', async function () {
await expect(fetchRedirect(this.url('/redirect/empty-location')))
.to.be.rejectedWith(RequestFailedError)
.and.eventually.have.property('cause')
.and.to.have.property('message')
.to.equal('missing Location response header on 3xx response')
await expectRequestAborted(this.server.lastReq)
})
it('handles errors', async function () {
await expect(fetchRedirect(this.url('/500'))).to.be.rejectedWith(
RequestFailedError
)
await expectRequestAborted(this.server.lastReq)
})
})
})
async function streamToString(stream) {