|
@@ -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, {
|