mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-25 10:10:08 +02:00
* added primary-email-check page, route and controllers * add `#add-email` internal link in settings to display new email form * added primary-email-check redirection with split test * update `lastPrimaryEmailCheck` when the default email address is set * added `lastPrimaryCheck` to admin panel * translations for primary-email-check * acceptance tests for primary-email-check * [web] multi-submit for primary email check * Using `confirmedAt` to prevent from displaying primary-email-check page Co-authored-by: Jakob Ackermann <jakob.ackermann@overleaf.com> Co-Authored-By: Miguel Serrano <mserranom@gmail.com> GitOrigin-RevId: d8e3a280439da08038a4487d8bfd7b3b0596e3b5
163 lines
5.9 KiB
JavaScript
163 lines
5.9 KiB
JavaScript
const UserHelper = require('./helpers/UserHelper')
|
|
const Settings = require('@overleaf/settings')
|
|
const { expect } = require('chai')
|
|
|
|
// While the split test is in progress this must be appended to URLs during tests
|
|
const SPLIT_TEST_QUERY = '?primary-email-check=active'
|
|
|
|
describe('PrimaryEmailCheck', function () {
|
|
let userHelper
|
|
|
|
beforeEach(async function () {
|
|
userHelper = await UserHelper.createUser()
|
|
userHelper = await UserHelper.loginUser(
|
|
userHelper.getDefaultEmailPassword()
|
|
)
|
|
})
|
|
|
|
describe('redirections', function () {
|
|
describe('when the user has signed up recently', function () {
|
|
it("shouldn't be redirected from project list to the primary email check page", async function () {
|
|
const response = await userHelper.request.get(
|
|
'/project' + SPLIT_TEST_QUERY
|
|
)
|
|
expect(response.statusCode).to.equal(200)
|
|
})
|
|
|
|
it('should be redirected from the primary email check page to the project list', async function () {
|
|
const response = await userHelper.request.get(
|
|
'/user/emails/primary-email-check' + SPLIT_TEST_QUERY,
|
|
{ simple: false }
|
|
)
|
|
expect(response.statusCode).to.equal(302)
|
|
expect(response.headers.location).to.equal('/project')
|
|
})
|
|
})
|
|
|
|
describe('when the user has checked their email recently', function () {
|
|
beforeEach(async function () {
|
|
const time = Date.now() - Settings.primary_email_check_expiration * 0.5
|
|
await UserHelper.updateUser(userHelper.user._id, {
|
|
$set: { lastPrimaryEmailCheck: new Date(time) },
|
|
})
|
|
})
|
|
|
|
it("shouldn't be redirected from project list to the primary email check page", async function () {
|
|
const response = await userHelper.request.get(
|
|
'/project' + SPLIT_TEST_QUERY
|
|
)
|
|
expect(response.statusCode).to.equal(200)
|
|
})
|
|
|
|
it('should be redirected from the primary email check page to the project list', async function () {
|
|
const response = await userHelper.request.get(
|
|
'/user/emails/primary-email-check' + SPLIT_TEST_QUERY,
|
|
{ simple: false }
|
|
)
|
|
expect(response.statusCode).to.equal(302)
|
|
expect(response.headers.location).to.equal('/project')
|
|
})
|
|
})
|
|
|
|
describe('when the user has confirmed their primary email recently', function () {
|
|
beforeEach(async function () {
|
|
// the user should check again their email according to `lastPrimaryEmailCheck` timestamp, but the behaviour is
|
|
// overridden by email confirmation
|
|
const time = Date.now() - Settings.primary_email_check_expiration * 2
|
|
await UserHelper.updateUser(userHelper.user._id, {
|
|
$set: { lastPrimaryEmailCheck: new Date(time) },
|
|
})
|
|
|
|
await userHelper.confirmEmail(
|
|
userHelper.user._id,
|
|
userHelper.user.email
|
|
)
|
|
})
|
|
|
|
it("shouldn't be redirected from project list to the primary email check page", async function () {
|
|
const response = await userHelper.request.get(
|
|
'/project' + SPLIT_TEST_QUERY
|
|
)
|
|
expect(response.statusCode).to.equal(200)
|
|
})
|
|
|
|
it('should be redirected from the primary email check page to the project list', async function () {
|
|
const response = await userHelper.request.get(
|
|
'/user/emails/primary-email-check' + SPLIT_TEST_QUERY,
|
|
{ simple: false }
|
|
)
|
|
expect(response.statusCode).to.equal(302)
|
|
expect(response.headers.location).to.equal('/project')
|
|
})
|
|
})
|
|
|
|
describe('when the user has signed for longer than the email check expiration period', function () {
|
|
beforeEach(async function () {
|
|
const time = Date.now() - Settings.primary_email_check_expiration * 2
|
|
await UserHelper.updateUser(userHelper.user._id, {
|
|
$set: { lastPrimaryEmailCheck: new Date(time) },
|
|
})
|
|
})
|
|
|
|
it('should be redirected from project list to the primary email check page', async function () {
|
|
const response = await userHelper.request.get(
|
|
'/project' + SPLIT_TEST_QUERY,
|
|
{ simple: false }
|
|
)
|
|
expect(response.statusCode).to.equal(302)
|
|
expect(response.headers.location).to.equal(
|
|
'/user/emails/primary-email-check'
|
|
)
|
|
})
|
|
|
|
it('can visit the primary email check page', async function () {
|
|
const response = await userHelper.request.get(
|
|
'/user/emails/primary-email-check'
|
|
)
|
|
expect(response.statusCode).to.equal(200)
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('when user checks their primary email address', function () {
|
|
let checkResponse
|
|
|
|
beforeEach(async function () {
|
|
// make sure the user requires checking their primary email address
|
|
const time = Date.now() - Settings.primary_email_check_expiration * 2
|
|
await UserHelper.updateUser(userHelper.user._id, {
|
|
$set: { lastPrimaryEmailCheck: new Date(time) },
|
|
})
|
|
|
|
checkResponse = await userHelper.request.post(
|
|
'/user/emails/primary-email-check' + SPLIT_TEST_QUERY,
|
|
{
|
|
form: {},
|
|
simple: false,
|
|
}
|
|
)
|
|
})
|
|
|
|
it('should be redirected to the project list page', function () {
|
|
expect(checkResponse.statusCode).to.equal(302)
|
|
expect(checkResponse.headers.location).to.equal('/project')
|
|
})
|
|
|
|
it("shouldn't be redirected from project list to the primary email check page any longer", async function () {
|
|
const response = await userHelper.request.get(
|
|
'/project' + SPLIT_TEST_QUERY
|
|
)
|
|
expect(response.statusCode).to.equal(200)
|
|
})
|
|
|
|
it('visiting the primary email check page should redirect to the project list page', async function () {
|
|
const response = await userHelper.request.get(
|
|
'/user/emails/primary-email-check',
|
|
{ simple: false }
|
|
)
|
|
expect(response.statusCode).to.equal(302)
|
|
expect(response.headers.location).to.equal('/project')
|
|
})
|
|
})
|
|
})
|