mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-05 02:39:33 +02:00
Handle email update on server
This commit is contained in:
parent
fff77ba231
commit
d1ab89deb7
12 changed files with 164 additions and 30 deletions
|
@ -3,18 +3,29 @@
|
|||
import * as chai from 'chai'
|
||||
import 'mocha'
|
||||
import {
|
||||
registerUser, flushTests, getUserInformation, getMyUserInformation, killallServers,
|
||||
userLogin, login, flushAndRunServer, ServerInfo, verifyEmail, updateCustomSubConfig, wait, cleanupTests
|
||||
cleanupTests,
|
||||
flushAndRunServer,
|
||||
getMyUserInformation,
|
||||
getUserInformation,
|
||||
login,
|
||||
registerUser,
|
||||
ServerInfo,
|
||||
updateCustomSubConfig,
|
||||
updateMyUser,
|
||||
userLogin,
|
||||
verifyEmail
|
||||
} from '../../../../shared/extra-utils'
|
||||
import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
|
||||
import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
|
||||
import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
|
||||
import { User } from '../../../../shared/models/users'
|
||||
|
||||
const expect = chai.expect
|
||||
|
||||
describe('Test users account verification', function () {
|
||||
let server: ServerInfo
|
||||
let userId: number
|
||||
let userAccessToken: string
|
||||
let verificationString: string
|
||||
let expectedEmailsLength = 0
|
||||
const user1 = {
|
||||
|
@ -83,11 +94,53 @@ describe('Test users account verification', function () {
|
|||
|
||||
it('Should verify the user via email and allow login', async function () {
|
||||
await verifyEmail(server.url, userId, verificationString)
|
||||
await login(server.url, server.client, user1)
|
||||
|
||||
const res = await login(server.url, server.client, user1)
|
||||
userAccessToken = res.body.access_token
|
||||
|
||||
const resUserVerified = await getUserInformation(server.url, server.accessToken, userId)
|
||||
expect(resUserVerified.body.emailVerified).to.be.true
|
||||
})
|
||||
|
||||
it('Should be able to change the user email', async function () {
|
||||
let updateVerificationString: string
|
||||
|
||||
{
|
||||
await updateMyUser({
|
||||
url: server.url,
|
||||
accessToken: userAccessToken,
|
||||
email: 'updated@example.com'
|
||||
})
|
||||
|
||||
await waitJobs(server)
|
||||
expectedEmailsLength++
|
||||
expect(emails).to.have.lengthOf(expectedEmailsLength)
|
||||
|
||||
const email = emails[expectedEmailsLength - 1]
|
||||
|
||||
const verificationStringMatches = /verificationString=([a-z0-9]+)/.exec(email['text'])
|
||||
updateVerificationString = verificationStringMatches[1]
|
||||
}
|
||||
|
||||
{
|
||||
const res = await getMyUserInformation(server.url, userAccessToken)
|
||||
const me: User = res.body
|
||||
|
||||
expect(me.email).to.equal('user_1@example.com')
|
||||
expect(me.pendingEmail).to.equal('updated@example.com')
|
||||
}
|
||||
|
||||
{
|
||||
await verifyEmail(server.url, userId, updateVerificationString, true)
|
||||
|
||||
const res = await getMyUserInformation(server.url, userAccessToken)
|
||||
const me: User = res.body
|
||||
|
||||
expect(me.email).to.equal('updated@example.com')
|
||||
expect(me.pendingEmail).to.be.null
|
||||
}
|
||||
})
|
||||
|
||||
it('Should register user not requiring email verification if setting not enabled', async function () {
|
||||
this.timeout(5000)
|
||||
await updateCustomSubConfig(server.url, server.accessToken, {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue