diff options
Diffstat (limited to 'server/tests/api/users')
-rw-r--r-- | server/tests/api/users/users-verification.ts | 59 |
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 @@ | |||
3 | import * as chai from 'chai' | 3 | import * as chai from 'chai' |
4 | import 'mocha' | 4 | import 'mocha' |
5 | import { | 5 | import { |
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' |
9 | import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' | 18 | import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' |
10 | import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' | 19 | import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email' |
11 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | 20 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' |
21 | import { User } from '../../../../shared/models/users' | ||
12 | 22 | ||
13 | const expect = chai.expect | 23 | const expect = chai.expect |
14 | 24 | ||
15 | describe('Test users account verification', function () { | 25 | describe('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, { |