diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-13 14:23:01 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-20 15:27:18 +0200 |
commit | 7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0 (patch) | |
tree | 7a166515e4d57a06eb3c08be569f106ed049988b /server/tests/api/server/email.ts | |
parent | d0a0fa429d4651710ed951a3c11af0219e408964 (diff) | |
download | PeerTube-7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0.tar.gz PeerTube-7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0.tar.zst PeerTube-7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0.zip |
Introduce user command
Diffstat (limited to 'server/tests/api/server/email.ts')
-rw-r--r-- | server/tests/api/server/email.ts | 73 |
1 files changed, 43 insertions, 30 deletions
diff --git a/server/tests/api/server/email.ts b/server/tests/api/server/email.ts index c64c120e3..422db6ceb 100644 --- a/server/tests/api/server/email.ts +++ b/server/tests/api/server/email.ts | |||
@@ -2,23 +2,16 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import * as chai from 'chai' | 4 | import * as chai from 'chai' |
5 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | 5 | import { HttpStatusCode } from '@shared/core-utils' |
6 | import { | 6 | import { |
7 | askResetPassword, | ||
8 | askSendVerifyEmail, | ||
9 | blockUser, | ||
10 | cleanupTests, | 7 | cleanupTests, |
11 | createUser, | ||
12 | flushAndRunServer, | 8 | flushAndRunServer, |
13 | resetPassword, | 9 | MockSmtpServer, |
14 | ServerInfo, | 10 | ServerInfo, |
15 | setAccessTokensToServers, | 11 | setAccessTokensToServers, |
16 | unblockUser, | ||
17 | uploadVideo, | 12 | uploadVideo, |
18 | verifyEmail | 13 | waitJobs |
19 | } from '../../../../shared/extra-utils' | 14 | } from '@shared/extra-utils' |
20 | import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email' | ||
21 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | ||
22 | 15 | ||
23 | const expect = chai.expect | 16 | const expect = chai.expect |
24 | 17 | ||
@@ -58,8 +51,8 @@ describe('Test emails', function () { | |||
58 | await setAccessTokensToServers([ server ]) | 51 | await setAccessTokensToServers([ server ]) |
59 | 52 | ||
60 | { | 53 | { |
61 | const res = await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) | 54 | const created = await server.usersCommand.create({ username: user.username, password: user.password }) |
62 | userId = res.body.user.id | 55 | userId = created.id |
63 | 56 | ||
64 | userAccessToken = await server.loginCommand.getAccessToken(user) | 57 | userAccessToken = await server.loginCommand.getAccessToken(user) |
65 | } | 58 | } |
@@ -87,7 +80,7 @@ describe('Test emails', function () { | |||
87 | it('Should ask to reset the password', async function () { | 80 | it('Should ask to reset the password', async function () { |
88 | this.timeout(10000) | 81 | this.timeout(10000) |
89 | 82 | ||
90 | await askResetPassword(server.url, 'user_1@example.com') | 83 | await server.usersCommand.askResetPassword({ email: 'user_1@example.com' }) |
91 | 84 | ||
92 | await waitJobs(server) | 85 | await waitJobs(server) |
93 | expect(emails).to.have.lengthOf(1) | 86 | expect(emails).to.have.lengthOf(1) |
@@ -113,15 +106,25 @@ describe('Test emails', function () { | |||
113 | }) | 106 | }) |
114 | 107 | ||
115 | it('Should not reset the password with an invalid verification string', async function () { | 108 | it('Should not reset the password with an invalid verification string', async function () { |
116 | await resetPassword(server.url, userId, verificationString + 'b', 'super_password2', HttpStatusCode.FORBIDDEN_403) | 109 | await server.usersCommand.resetPassword({ |
110 | userId, | ||
111 | verificationString: verificationString + 'b', | ||
112 | password: 'super_password2', | ||
113 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | ||
114 | }) | ||
117 | }) | 115 | }) |
118 | 116 | ||
119 | it('Should reset the password', async function () { | 117 | it('Should reset the password', async function () { |
120 | await resetPassword(server.url, userId, verificationString, 'super_password2') | 118 | await server.usersCommand.resetPassword({ userId, verificationString, password: 'super_password2' }) |
121 | }) | 119 | }) |
122 | 120 | ||
123 | it('Should not reset the password with the same verification string', async function () { | 121 | it('Should not reset the password with the same verification string', async function () { |
124 | await resetPassword(server.url, userId, verificationString, 'super_password3', HttpStatusCode.FORBIDDEN_403) | 122 | await server.usersCommand.resetPassword({ |
123 | userId, | ||
124 | verificationString, | ||
125 | password: 'super_password3', | ||
126 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | ||
127 | }) | ||
125 | }) | 128 | }) |
126 | 129 | ||
127 | it('Should login with this new password', async function () { | 130 | it('Should login with this new password', async function () { |
@@ -132,15 +135,11 @@ describe('Test emails', function () { | |||
132 | }) | 135 | }) |
133 | 136 | ||
134 | describe('When creating a user without password', function () { | 137 | describe('When creating a user without password', function () { |
138 | |||
135 | it('Should send a create password email', async function () { | 139 | it('Should send a create password email', async function () { |
136 | this.timeout(10000) | 140 | this.timeout(10000) |
137 | 141 | ||
138 | await createUser({ | 142 | await server.usersCommand.create({ username: 'create_password', password: '' }) |
139 | url: server.url, | ||
140 | accessToken: server.accessToken, | ||
141 | username: 'create_password', | ||
142 | password: '' | ||
143 | }) | ||
144 | 143 | ||
145 | await waitJobs(server) | 144 | await waitJobs(server) |
146 | expect(emails).to.have.lengthOf(2) | 145 | expect(emails).to.have.lengthOf(2) |
@@ -166,11 +165,20 @@ describe('Test emails', function () { | |||
166 | }) | 165 | }) |
167 | 166 | ||
168 | it('Should not reset the password with an invalid verification string', async function () { | 167 | it('Should not reset the password with an invalid verification string', async function () { |
169 | await resetPassword(server.url, userId2, verificationString2 + 'c', 'newly_created_password', HttpStatusCode.FORBIDDEN_403) | 168 | await server.usersCommand.resetPassword({ |
169 | userId: userId2, | ||
170 | verificationString: verificationString2 + 'c', | ||
171 | password: 'newly_created_password', | ||
172 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | ||
173 | }) | ||
170 | }) | 174 | }) |
171 | 175 | ||
172 | it('Should reset the password', async function () { | 176 | it('Should reset the password', async function () { |
173 | await resetPassword(server.url, userId2, verificationString2, 'newly_created_password') | 177 | await server.usersCommand.resetPassword({ |
178 | userId: userId2, | ||
179 | verificationString: verificationString2, | ||
180 | password: 'newly_created_password' | ||
181 | }) | ||
174 | }) | 182 | }) |
175 | 183 | ||
176 | it('Should login with this new password', async function () { | 184 | it('Should login with this new password', async function () { |
@@ -207,7 +215,7 @@ describe('Test emails', function () { | |||
207 | this.timeout(10000) | 215 | this.timeout(10000) |
208 | 216 | ||
209 | const reason = 'my super bad reason' | 217 | const reason = 'my super bad reason' |
210 | await blockUser(server.url, userId, server.accessToken, HttpStatusCode.NO_CONTENT_204, reason) | 218 | await server.usersCommand.banUser({ userId, reason }) |
211 | 219 | ||
212 | await waitJobs(server) | 220 | await waitJobs(server) |
213 | expect(emails).to.have.lengthOf(4) | 221 | expect(emails).to.have.lengthOf(4) |
@@ -225,7 +233,7 @@ describe('Test emails', function () { | |||
225 | it('Should send the notification email when unblocking a user', async function () { | 233 | it('Should send the notification email when unblocking a user', async function () { |
226 | this.timeout(10000) | 234 | this.timeout(10000) |
227 | 235 | ||
228 | await unblockUser(server.url, userId, server.accessToken, HttpStatusCode.NO_CONTENT_204) | 236 | await server.usersCommand.unbanUser({ userId }) |
229 | 237 | ||
230 | await waitJobs(server) | 238 | await waitJobs(server) |
231 | expect(emails).to.have.lengthOf(5) | 239 | expect(emails).to.have.lengthOf(5) |
@@ -288,7 +296,7 @@ describe('Test emails', function () { | |||
288 | it('Should ask to send the verification email', async function () { | 296 | it('Should ask to send the verification email', async function () { |
289 | this.timeout(10000) | 297 | this.timeout(10000) |
290 | 298 | ||
291 | await askSendVerifyEmail(server.url, 'user_1@example.com') | 299 | await server.usersCommand.askSendVerifyEmail({ email: 'user_1@example.com' }) |
292 | 300 | ||
293 | await waitJobs(server) | 301 | await waitJobs(server) |
294 | expect(emails).to.have.lengthOf(8) | 302 | expect(emails).to.have.lengthOf(8) |
@@ -314,11 +322,16 @@ describe('Test emails', function () { | |||
314 | }) | 322 | }) |
315 | 323 | ||
316 | it('Should not verify the email with an invalid verification string', async function () { | 324 | it('Should not verify the email with an invalid verification string', async function () { |
317 | await verifyEmail(server.url, userId, verificationString + 'b', false, HttpStatusCode.FORBIDDEN_403) | 325 | await server.usersCommand.verifyEmail({ |
326 | userId, | ||
327 | verificationString: verificationString + 'b', | ||
328 | isPendingEmail: false, | ||
329 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | ||
330 | }) | ||
318 | }) | 331 | }) |
319 | 332 | ||
320 | it('Should verify the email', async function () { | 333 | it('Should verify the email', async function () { |
321 | await verifyEmail(server.url, userId, verificationString) | 334 | await server.usersCommand.verifyEmail({ userId, verificationString }) |
322 | }) | 335 | }) |
323 | }) | 336 | }) |
324 | 337 | ||