aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/users/users-verification.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-13 14:23:01 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:18 +0200
commit7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0 (patch)
tree7a166515e4d57a06eb3c08be569f106ed049988b /server/tests/api/users/users-verification.ts
parentd0a0fa429d4651710ed951a3c11af0219e408964 (diff)
downloadPeerTube-7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0.tar.gz
PeerTube-7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0.tar.zst
PeerTube-7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0.zip
Introduce user command
Diffstat (limited to 'server/tests/api/users/users-verification.ts')
-rw-r--r--server/tests/api/users/users-verification.ts48
1 files changed, 15 insertions, 33 deletions
diff --git a/server/tests/api/users/users-verification.ts b/server/tests/api/users/users-verification.ts
index ade730323..271aa3c7a 100644
--- a/server/tests/api/users/users-verification.ts
+++ b/server/tests/api/users/users-verification.ts
@@ -3,20 +3,7 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { HttpStatusCode } from '@shared/core-utils' 5import { HttpStatusCode } from '@shared/core-utils'
6import { 6import { cleanupTests, flushAndRunServer, MockSmtpServer, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
7 cleanupTests,
8 flushAndRunServer,
9 getMyUserInformation,
10 getUserInformation,
11 MockSmtpServer,
12 registerUser,
13 ServerInfo,
14 setAccessTokensToServers,
15 updateMyUser,
16 verifyEmail,
17 waitJobs
18} from '@shared/extra-utils'
19import { User } from '@shared/models'
20 7
21const expect = chai.expect 8const expect = chai.expect
22 9
@@ -65,7 +52,7 @@ describe('Test users account verification', function () {
65 } 52 }
66 }) 53 })
67 54
68 await registerUser(server.url, user1.username, user1.password) 55 await server.usersCommand.register(user1)
69 56
70 await waitJobs(server) 57 await waitJobs(server)
71 expectedEmailsLength++ 58 expectedEmailsLength++
@@ -84,8 +71,8 @@ describe('Test users account verification', function () {
84 71
85 userId = parseInt(userIdMatches[1], 10) 72 userId = parseInt(userIdMatches[1], 10)
86 73
87 const resUserInfo = await getUserInformation(server.url, server.accessToken, userId) 74 const body = await server.usersCommand.get({ userId })
88 expect(resUserInfo.body.emailVerified).to.be.false 75 expect(body.emailVerified).to.be.false
89 }) 76 })
90 77
91 it('Should not allow login for user with unverified email', async function () { 78 it('Should not allow login for user with unverified email', async function () {
@@ -94,13 +81,13 @@ describe('Test users account verification', function () {
94 }) 81 })
95 82
96 it('Should verify the user via email and allow login', async function () { 83 it('Should verify the user via email and allow login', async function () {
97 await verifyEmail(server.url, userId, verificationString) 84 await server.usersCommand.verifyEmail({ userId, verificationString })
98 85
99 const body = await server.loginCommand.login({ user: user1 }) 86 const body = await server.loginCommand.login({ user: user1 })
100 userAccessToken = body.access_token 87 userAccessToken = body.access_token
101 88
102 const resUserVerified = await getUserInformation(server.url, server.accessToken, userId) 89 const user = await server.usersCommand.get({ userId })
103 expect(resUserVerified.body.emailVerified).to.be.true 90 expect(user.emailVerified).to.be.true
104 }) 91 })
105 92
106 it('Should be able to change the user email', async function () { 93 it('Should be able to change the user email', async function () {
@@ -109,9 +96,8 @@ describe('Test users account verification', function () {
109 let updateVerificationString: string 96 let updateVerificationString: string
110 97
111 { 98 {
112 await updateMyUser({ 99 await server.usersCommand.updateMe({
113 url: server.url, 100 token: userAccessToken,
114 accessToken: userAccessToken,
115 email: 'updated@example.com', 101 email: 'updated@example.com',
116 currentPassword: user1.password 102 currentPassword: user1.password
117 }) 103 })
@@ -127,19 +113,15 @@ describe('Test users account verification', function () {
127 } 113 }
128 114
129 { 115 {
130 const res = await getMyUserInformation(server.url, userAccessToken) 116 const me = await server.usersCommand.getMyInfo({ token: userAccessToken })
131 const me: User = res.body
132
133 expect(me.email).to.equal('user_1@example.com') 117 expect(me.email).to.equal('user_1@example.com')
134 expect(me.pendingEmail).to.equal('updated@example.com') 118 expect(me.pendingEmail).to.equal('updated@example.com')
135 } 119 }
136 120
137 { 121 {
138 await verifyEmail(server.url, userId, updateVerificationString, true) 122 await server.usersCommand.verifyEmail({ userId, verificationString: updateVerificationString, isPendingEmail: true })
139
140 const res = await getMyUserInformation(server.url, userAccessToken)
141 const me: User = res.body
142 123
124 const me = await server.usersCommand.getMyInfo({ token: userAccessToken })
143 expect(me.email).to.equal('updated@example.com') 125 expect(me.email).to.equal('updated@example.com')
144 expect(me.pendingEmail).to.be.null 126 expect(me.pendingEmail).to.be.null
145 } 127 }
@@ -157,15 +139,15 @@ describe('Test users account verification', function () {
157 } 139 }
158 }) 140 })
159 141
160 await registerUser(server.url, user2.username, user2.password) 142 await server.usersCommand.register(user2)
161 143
162 await waitJobs(server) 144 await waitJobs(server)
163 expect(emails).to.have.lengthOf(expectedEmailsLength) 145 expect(emails).to.have.lengthOf(expectedEmailsLength)
164 146
165 const accessToken = await server.loginCommand.getAccessToken(user2) 147 const accessToken = await server.loginCommand.getAccessToken(user2)
166 148
167 const resMyUserInfo = await getMyUserInformation(server.url, accessToken) 149 const user = await server.usersCommand.getMyInfo({ token: accessToken })
168 expect(resMyUserInfo.body.emailVerified).to.be.null 150 expect(user.emailVerified).to.be.null
169 }) 151 })
170 152
171 it('Should allow login for user with unverified email when setting later enabled', async function () { 153 it('Should allow login for user with unverified email when setting later enabled', async function () {