]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/users/users.ts
Use test wrapper exit function
[github/Chocobozzz/PeerTube.git] / server / tests / api / users / users.ts
CommitLineData
0e1dc3e7 1/* tslint:disable:no-unused-expression */
86d13ec2 2
0e1dc3e7 3import * as chai from 'chai'
afffe988 4import 'mocha'
a76138ff 5import { User, UserRole } from '../../../../shared/index'
0e1dc3e7 6import {
a890d1e0 7 blockUser,
7c3b7976 8 cleanupTests,
a890d1e0
C
9 createUser,
10 deleteMe,
7c3b7976 11 flushAndRunServer,
c100a614 12 getAccountRatings,
a890d1e0
C
13 getBlacklistedVideosList,
14 getMyUserInformation,
15 getMyUserVideoQuotaUsed,
16 getMyUserVideoRating,
17 getUserInformation,
18 getUsersList,
19 getUsersListPaginationAndSort,
20 getVideosList,
a890d1e0
C
21 login,
22 makePutBodyRequest,
23 rateVideo,
24 registerUser,
25 removeUser,
26 removeVideo,
a890d1e0
C
27 ServerInfo,
28 testImage,
29 unblockUser,
30 updateMyAvatar,
31 updateMyUser,
32 updateUser,
33 uploadVideo,
34 userLogin
94565d52
C
35} from '../../../../shared/extra-utils'
36import { follow } from '../../../../shared/extra-utils/server/follows'
37import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
38import { getMyVideos } from '../../../../shared/extra-utils/videos/videos'
1eddc9a7 39import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
0e1dc3e7 40
afffe988
C
41const expect = chai.expect
42
0e1dc3e7
C
43describe('Test users', function () {
44 let server: ServerInfo
45 let accessToken: string
46 let accessTokenUser: string
47 let videoId: number
48 let userId: number
f8b8c36b
C
49 const user = {
50 username: 'user_1',
51 password: 'super password'
52 }
0e1dc3e7
C
53
54 before(async function () {
e212f887 55 this.timeout(30000)
210feb6c 56 server = await flushAndRunServer(1)
86d13ec2
C
57
58 await setAccessTokensToServers([ server ])
0e1dc3e7
C
59 })
60
1eddc9a7
C
61 describe('OAuth client', function () {
62 it('Should create a new client')
0e1dc3e7 63
1eddc9a7 64 it('Should return the first client')
0e1dc3e7 65
1eddc9a7 66 it('Should remove the last client')
0e1dc3e7 67
1eddc9a7
C
68 it('Should not login with an invalid client id', async function () {
69 const client = { id: 'client', secret: server.client.secret }
70 const res = await login(server.url, client, server.user, 400)
0e1dc3e7 71
1eddc9a7
C
72 expect(res.body.error).to.contain('client is invalid')
73 })
0e1dc3e7 74
1eddc9a7
C
75 it('Should not login with an invalid client secret', async function () {
76 const client = { id: server.client.id, secret: 'coucou' }
77 const res = await login(server.url, client, server.user, 400)
0e1dc3e7 78
1eddc9a7
C
79 expect(res.body.error).to.contain('client is invalid')
80 })
0e1dc3e7
C
81 })
82
1eddc9a7 83 describe('Login', function () {
0e1dc3e7 84
1eddc9a7
C
85 it('Should not login with an invalid username', async function () {
86 const user = { username: 'captain crochet', password: server.user.password }
87 const res = await login(server.url, server.client, user, 400)
0e1dc3e7 88
1eddc9a7
C
89 expect(res.body.error).to.contain('credentials are invalid')
90 })
0e1dc3e7 91
1eddc9a7
C
92 it('Should not login with an invalid password', async function () {
93 const user = { username: server.user.username, password: 'mew_three' }
94 const res = await login(server.url, server.client, user, 400)
0e1dc3e7 95
1eddc9a7
C
96 expect(res.body.error).to.contain('credentials are invalid')
97 })
0e1dc3e7 98
1eddc9a7
C
99 it('Should not be able to upload a video', async function () {
100 accessToken = 'my_super_token'
0e1dc3e7 101
1eddc9a7
C
102 const videoAttributes = {}
103 await uploadVideo(server.url, accessToken, videoAttributes, 401)
104 })
0e1dc3e7 105
1eddc9a7
C
106 it('Should not be able to follow', async function () {
107 accessToken = 'my_super_token'
108 await follow(server.url, [ 'http://example.com' ], accessToken, 401)
109 })
0e1dc3e7 110
1eddc9a7 111 it('Should not be able to unfollow')
0e1dc3e7 112
1eddc9a7
C
113 it('Should be able to login', async function () {
114 const res = await login(server.url, server.client, server.user, 200)
0e1dc3e7 115
1eddc9a7
C
116 accessToken = res.body.access_token
117 })
0e1dc3e7
C
118 })
119
1eddc9a7 120 describe('Upload', function () {
0e1dc3e7 121
1eddc9a7
C
122 it('Should upload the video with the correct token', async function () {
123 const videoAttributes = {}
124 await uploadVideo(server.url, accessToken, videoAttributes)
125 const res = await getVideosList(server.url)
126 const video = res.body.data[ 0 ]
0e1dc3e7 127
1eddc9a7
C
128 expect(video.account.name).to.equal('root')
129 videoId = video.id
130 })
131
132 it('Should upload the video again with the correct token', async function () {
133 const videoAttributes = {}
134 await uploadVideo(server.url, accessToken, videoAttributes)
135 })
0e1dc3e7
C
136 })
137
1eddc9a7 138 describe('Ratings', function () {
22834691 139
1eddc9a7
C
140 it('Should retrieve a video rating', async function () {
141 await rateVideo(server.url, accessToken, videoId, 'like')
142 const res = await getMyUserVideoRating(server.url, accessToken, videoId)
143 const rating = res.body
c100a614 144
1eddc9a7
C
145 expect(rating.videoId).to.equal(videoId)
146 expect(rating.rating).to.equal('like')
147 })
c100a614 148
1eddc9a7
C
149 it('Should retrieve ratings list', async function () {
150 await rateVideo(server.url, accessToken, videoId, 'like')
22834691 151
1eddc9a7 152 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, 200)
22834691 153 const ratings = res.body
0e1dc3e7 154
1eddc9a7
C
155 expect(ratings.total).to.equal(1)
156 expect(ratings.data[ 0 ].video.id).to.equal(videoId)
157 expect(ratings.data[ 0 ].rating).to.equal('like')
158 })
0e1dc3e7 159
1eddc9a7
C
160 it('Should retrieve ratings list by rating type', async function () {
161 {
162 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'like')
163 const ratings = res.body
164 expect(ratings.data.length).to.equal(1)
165 }
166
167 {
168 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'dislike')
169 const ratings = res.body
170 expect(ratings.data.length).to.equal(0)
171 }
172 })
0e1dc3e7
C
173 })
174
1eddc9a7
C
175 describe('Remove video', function () {
176 it('Should not be able to remove the video with an incorrect token', async function () {
177 await removeVideo(server.url, 'bad_token', videoId, 401)
178 })
0e1dc3e7 179
1eddc9a7 180 it('Should not be able to remove the video with the token of another account')
0e1dc3e7 181
1eddc9a7
C
182 it('Should be able to remove the video with the correct token', async function () {
183 await removeVideo(server.url, accessToken, videoId)
184 })
0e1dc3e7
C
185 })
186
1eddc9a7
C
187 describe('Logout', function () {
188 it('Should logout (revoke token)')
0e1dc3e7 189
1eddc9a7 190 it('Should not be able to get the user information')
0e1dc3e7 191
1eddc9a7 192 it('Should not be able to upload a video')
0e1dc3e7 193
1eddc9a7 194 it('Should not be able to remove a video')
0e1dc3e7 195
1eddc9a7
C
196 it('Should not be able to rate a video', async function () {
197 const path = '/api/v1/videos/'
198 const data = {
199 rating: 'likes'
200 }
0e1dc3e7 201
1eddc9a7
C
202 const options = {
203 url: server.url,
204 path: path + videoId,
205 token: 'wrong token',
206 fields: data,
207 statusCodeExpected: 401
208 }
209 await makePutBodyRequest(options)
210 })
0e1dc3e7 211
1eddc9a7 212 it('Should be able to login again')
0e1dc3e7 213
1eddc9a7 214 it('Should have an expired access token')
0e1dc3e7 215
1eddc9a7
C
216 it('Should refresh the token')
217
218 it('Should be able to upload a video again')
0e1dc3e7
C
219 })
220
1eddc9a7 221 describe('Creating a user', function () {
ce5496d6 222
1eddc9a7
C
223 it('Should be able to create a new user', async function () {
224 await createUser({
225 url: server.url,
226 accessToken: accessToken,
227 username: user.username,
228 password: user.password,
229 videoQuota: 2 * 1024 * 1024,
230 adminFlags: UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST
231 })
232 })
a76138ff 233
1eddc9a7
C
234 it('Should be able to login with this user', async function () {
235 accessTokenUser = await userLogin(server, user)
236 })
a76138ff 237
1eddc9a7
C
238 it('Should be able to get user information', async function () {
239 const res1 = await getMyUserInformation(server.url, accessTokenUser)
240 const userMe: User = res1.body
241
242 const res2 = await getUserInformation(server.url, server.accessToken, userMe.id)
243 const userGet: User = res2.body
244
245 for (const user of [ userMe, userGet ]) {
246 expect(user.username).to.equal('user_1')
247 expect(user.email).to.equal('user_1@example.com')
248 expect(user.nsfwPolicy).to.equal('display')
249 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
250 expect(user.roleLabel).to.equal('User')
251 expect(user.id).to.be.a('number')
252 expect(user.account.displayName).to.equal('user_1')
253 expect(user.account.description).to.be.null
254 }
255
256 expect(userMe.adminFlags).to.be.undefined
257 expect(userGet.adminFlags).to.equal(UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST)
258 })
ce5496d6
C
259 })
260
1eddc9a7 261 describe('My videos & quotas', function () {
11474c3c 262
1eddc9a7
C
263 it('Should be able to upload a video with this user', async function () {
264 this.timeout(5000)
0e1dc3e7 265
1eddc9a7
C
266 const videoAttributes = {
267 name: 'super user video',
268 fixture: 'video_short.webm'
269 }
270 await uploadVideo(server.url, accessTokenUser, videoAttributes)
271 })
afffe988 272
1eddc9a7
C
273 it('Should have video quota updated', async function () {
274 const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser)
275 const data = res.body
0e1dc3e7 276
1eddc9a7 277 expect(data.videoQuotaUsed).to.equal(218910)
0e1dc3e7 278
1eddc9a7 279 const resUsers = await getUsersList(server.url, server.accessToken)
0e1dc3e7 280
1eddc9a7
C
281 const users: User[] = resUsers.body.data
282 const tmpUser = users.find(u => u.username === user.username)
283 expect(tmpUser.videoQuotaUsed).to.equal(218910)
284 })
0e1dc3e7 285
1eddc9a7
C
286 it('Should be able to list my videos', async function () {
287 const res = await getMyVideos(server.url, accessTokenUser, 0, 5)
288 expect(res.body.total).to.equal(1)
0e1dc3e7 289
1eddc9a7
C
290 const videos = res.body.data
291 expect(videos).to.have.lengthOf(1)
afffe988 292
1eddc9a7
C
293 expect(videos[ 0 ].name).to.equal('super user video')
294 })
0e1dc3e7
C
295 })
296
1eddc9a7 297 describe('Users listing', function () {
0e1dc3e7 298
1eddc9a7
C
299 it('Should list all the users', async function () {
300 const res = await getUsersList(server.url, server.accessToken)
301 const result = res.body
302 const total = result.total
303 const users = result.data
afffe988 304
1eddc9a7
C
305 expect(total).to.equal(2)
306 expect(users).to.be.an('array')
307 expect(users.length).to.equal(2)
0e1dc3e7 308
1eddc9a7
C
309 const user = users[ 0 ]
310 expect(user.username).to.equal('user_1')
311 expect(user.email).to.equal('user_1@example.com')
312 expect(user.nsfwPolicy).to.equal('display')
0e1dc3e7 313
1eddc9a7
C
314 const rootUser = users[ 1 ]
315 expect(rootUser.username).to.equal('root')
316 expect(rootUser.email).to.equal('admin1@example.com')
317 expect(user.nsfwPolicy).to.equal('display')
afffe988 318
1eddc9a7
C
319 userId = user.id
320 })
0e1dc3e7 321
1eddc9a7
C
322 it('Should list only the first user by username asc', async function () {
323 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, 'username')
0e1dc3e7 324
1eddc9a7
C
325 const result = res.body
326 const total = result.total
327 const users = result.data
a7ba16b6 328
1eddc9a7
C
329 expect(total).to.equal(2)
330 expect(users.length).to.equal(1)
afffe988 331
1eddc9a7
C
332 const user = users[ 0 ]
333 expect(user.username).to.equal('root')
334 expect(user.email).to.equal('admin1@example.com')
335 expect(user.roleLabel).to.equal('Administrator')
336 expect(user.nsfwPolicy).to.equal('display')
337 })
0e1dc3e7 338
1eddc9a7
C
339 it('Should list only the first user by username desc', async function () {
340 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-username')
341 const result = res.body
342 const total = result.total
343 const users = result.data
24b9417c 344
1eddc9a7
C
345 expect(total).to.equal(2)
346 expect(users.length).to.equal(1)
24b9417c 347
1eddc9a7
C
348 const user = users[ 0 ]
349 expect(user.username).to.equal('user_1')
350 expect(user.email).to.equal('user_1@example.com')
351 expect(user.nsfwPolicy).to.equal('display')
352 })
24b9417c 353
1eddc9a7
C
354 it('Should list only the second user by createdAt desc', async function () {
355 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-createdAt')
356 const result = res.body
357 const total = result.total
358 const users = result.data
24b9417c 359
1eddc9a7 360 expect(total).to.equal(2)
24b9417c
C
361 expect(users.length).to.equal(1)
362
1eddc9a7
C
363 const user = users[ 0 ]
364 expect(user.username).to.equal('user_1')
365 expect(user.email).to.equal('user_1@example.com')
366 expect(user.nsfwPolicy).to.equal('display')
367 })
24b9417c 368
1eddc9a7
C
369 it('Should list all the users by createdAt asc', async function () {
370 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt')
371 const result = res.body
372 const total = result.total
373 const users = result.data
24b9417c 374
1eddc9a7 375 expect(total).to.equal(2)
24b9417c
C
376 expect(users.length).to.equal(2)
377
378 expect(users[ 0 ].username).to.equal('root')
1eddc9a7
C
379 expect(users[ 0 ].email).to.equal('admin1@example.com')
380 expect(users[ 0 ].nsfwPolicy).to.equal('display')
24b9417c 381
1eddc9a7
C
382 expect(users[ 1 ].username).to.equal('user_1')
383 expect(users[ 1 ].email).to.equal('user_1@example.com')
384 expect(users[ 1 ].nsfwPolicy).to.equal('display')
11ba2ab3 385 })
0e1dc3e7 386
1eddc9a7
C
387 it('Should search user by username', async function () {
388 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'oot')
389 const users = res.body.data as User[]
390
391 expect(res.body.total).to.equal(1)
392 expect(users.length).to.equal(1)
0e1dc3e7 393
1eddc9a7 394 expect(users[ 0 ].username).to.equal('root')
11ba2ab3 395 })
0e1dc3e7 396
1eddc9a7
C
397 it('Should search user by email', async function () {
398 {
399 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'r_1@exam')
400 const users = res.body.data as User[]
0e1dc3e7 401
1eddc9a7
C
402 expect(res.body.total).to.equal(1)
403 expect(users.length).to.equal(1)
5c98d3bf 404
1eddc9a7
C
405 expect(users[ 0 ].username).to.equal('user_1')
406 expect(users[ 0 ].email).to.equal('user_1@example.com')
407 }
7efe153b 408
1eddc9a7
C
409 {
410 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'example')
411 const users = res.body.data as User[]
7efe153b 412
1eddc9a7
C
413 expect(res.body.total).to.equal(2)
414 expect(users.length).to.equal(2)
7efe153b 415
1eddc9a7
C
416 expect(users[ 0 ].username).to.equal('root')
417 expect(users[ 1 ].username).to.equal('user_1')
418 }
11ba2ab3 419 })
5c98d3bf
C
420 })
421
1eddc9a7
C
422 describe('Update my account', function () {
423 it('Should update my password', async function () {
424 await updateMyUser({
425 url: server.url,
426 accessToken: accessTokenUser,
427 currentPassword: 'super password',
428 newPassword: 'new password'
429 })
430 user.password = 'new password'
c5911fd3 431
1eddc9a7 432 await userLogin(server, user, 200)
c5911fd3
C
433 })
434
1eddc9a7
C
435 it('Should be able to change the NSFW display attribute', async function () {
436 await updateMyUser({
437 url: server.url,
438 accessToken: accessTokenUser,
439 nsfwPolicy: 'do_not_list'
440 })
441
442 const res = await getMyUserInformation(server.url, accessTokenUser)
443 const user = res.body
444
445 expect(user.username).to.equal('user_1')
446 expect(user.email).to.equal('user_1@example.com')
447 expect(user.nsfwPolicy).to.equal('do_not_list')
448 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
449 expect(user.id).to.be.a('number')
450 expect(user.account.displayName).to.equal('user_1')
451 expect(user.account.description).to.be.null
452 })
c5911fd3 453
1eddc9a7
C
454 it('Should be able to change the autoPlayVideo attribute', async function () {
455 await updateMyUser({
456 url: server.url,
457 accessToken: accessTokenUser,
458 autoPlayVideo: false
459 })
c5911fd3 460
1eddc9a7
C
461 const res = await getMyUserInformation(server.url, accessTokenUser)
462 const user = res.body
463
464 expect(user.autoPlayVideo).to.be.false
ed56ad11
C
465 })
466
1eddc9a7
C
467 it('Should be able to change the email display attribute', async function () {
468 await updateMyUser({
469 url: server.url,
470 accessToken: accessTokenUser,
471 email: 'updated@example.com'
472 })
473
474 const res = await getMyUserInformation(server.url, accessTokenUser)
475 const user = res.body
476
477 expect(user.username).to.equal('user_1')
478 expect(user.email).to.equal('updated@example.com')
479 expect(user.nsfwPolicy).to.equal('do_not_list')
480 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
481 expect(user.id).to.be.a('number')
482 expect(user.account.displayName).to.equal('user_1')
483 expect(user.account.description).to.be.null
484 })
ed56ad11 485
1eddc9a7
C
486 it('Should be able to update my avatar', async function () {
487 const fixture = 'avatar.png'
ed56ad11 488
1eddc9a7
C
489 await updateMyAvatar({
490 url: server.url,
491 accessToken: accessTokenUser,
492 fixture
493 })
2422c46b 494
1eddc9a7
C
495 const res = await getMyUserInformation(server.url, accessTokenUser)
496 const user = res.body
2422c46b 497
1eddc9a7
C
498 await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.png')
499 })
500
501 it('Should be able to update my display name', async function () {
502 await updateMyUser({
503 url: server.url,
504 accessToken: accessTokenUser,
505 displayName: 'new display name'
506 })
507
508 const res = await getMyUserInformation(server.url, accessTokenUser)
509 const user = res.body
510
511 expect(user.username).to.equal('user_1')
512 expect(user.email).to.equal('updated@example.com')
513 expect(user.nsfwPolicy).to.equal('do_not_list')
514 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
515 expect(user.id).to.be.a('number')
516 expect(user.account.displayName).to.equal('new display name')
517 expect(user.account.description).to.be.null
518 })
2422c46b 519
1eddc9a7
C
520 it('Should be able to update my description', async function () {
521 await updateMyUser({
522 url: server.url,
523 accessToken: accessTokenUser,
524 description: 'my super description updated'
525 })
526
527 const res = await getMyUserInformation(server.url, accessTokenUser)
528 const user = res.body
529
530 expect(user.username).to.equal('user_1')
531 expect(user.email).to.equal('updated@example.com')
532 expect(user.nsfwPolicy).to.equal('do_not_list')
533 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
534 expect(user.id).to.be.a('number')
535 expect(user.account.displayName).to.equal('new display name')
536 expect(user.account.description).to.equal('my super description updated')
537 })
0e1dc3e7
C
538 })
539
1eddc9a7
C
540 describe('Updating another user', function () {
541
542 it('Should be able to update another user', async function () {
543 await updateUser({
544 url: server.url,
545 userId,
546 accessToken,
547 email: 'updated2@example.com',
548 emailVerified: true,
549 videoQuota: 42,
550 role: UserRole.MODERATOR,
551 adminFlags: UserAdminFlag.NONE
552 })
553
554 const res = await getUserInformation(server.url, accessToken, userId)
555 const user = res.body
556
557 expect(user.username).to.equal('user_1')
558 expect(user.email).to.equal('updated2@example.com')
559 expect(user.emailVerified).to.be.true
560 expect(user.nsfwPolicy).to.equal('do_not_list')
561 expect(user.videoQuota).to.equal(42)
562 expect(user.roleLabel).to.equal('Moderator')
563 expect(user.id).to.be.a('number')
564 expect(user.adminFlags).to.equal(UserAdminFlag.NONE)
565 })
f8b8c36b 566
1eddc9a7
C
567 it('Should have removed the user token', async function () {
568 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401)
f8b8c36b 569
1eddc9a7 570 accessTokenUser = await userLogin(server, user)
b426edd4
C
571 })
572
1eddc9a7
C
573 it('Should be able to update another user password', async function () {
574 await updateUser({
575 url: server.url,
576 userId,
577 accessToken,
578 password: 'password updated'
579 })
b426edd4 580
1eddc9a7 581 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401)
b426edd4 582
1eddc9a7 583 await userLogin(server, user, 400)
b426edd4 584
1eddc9a7
C
585 user.password = 'password updated'
586 accessTokenUser = await userLogin(server, user)
587 })
757f0da3
C
588 })
589
1eddc9a7
C
590 describe('Video blacklists', function () {
591 it('Should be able to list video blacklist by a moderator', async function () {
592 await getBlacklistedVideosList({ url: server.url, token: accessTokenUser })
593 })
0e1dc3e7
C
594 })
595
1eddc9a7
C
596 describe('Remove a user', function () {
597 it('Should be able to remove this user', async function () {
598 await removeUser(server.url, userId, accessToken)
599 })
0e1dc3e7 600
1eddc9a7
C
601 it('Should not be able to login with this user', async function () {
602 await userLogin(server, user, 400)
603 })
0e1dc3e7 604
1eddc9a7
C
605 it('Should not have videos of this user', async function () {
606 const res = await getVideosList(server.url)
0e1dc3e7 607
1eddc9a7 608 expect(res.body.total).to.equal(1)
0e1dc3e7 609
1eddc9a7
C
610 const video = res.body.data[ 0 ]
611 expect(video.account.name).to.equal('root')
612 })
0e1dc3e7
C
613 })
614
1eddc9a7
C
615 describe('Registering a new user', function () {
616 it('Should register a new user', async function () {
617 await registerUser(server.url, 'user_15', 'my super password')
618 })
0e1dc3e7 619
1eddc9a7
C
620 it('Should be able to login with this registered user', async function () {
621 const user15 = {
622 username: 'user_15',
623 password: 'my super password'
624 }
5c98d3bf 625
1eddc9a7
C
626 accessToken = await userLogin(server, user15)
627 })
5c98d3bf 628
1eddc9a7
C
629 it('Should have the correct video quota', async function () {
630 const res = await getMyUserInformation(server.url, accessToken)
631 const user = res.body
0e1dc3e7 632
1eddc9a7
C
633 expect(user.videoQuota).to.equal(5 * 1024 * 1024)
634 })
92b9d60c 635
1eddc9a7
C
636 it('Should remove me', async function () {
637 {
638 const res = await getUsersList(server.url, server.accessToken)
639 expect(res.body.data.find(u => u.username === 'user_15')).to.not.be.undefined
640 }
92b9d60c 641
1eddc9a7
C
642 await deleteMe(server.url, accessToken)
643
644 {
645 const res = await getUsersList(server.url, server.accessToken)
646 expect(res.body.data.find(u => u.username === 'user_15')).to.be.undefined
647 }
648 })
92b9d60c
C
649 })
650
1eddc9a7
C
651 describe('User blocking', function () {
652 it('Should block and unblock a user', async function () {
653 const user16 = {
654 username: 'user_16',
655 password: 'my super password'
656 }
657 const resUser = await createUser({
658 url: server.url,
659 accessToken: server.accessToken,
660 username: user16.username,
661 password: user16.password
662 })
663 const user16Id = resUser.body.user.id
e6921918 664
1eddc9a7 665 accessToken = await userLogin(server, user16)
e6921918 666
1eddc9a7
C
667 await getMyUserInformation(server.url, accessToken, 200)
668 await blockUser(server.url, user16Id, server.accessToken)
e6921918 669
1eddc9a7
C
670 await getMyUserInformation(server.url, accessToken, 401)
671 await userLogin(server, user16, 400)
e6921918 672
1eddc9a7
C
673 await unblockUser(server.url, user16Id, server.accessToken)
674 accessToken = await userLogin(server, user16)
675 await getMyUserInformation(server.url, accessToken, 200)
676 })
e6921918
C
677 })
678
7c3b7976
C
679 after(async function () {
680 await cleanupTests([ server ])
0e1dc3e7
C
681 })
682})