aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/users
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-06-11 11:54:33 +0200
committerChocobozzz <me@florianbigard.com>2019-06-11 14:31:11 +0200
commitd1ab89deb79f70c439b58750d044d9cadf1194e5 (patch)
tree3cd18a0a8a3bf7497aec9d803c759bf54656115c /server/tests/api/users
parentfff77ba23191f9bca959d5989a1f1df331dbac0b (diff)
downloadPeerTube-d1ab89deb79f70c439b58750d044d9cadf1194e5.tar.gz
PeerTube-d1ab89deb79f70c439b58750d044d9cadf1194e5.tar.zst
PeerTube-d1ab89deb79f70c439b58750d044d9cadf1194e5.zip
Handle email update on server
Diffstat (limited to 'server/tests/api/users')
-rw-r--r--server/tests/api/users/users-verification.ts59
1 files changed, 56 insertions, 3 deletions
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 @@
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { 5import {
6 registerUser, flushTests, getUserInformation, getMyUserInformation, killallServers, 6 cleanupTests,
7 userLogin, login, flushAndRunServer, ServerInfo, verifyEmail, updateCustomSubConfig, wait, cleanupTests 7 flushAndRunServer,
8 getMyUserInformation,
9 getUserInformation,
10 login,
11 registerUser,
12 ServerInfo,
13 updateCustomSubConfig,
14 updateMyUser,
15 userLogin,
16 verifyEmail
8} from '../../../../shared/extra-utils' 17} from '../../../../shared/extra-utils'
9import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' 18import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
10import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' 19import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
11import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 20import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
21import { User } from '../../../../shared/models/users'
12 22
13const expect = chai.expect 23const expect = chai.expect
14 24
15describe('Test users account verification', function () { 25describe('Test users account verification', function () {
16 let server: ServerInfo 26 let server: ServerInfo
17 let userId: number 27 let userId: number
28 let userAccessToken: string
18 let verificationString: string 29 let verificationString: string
19 let expectedEmailsLength = 0 30 let expectedEmailsLength = 0
20 const user1 = { 31 const user1 = {
@@ -83,11 +94,53 @@ describe('Test users account verification', function () {
83 94
84 it('Should verify the user via email and allow login', async function () { 95 it('Should verify the user via email and allow login', async function () {
85 await verifyEmail(server.url, userId, verificationString) 96 await verifyEmail(server.url, userId, verificationString)
86 await login(server.url, server.client, user1) 97
98 const res = await login(server.url, server.client, user1)
99 userAccessToken = res.body.access_token
100
87 const resUserVerified = await getUserInformation(server.url, server.accessToken, userId) 101 const resUserVerified = await getUserInformation(server.url, server.accessToken, userId)
88 expect(resUserVerified.body.emailVerified).to.be.true 102 expect(resUserVerified.body.emailVerified).to.be.true
89 }) 103 })
90 104
105 it('Should be able to change the user email', async function () {
106 let updateVerificationString: string
107
108 {
109 await updateMyUser({
110 url: server.url,
111 accessToken: userAccessToken,
112 email: 'updated@example.com'
113 })
114
115 await waitJobs(server)
116 expectedEmailsLength++
117 expect(emails).to.have.lengthOf(expectedEmailsLength)
118
119 const email = emails[expectedEmailsLength - 1]
120
121 const verificationStringMatches = /verificationString=([a-z0-9]+)/.exec(email['text'])
122 updateVerificationString = verificationStringMatches[1]
123 }
124
125 {
126 const res = await getMyUserInformation(server.url, userAccessToken)
127 const me: User = res.body
128
129 expect(me.email).to.equal('user_1@example.com')
130 expect(me.pendingEmail).to.equal('updated@example.com')
131 }
132
133 {
134 await verifyEmail(server.url, userId, updateVerificationString, true)
135
136 const res = await getMyUserInformation(server.url, userAccessToken)
137 const me: User = res.body
138
139 expect(me.email).to.equal('updated@example.com')
140 expect(me.pendingEmail).to.be.null
141 }
142 })
143
91 it('Should register user not requiring email verification if setting not enabled', async function () { 144 it('Should register user not requiring email verification if setting not enabled', async function () {
92 this.timeout(5000) 145 this.timeout(5000)
93 await updateCustomSubConfig(server.url, server.accessToken, { 146 await updateCustomSubConfig(server.url, server.accessToken, {