Files
overleaf-cep/services/web/modules/launchpad/test/acceptance/src/LaunchpadTests.mjs
T
Jakob Ackermann 425e7b1e5b [web] enable mongo notablescan in CI (#29501)
* [monorepo] record ERROR/FATAL log messages in junit report

* [web] put SaaS specific code behind feature flag

* [web] use split test cache for getting user assignments

The unit tests needed updating as they did not replicate any of the
 mongo filtering. The acceptance tests cover this logic.

* [web] make better use of existing indexes

* [web] avoid col-scan in tests of notifications module

* [web] remove cleanup of empty feedbacks collection

* [web] add assertion for reason of rejected request in launchpad test

* [web] add missing indexes

* [web] enable mongo notablescan

* [web] make emailNotifications tests compatible with notablescan

GitOrigin-RevId: b888f2feeb3a0e915f068ae1c4ea23ec17821221
2026-01-13 09:06:38 +00:00

87 lines
3.0 KiB
JavaScript

import { expect } from 'chai'
import cheerio from 'cheerio'
import UserHelper from '../../../../../test/acceptance/src/helpers/UserHelper.mjs'
describe('Launchpad', function () {
const adminEmail = 'admin@example.com'
const adminPassword = 'adreadfulsecret'
const user = new UserHelper()
it('should show the launchpad page', async function () {
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
})
it('should allow for creation of the first admin user', async function () {
// Load the launchpad page
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.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.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.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.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',
}),
})
expect(badPostResponse.status).to.equal(403)
expect(await badPostResponse.json()).to.deep.equal({
message: { type: 'error', text: 'admin user already exists' },
})
// Log in as this new admin user
const adminUser = await UserHelper.loginUser({
email: adminEmail,
password: adminPassword,
})
// Check we are actually admin
expect(await adminUser.isLoggedIn()).to.equal(true)
expect(adminUser.user.isAdmin).to.equal(true)
// Check reversedHostName is stored
expect(adminUser.user.emails[0].reversedHostname).to.equal('moc.elpmaxe')
})
})