diff --git a/services/web/test/acceptance/src/PrimaryEmailCheckTests.mjs b/services/web/test/acceptance/src/PrimaryEmailCheckTests.mjs index 1598373f34..bc85f96a5d 100644 --- a/services/web/test/acceptance/src/PrimaryEmailCheckTests.mjs +++ b/services/web/test/acceptance/src/PrimaryEmailCheckTests.mjs @@ -69,10 +69,7 @@ describe('PrimaryEmailCheck', function () { $set: { lastPrimaryEmailCheck: new Date(time) }, }) - await userHelper.confirmEmail( - userHelper.user._id, - userHelper.user.email - ) + await userHelper.confirmEmail(userHelper.user.email) }) it("shouldn't be redirected from project list to the primary email check page", async function () { @@ -153,10 +150,7 @@ describe('PrimaryEmailCheck', function () { $set: { lastPrimaryEmailCheck: new Date(time) }, }) - await userHelper.confirmEmail( - userHelper.user._id, - userHelper.user.email - ) + await userHelper.confirmEmail(userHelper.user.email) }) it("shouldn't be redirected from project list to the primary email check page", async function () { @@ -219,14 +213,8 @@ describe('PrimaryEmailCheck', function () { }) beforeEach(async function () { - await userHelper.confirmEmail( - userHelper.user._id, - userHelper.user.email - ) - await userHelper.addEmailAndConfirm( - userHelper.user._id, - 'secondary@overleaf.com' - ) + await userHelper.confirmEmail(userHelper.user.email) + await userHelper.addEmailAndConfirm('secondary@overleaf.com') checkResponse = await userHelper.fetch( '/user/emails/primary-email-check', diff --git a/services/web/test/acceptance/src/helpers/UserHelper.mjs b/services/web/test/acceptance/src/helpers/UserHelper.mjs index 951dccaf2b..05fef85604 100644 --- a/services/web/test/acceptance/src/helpers/UserHelper.mjs +++ b/services/web/test/acceptance/src/helpers/UserHelper.mjs @@ -162,7 +162,7 @@ class UserHelper { /** * - * @param {'pendingExistingEmail'|'pendingUserRegistration'}sessionKey + * @param {'pendingExistingEmail'|'pendingUserRegistration'|'pendingSecondaryEmail'}sessionKey * @return {Promise<*>} */ async getEmailConfirmationCode(sessionKey) { @@ -431,16 +431,16 @@ class UserHelper { } async addEmail(email) { - const response = await this.fetch('/user/emails', { + const response = await this.fetch('/user/emails/secondary', { method: 'POST', body: new URLSearchParams([['email', email]]), }) await throwIfErrorResponse(response) } - async addEmailAndConfirm(userId, email) { + async addEmailAndConfirm(email) { await this.addEmail(email) - await this.confirmEmail(userId, email) + await this.confirmSecondaryEmail() } async changeConfirmationDate(userId, email, date) { @@ -499,9 +499,9 @@ class UserHelper { await this.changeConfirmationDate(userId, email, date) } - async confirmEmail(userId, email) { + async confirmEmail(email) { // clear ratelimiting on resend confirmation endpoint - await rateLimiters.sendConfirmation.delete(userId) + await rateLimiters.sendConfirmation.delete(this.user._id) const requestConfirmationCode = await this.fetch( '/user/emails/send-confirmation-code', { @@ -517,6 +517,25 @@ class UserHelper { }) await throwIfErrorResponse(requestConfirmCode) } + + async confirmSecondaryEmail() { + const code = await this.getEmailConfirmationCode('pendingSecondaryEmail') + const requestConfirmCode = await this.fetch( + '/user/emails/confirm-secondary', + { + method: 'POST', + body: new URLSearchParams({ code }), + } + ) + await throwIfErrorResponse(requestConfirmCode) + } + + async unconfirmEmail(email) { + await UserUpdater.promises.updateUser( + { _id: this.user._id, 'emails.email': email.toLowerCase() }, + { $unset: { 'emails.$.confirmedAt': 1, 'emails.$.reconfirmedAt': 1 } } + ) + } } export default UserHelper