Merge pull request #9956 from overleaf/em-node-fetch-web

Replace request-promise with fetch in web acceptance tests

GitOrigin-RevId: f50357cdea2d1353d7a82c5346b149018f91823f
This commit is contained in:
Eric Mc Sween
2022-10-18 08:03:25 +00:00
committed by Copybot
parent 00b051e2d7
commit fe963ba692
9 changed files with 368 additions and 453 deletions
@@ -9,9 +9,10 @@ describe('Launchpad', function () {
const user = new UserHelper()
it('should show the launchpad page', async function () {
const response = await user.request.get('/launchpad')
expect(response.statusCode).to.equal(200)
const $ = cheerio.load(response.body)
const response = await user.fetch('/launchpad')
expect(response.status).to.equal(200)
const body = await response.text()
const $ = cheerio.load(body)
expect($('h2').first().text()).to.equal('Create the first Admin account')
expect($('form[name="email"]').first()).to.exist
expect($('form[name="password"]').first()).to.exist
@@ -19,45 +20,54 @@ describe('Launchpad', function () {
it('should allow for creation of the first admin user', async function () {
// Load the launchpad page
const initialPageResponse = await user.request.get('/launchpad')
expect(initialPageResponse.statusCode).to.equal(200)
const $ = cheerio.load(initialPageResponse.body)
const initialPageResponse = await user.fetch('/launchpad')
expect(initialPageResponse.status).to.equal(200)
const initialPageBody = await initialPageResponse.text()
const $ = cheerio.load(initialPageBody)
expect($('h2').first().text()).to.equal('Create the first Admin account')
expect($('form[name="email"]').first()).to.exist
expect($('form[name="password"]').first()).to.exist
// Submit the form
let csrfToken = await user.getCsrfToken()
const postResponse = await user.request.post({
url: '/launchpad/register_admin',
json: {
const postResponse = await user.fetch('/launchpad/register_admin', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
body: JSON.stringify({
_csrf: csrfToken,
email: adminEmail,
password: adminPassword,
},
}),
})
expect(postResponse.statusCode).to.equal(200)
expect(postResponse.body).to.deep.equal({ redir: '/launchpad' })
expect(postResponse.status).to.equal(200)
const postBody = await postResponse.json()
expect(postBody).to.deep.equal({ redir: '/launchpad' })
// Try to load the page again
const secondPageResponse = await user.request.get('/launchpad', {
simple: false,
})
expect(secondPageResponse.statusCode).to.equal(302)
expect(secondPageResponse.headers.location).to.equal('/login')
const secondPageResponse = await user.fetch('/launchpad')
expect(secondPageResponse.status).to.equal(302)
expect(secondPageResponse.headers.get('location')).to.equal(
UserHelper.url('/login').toString()
)
// Forbid submitting the form again
csrfToken = await user.getCsrfToken()
const badPostResponse = await user.request.post({
url: '/launchpad/register_admin',
json: {
const badPostResponse = await user.fetch('/launchpad/register_admin', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
body: JSON.stringify({
_csrf: csrfToken,
email: adminEmail + '1',
password: adminPassword + '1',
},
simple: false,
}),
})
expect(badPostResponse.statusCode).to.equal(403)
expect(badPostResponse.status).to.equal(403)
// Log in as this new admin user
const adminUser = await UserHelper.loginUser({