mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
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:
@@ -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) {
|
||||
|
||||
@@ -73,6 +73,18 @@ class TestServer {
|
||||
// Never returns
|
||||
|
||||
this.app.post('/hang', (req, res) => {})
|
||||
|
||||
// Redirect
|
||||
|
||||
this.app.get('/redirect/1', (req, res) => {
|
||||
res.redirect('/redirect/2')
|
||||
})
|
||||
this.app.get('/redirect/2', (req, res) => {
|
||||
res.send('body after redirect')
|
||||
})
|
||||
this.app.get('/redirect/empty-location', (req, res) => {
|
||||
res.sendStatus(302)
|
||||
})
|
||||
}
|
||||
|
||||
start(port) {
|
||||
|
||||
Reference in New Issue
Block a user