From d1ab89deb79f70c439b58750d044d9cadf1194e5 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 11 Jun 2019 11:54:33 +0200 Subject: Handle email update on server --- server/tests/api/users/users-verification.ts | 59 ++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 3 deletions(-) (limited to 'server/tests/api/users') diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts index 3b37a26cf..b8fa1430b 100644 --- a/server/tests/api/users/users-verification.ts +++ b/server/tests/api/users/users-verification.ts @@ -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, { -- cgit v1.2.3