mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
[web] Update tests to add emails with 6-digits flow (#27076)
* In tests, post to `/user/emails/secondary` (6-digits) instead of the deprecated `/user/emails` (link-token) * Update `addEmailAndConfirm` so it calls the right endpoint * Remove unnecessary `userId` from `confirmEmail` and `addEmailAndConfirm` args * Use `updateUser` to add unconfirmed email to user * Confirm, then unconfirm emails, in order to test on unconfirmed emails * Lowercase emails in `unconfirmSecondaryEmail`, so they get matched correctly * Update UserEmailsTests.mjs with 6-digits flow, fetch, no `npm:async` GitOrigin-RevId: 71b9ed65daebea5f22272240559caab375515f0c
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user