X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fusers%2Fusers-verification.ts;h=e05acdd7294dc433762c2e8917b252fd225ef55c;hb=59fd824cf3434a8417b73230f1840fed327e3495;hp=fa5f5e3717394dc39d85c11a32b2d8c71b06297b;hpb=d9eaee3939bf2e93e5d775d32bce77842201faba;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts index fa5f5e371..e05acdd72 100644 --- a/server/tests/api/users/users-verification.ts +++ b/server/tests/api/users/users-verification.ts @@ -1,20 +1,31 @@ -/* tslint:disable:no-unused-expression */ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import * as chai from 'chai' import 'mocha' import { - registerUser, flushTests, getUserInformation, getMyUserInformation, killallServers, - userLogin, login, runServer, ServerInfo, verifyEmail, updateCustomSubConfig -} from '../../utils' -import { setAccessTokensToServers } from '../../utils/users/login' -import { mockSmtpServer } from '../../utils/miscs/email' -import { waitJobs } from '../../utils/server/jobs' + 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 = { @@ -30,22 +41,22 @@ describe('Test users account verification', function () { before(async function () { this.timeout(30000) - await mockSmtpServer(emails) - - await flushTests() + const port = await MockSmtpServer.Instance.collectEmails(emails) const overrideConfig = { smtp: { - hostname: 'localhost' + hostname: 'localhost', + port } } - server = await runServer(1, overrideConfig) + server = await flushAndRunServer(1, overrideConfig) await setAccessTokensToServers([ server ]) }) it('Should register user and send verification email if verification required', async function () { - this.timeout(5000) + this.timeout(30000) + await updateCustomSubConfig(server.url, server.accessToken, { signup: { enabled: true, @@ -84,11 +95,54 @@ 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', + currentPassword: user1.password + }) + + 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, { @@ -123,11 +177,8 @@ describe('Test users account verification', function () { }) after(async function () { - killallServers([ server ]) + MockSmtpServer.Instance.kill() - // Keep the logs if the test failed - if (this[ 'ok' ]) { - await flushTests() - } + await cleanupTests([ server ]) }) })