]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/users/users.ts
Fix user video quota with webtorrent disabled
[github/Chocobozzz/PeerTube.git] / server / tests / api / users / users.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import * as chai from 'chai'
4 import 'mocha'
5 import { MyUser, User, UserRole, Video, VideoPlaylistType, VideoAbuseState, VideoAbuseUpdate } from '../../../../shared/index'
6 import {
7 blockUser,
8 cleanupTests,
9 createUser,
10 deleteMe,
11 flushAndRunServer,
12 getAccountRatings,
13 getBlacklistedVideosList,
14 getMyUserInformation,
15 getMyUserVideoQuotaUsed,
16 getMyUserVideoRating,
17 getUserInformation,
18 getUsersList,
19 getUsersListPaginationAndSort,
20 getVideoChannel,
21 getVideosList,
22 installPlugin,
23 login,
24 makePutBodyRequest,
25 rateVideo,
26 registerUserWithChannel,
27 removeUser,
28 removeVideo,
29 ServerInfo,
30 testImage,
31 unblockUser,
32 updateMyAvatar,
33 updateMyUser,
34 updateUser,
35 uploadVideo,
36 userLogin,
37 reportVideoAbuse,
38 addVideoCommentThread,
39 updateVideoAbuse,
40 getVideoAbusesList, updateCustomSubConfig, getCustomConfig, waitJobs
41 } from '../../../../shared/extra-utils'
42 import { follow } from '../../../../shared/extra-utils/server/follows'
43 import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
44 import { getMyVideos } from '../../../../shared/extra-utils/videos/videos'
45 import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
46 import { CustomConfig } from '@shared/models/server'
47
48 const expect = chai.expect
49
50 describe('Test users', function () {
51 let server: ServerInfo
52 let accessToken: string
53 let accessTokenUser: string
54 let videoId: number
55 let userId: number
56 const user = {
57 username: 'user_1',
58 password: 'super password'
59 }
60
61 before(async function () {
62 this.timeout(30000)
63 server = await flushAndRunServer(1)
64
65 await setAccessTokensToServers([ server ])
66
67 await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-theme-background-red' })
68 })
69
70 describe('OAuth client', function () {
71 it('Should create a new client')
72
73 it('Should return the first client')
74
75 it('Should remove the last client')
76
77 it('Should not login with an invalid client id', async function () {
78 const client = { id: 'client', secret: server.client.secret }
79 const res = await login(server.url, client, server.user, 400)
80
81 expect(res.body.error).to.contain('client is invalid')
82 })
83
84 it('Should not login with an invalid client secret', async function () {
85 const client = { id: server.client.id, secret: 'coucou' }
86 const res = await login(server.url, client, server.user, 400)
87
88 expect(res.body.error).to.contain('client is invalid')
89 })
90 })
91
92 describe('Login', function () {
93
94 it('Should not login with an invalid username', async function () {
95 const user = { username: 'captain crochet', password: server.user.password }
96 const res = await login(server.url, server.client, user, 400)
97
98 expect(res.body.error).to.contain('credentials are invalid')
99 })
100
101 it('Should not login with an invalid password', async function () {
102 const user = { username: server.user.username, password: 'mew_three' }
103 const res = await login(server.url, server.client, user, 400)
104
105 expect(res.body.error).to.contain('credentials are invalid')
106 })
107
108 it('Should not be able to upload a video', async function () {
109 accessToken = 'my_super_token'
110
111 const videoAttributes = {}
112 await uploadVideo(server.url, accessToken, videoAttributes, 401)
113 })
114
115 it('Should not be able to follow', async function () {
116 accessToken = 'my_super_token'
117 await follow(server.url, [ 'http://example.com' ], accessToken, 401)
118 })
119
120 it('Should not be able to unfollow')
121
122 it('Should be able to login', async function () {
123 const res = await login(server.url, server.client, server.user, 200)
124
125 accessToken = res.body.access_token
126 })
127
128 it('Should be able to login with an insensitive username', async function () {
129 const user = { username: 'RoOt', password: server.user.password }
130 await login(server.url, server.client, user, 200)
131
132 const user2 = { username: 'rOoT', password: server.user.password }
133 await login(server.url, server.client, user2, 200)
134
135 const user3 = { username: 'ROOt', password: server.user.password }
136 await login(server.url, server.client, user3, 200)
137 })
138 })
139
140 describe('Upload', function () {
141
142 it('Should upload the video with the correct token', async function () {
143 const videoAttributes = {}
144 await uploadVideo(server.url, accessToken, videoAttributes)
145 const res = await getVideosList(server.url)
146 const video = res.body.data[0]
147
148 expect(video.account.name).to.equal('root')
149 videoId = video.id
150 })
151
152 it('Should upload the video again with the correct token', async function () {
153 const videoAttributes = {}
154 await uploadVideo(server.url, accessToken, videoAttributes)
155 })
156 })
157
158 describe('Ratings', function () {
159
160 it('Should retrieve a video rating', async function () {
161 await rateVideo(server.url, accessToken, videoId, 'like')
162 const res = await getMyUserVideoRating(server.url, accessToken, videoId)
163 const rating = res.body
164
165 expect(rating.videoId).to.equal(videoId)
166 expect(rating.rating).to.equal('like')
167 })
168
169 it('Should retrieve ratings list', async function () {
170 await rateVideo(server.url, accessToken, videoId, 'like')
171
172 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, 200)
173 const ratings = res.body
174
175 expect(ratings.total).to.equal(1)
176 expect(ratings.data[0].video.id).to.equal(videoId)
177 expect(ratings.data[0].rating).to.equal('like')
178 })
179
180 it('Should retrieve ratings list by rating type', async function () {
181 {
182 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'like')
183 const ratings = res.body
184 expect(ratings.data.length).to.equal(1)
185 }
186
187 {
188 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'dislike')
189 const ratings = res.body
190 expect(ratings.data.length).to.equal(0)
191 }
192 })
193 })
194
195 describe('Remove video', function () {
196 it('Should not be able to remove the video with an incorrect token', async function () {
197 await removeVideo(server.url, 'bad_token', videoId, 401)
198 })
199
200 it('Should not be able to remove the video with the token of another account')
201
202 it('Should be able to remove the video with the correct token', async function () {
203 await removeVideo(server.url, accessToken, videoId)
204 })
205 })
206
207 describe('Logout', function () {
208 it('Should logout (revoke token)')
209
210 it('Should not be able to get the user information')
211
212 it('Should not be able to upload a video')
213
214 it('Should not be able to remove a video')
215
216 it('Should not be able to rate a video', async function () {
217 const path = '/api/v1/videos/'
218 const data = {
219 rating: 'likes'
220 }
221
222 const options = {
223 url: server.url,
224 path: path + videoId,
225 token: 'wrong token',
226 fields: data,
227 statusCodeExpected: 401
228 }
229 await makePutBodyRequest(options)
230 })
231
232 it('Should be able to login again')
233
234 it('Should have an expired access token')
235
236 it('Should refresh the token')
237
238 it('Should be able to upload a video again')
239 })
240
241 describe('Creating a user', function () {
242
243 it('Should be able to create a new user', async function () {
244 await createUser({
245 url: server.url,
246 accessToken: accessToken,
247 username: user.username,
248 password: user.password,
249 videoQuota: 2 * 1024 * 1024,
250 adminFlags: UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST
251 })
252 })
253
254 it('Should be able to login with this user', async function () {
255 accessTokenUser = await userLogin(server, user)
256 })
257
258 it('Should be able to get user information', async function () {
259 const res1 = await getMyUserInformation(server.url, accessTokenUser)
260 const userMe: MyUser = res1.body
261
262 const res2 = await getUserInformation(server.url, server.accessToken, userMe.id, true)
263 const userGet: User = res2.body
264
265 for (const user of [ userMe, userGet ]) {
266 expect(user.username).to.equal('user_1')
267 expect(user.email).to.equal('user_1@example.com')
268 expect(user.nsfwPolicy).to.equal('display')
269 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
270 expect(user.roleLabel).to.equal('User')
271 expect(user.id).to.be.a('number')
272 expect(user.account.displayName).to.equal('user_1')
273 expect(user.account.description).to.be.null
274 }
275
276 expect(userMe.adminFlags).to.be.undefined
277 expect(userGet.adminFlags).to.equal(UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST)
278
279 expect(userMe.specialPlaylists).to.have.lengthOf(1)
280 expect(userMe.specialPlaylists[0].type).to.equal(VideoPlaylistType.WATCH_LATER)
281
282 // Check stats are included with withStats
283 expect(userGet.videosCount).to.be.a('number')
284 expect(userGet.videosCount).to.equal(0)
285 expect(userGet.videoCommentsCount).to.be.a('number')
286 expect(userGet.videoCommentsCount).to.equal(0)
287 expect(userGet.videoAbusesCount).to.be.a('number')
288 expect(userGet.videoAbusesCount).to.equal(0)
289 expect(userGet.videoAbusesAcceptedCount).to.be.a('number')
290 expect(userGet.videoAbusesAcceptedCount).to.equal(0)
291 })
292 })
293
294 describe('My videos & quotas', function () {
295
296 it('Should be able to upload a video with this user', async function () {
297 this.timeout(10000)
298
299 const videoAttributes = {
300 name: 'super user video',
301 fixture: 'video_short.webm'
302 }
303 await uploadVideo(server.url, accessTokenUser, videoAttributes)
304 })
305
306 it('Should have video quota updated', async function () {
307 const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser)
308 const data = res.body
309
310 expect(data.videoQuotaUsed).to.equal(218910)
311
312 const resUsers = await getUsersList(server.url, server.accessToken)
313
314 const users: User[] = resUsers.body.data
315 const tmpUser = users.find(u => u.username === user.username)
316 expect(tmpUser.videoQuotaUsed).to.equal(218910)
317 })
318
319 it('Should be able to list my videos', async function () {
320 const res = await getMyVideos(server.url, accessTokenUser, 0, 5)
321 expect(res.body.total).to.equal(1)
322
323 const videos = res.body.data
324 expect(videos).to.have.lengthOf(1)
325
326 const video: Video = videos[0]
327 expect(video.name).to.equal('super user video')
328 expect(video.thumbnailPath).to.not.be.null
329 expect(video.previewPath).to.not.be.null
330 })
331
332 it('Should be able to search in my videos', async function () {
333 {
334 const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'user video')
335 expect(res.body.total).to.equal(1)
336
337 const videos = res.body.data
338 expect(videos).to.have.lengthOf(1)
339 }
340
341 {
342 const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'toto')
343 expect(res.body.total).to.equal(0)
344
345 const videos = res.body.data
346 expect(videos).to.have.lengthOf(0)
347 }
348 })
349
350 it('Should disable webtorrent, enable HLS, and update my quota', async function () {
351 this.timeout(60000)
352
353 {
354 const res = await getCustomConfig(server.url, server.accessToken)
355 const config = res.body as CustomConfig
356 config.transcoding.webtorrent.enabled = false
357 config.transcoding.hls.enabled = true
358 config.transcoding.enabled = true
359 await updateCustomSubConfig(server.url, server.accessToken, config)
360 }
361
362 {
363 const videoAttributes = {
364 name: 'super user video 2',
365 fixture: 'video_short.webm'
366 }
367 await uploadVideo(server.url, accessTokenUser, videoAttributes)
368
369 await waitJobs([ server ])
370 }
371
372 {
373 const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser)
374 const data = res.body
375
376 expect(data.videoQuotaUsed).to.be.greaterThan(220000)
377 }
378 })
379 })
380
381 describe('Users listing', function () {
382
383 it('Should list all the users', async function () {
384 const res = await getUsersList(server.url, server.accessToken)
385 const result = res.body
386 const total = result.total
387 const users = result.data
388
389 expect(total).to.equal(2)
390 expect(users).to.be.an('array')
391 expect(users.length).to.equal(2)
392
393 const user = users[0]
394 expect(user.username).to.equal('user_1')
395 expect(user.email).to.equal('user_1@example.com')
396 expect(user.nsfwPolicy).to.equal('display')
397
398 const rootUser = users[1]
399 expect(rootUser.username).to.equal('root')
400 expect(rootUser.email).to.equal('admin' + server.internalServerNumber + '@example.com')
401 expect(user.nsfwPolicy).to.equal('display')
402
403 userId = user.id
404 })
405
406 it('Should list only the first user by username asc', async function () {
407 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, 'username')
408
409 const result = res.body
410 const total = result.total
411 const users = result.data
412
413 expect(total).to.equal(2)
414 expect(users.length).to.equal(1)
415
416 const user = users[0]
417 expect(user.username).to.equal('root')
418 expect(user.email).to.equal('admin' + server.internalServerNumber + '@example.com')
419 expect(user.roleLabel).to.equal('Administrator')
420 expect(user.nsfwPolicy).to.equal('display')
421 })
422
423 it('Should list only the first user by username desc', async function () {
424 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-username')
425 const result = res.body
426 const total = result.total
427 const users = result.data
428
429 expect(total).to.equal(2)
430 expect(users.length).to.equal(1)
431
432 const user = users[0]
433 expect(user.username).to.equal('user_1')
434 expect(user.email).to.equal('user_1@example.com')
435 expect(user.nsfwPolicy).to.equal('display')
436 })
437
438 it('Should list only the second user by createdAt desc', async function () {
439 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-createdAt')
440 const result = res.body
441 const total = result.total
442 const users = result.data
443
444 expect(total).to.equal(2)
445 expect(users.length).to.equal(1)
446
447 const user = users[0]
448 expect(user.username).to.equal('user_1')
449 expect(user.email).to.equal('user_1@example.com')
450 expect(user.nsfwPolicy).to.equal('display')
451 })
452
453 it('Should list all the users by createdAt asc', async function () {
454 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt')
455 const result = res.body
456 const total = result.total
457 const users = result.data
458
459 expect(total).to.equal(2)
460 expect(users.length).to.equal(2)
461
462 expect(users[0].username).to.equal('root')
463 expect(users[0].email).to.equal('admin' + server.internalServerNumber + '@example.com')
464 expect(users[0].nsfwPolicy).to.equal('display')
465
466 expect(users[1].username).to.equal('user_1')
467 expect(users[1].email).to.equal('user_1@example.com')
468 expect(users[1].nsfwPolicy).to.equal('display')
469 })
470
471 it('Should search user by username', async function () {
472 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'oot')
473 const users = res.body.data as User[]
474
475 expect(res.body.total).to.equal(1)
476 expect(users.length).to.equal(1)
477
478 expect(users[0].username).to.equal('root')
479 })
480
481 it('Should search user by email', async function () {
482 {
483 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'r_1@exam')
484 const users = res.body.data as User[]
485
486 expect(res.body.total).to.equal(1)
487 expect(users.length).to.equal(1)
488
489 expect(users[0].username).to.equal('user_1')
490 expect(users[0].email).to.equal('user_1@example.com')
491 }
492
493 {
494 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'example')
495 const users = res.body.data as User[]
496
497 expect(res.body.total).to.equal(2)
498 expect(users.length).to.equal(2)
499
500 expect(users[0].username).to.equal('root')
501 expect(users[1].username).to.equal('user_1')
502 }
503 })
504 })
505
506 describe('Update my account', function () {
507 it('Should update my password', async function () {
508 await updateMyUser({
509 url: server.url,
510 accessToken: accessTokenUser,
511 currentPassword: 'super password',
512 password: 'new password'
513 })
514 user.password = 'new password'
515
516 await userLogin(server, user, 200)
517 })
518
519 it('Should be able to change the NSFW display attribute', async function () {
520 await updateMyUser({
521 url: server.url,
522 accessToken: accessTokenUser,
523 nsfwPolicy: 'do_not_list'
524 })
525
526 const res = await getMyUserInformation(server.url, accessTokenUser)
527 const user = res.body
528
529 expect(user.username).to.equal('user_1')
530 expect(user.email).to.equal('user_1@example.com')
531 expect(user.nsfwPolicy).to.equal('do_not_list')
532 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
533 expect(user.id).to.be.a('number')
534 expect(user.account.displayName).to.equal('user_1')
535 expect(user.account.description).to.be.null
536 })
537
538 it('Should be able to change the autoPlayVideo attribute', async function () {
539 await updateMyUser({
540 url: server.url,
541 accessToken: accessTokenUser,
542 autoPlayVideo: false
543 })
544
545 const res = await getMyUserInformation(server.url, accessTokenUser)
546 const user = res.body
547
548 expect(user.autoPlayVideo).to.be.false
549 })
550
551 it('Should be able to change the autoPlayNextVideo attribute', async function () {
552 await updateMyUser({
553 url: server.url,
554 accessToken: accessTokenUser,
555 autoPlayNextVideo: true
556 })
557
558 const res = await getMyUserInformation(server.url, accessTokenUser)
559 const user = res.body
560
561 expect(user.autoPlayNextVideo).to.be.true
562 })
563
564 it('Should be able to change the email attribute', async function () {
565 await updateMyUser({
566 url: server.url,
567 accessToken: accessTokenUser,
568 currentPassword: 'new password',
569 email: 'updated@example.com'
570 })
571
572 const res = await getMyUserInformation(server.url, accessTokenUser)
573 const user = res.body
574
575 expect(user.username).to.equal('user_1')
576 expect(user.email).to.equal('updated@example.com')
577 expect(user.nsfwPolicy).to.equal('do_not_list')
578 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
579 expect(user.id).to.be.a('number')
580 expect(user.account.displayName).to.equal('user_1')
581 expect(user.account.description).to.be.null
582 })
583
584 it('Should be able to update my avatar', async function () {
585 const fixture = 'avatar.png'
586
587 await updateMyAvatar({
588 url: server.url,
589 accessToken: accessTokenUser,
590 fixture
591 })
592
593 const res = await getMyUserInformation(server.url, accessTokenUser)
594 const user = res.body
595
596 await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.png')
597 })
598
599 it('Should be able to update my display name', async function () {
600 await updateMyUser({
601 url: server.url,
602 accessToken: accessTokenUser,
603 displayName: 'new display name'
604 })
605
606 const res = await getMyUserInformation(server.url, accessTokenUser)
607 const user = res.body
608
609 expect(user.username).to.equal('user_1')
610 expect(user.email).to.equal('updated@example.com')
611 expect(user.nsfwPolicy).to.equal('do_not_list')
612 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
613 expect(user.id).to.be.a('number')
614 expect(user.account.displayName).to.equal('new display name')
615 expect(user.account.description).to.be.null
616 })
617
618 it('Should be able to update my description', async function () {
619 await updateMyUser({
620 url: server.url,
621 accessToken: accessTokenUser,
622 description: 'my super description updated'
623 })
624
625 const res = await getMyUserInformation(server.url, accessTokenUser)
626 const user: User = res.body
627
628 expect(user.username).to.equal('user_1')
629 expect(user.email).to.equal('updated@example.com')
630 expect(user.nsfwPolicy).to.equal('do_not_list')
631 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
632 expect(user.id).to.be.a('number')
633 expect(user.account.displayName).to.equal('new display name')
634 expect(user.account.description).to.equal('my super description updated')
635 expect(user.noWelcomeModal).to.be.false
636 expect(user.noInstanceConfigWarningModal).to.be.false
637 })
638
639 it('Should be able to update my theme', async function () {
640 for (const theme of [ 'background-red', 'default', 'instance-default' ]) {
641 await updateMyUser({
642 url: server.url,
643 accessToken: accessTokenUser,
644 theme
645 })
646
647 const res = await getMyUserInformation(server.url, accessTokenUser)
648 const body: User = res.body
649
650 expect(body.theme).to.equal(theme)
651 }
652 })
653
654 it('Should be able to update my modal preferences', async function () {
655 await updateMyUser({
656 url: server.url,
657 accessToken: accessTokenUser,
658 noInstanceConfigWarningModal: true,
659 noWelcomeModal: true
660 })
661
662 const res = await getMyUserInformation(server.url, accessTokenUser)
663 const user: User = res.body
664
665 expect(user.noWelcomeModal).to.be.true
666 expect(user.noInstanceConfigWarningModal).to.be.true
667 })
668 })
669
670 describe('Updating another user', function () {
671 it('Should be able to update another user', async function () {
672 await updateUser({
673 url: server.url,
674 userId,
675 accessToken,
676 email: 'updated2@example.com',
677 emailVerified: true,
678 videoQuota: 42,
679 role: UserRole.MODERATOR,
680 adminFlags: UserAdminFlag.NONE
681 })
682
683 const res = await getUserInformation(server.url, accessToken, userId)
684 const user = res.body
685
686 expect(user.username).to.equal('user_1')
687 expect(user.email).to.equal('updated2@example.com')
688 expect(user.emailVerified).to.be.true
689 expect(user.nsfwPolicy).to.equal('do_not_list')
690 expect(user.videoQuota).to.equal(42)
691 expect(user.roleLabel).to.equal('Moderator')
692 expect(user.id).to.be.a('number')
693 expect(user.adminFlags).to.equal(UserAdminFlag.NONE)
694 })
695
696 it('Should have removed the user token', async function () {
697 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401)
698
699 accessTokenUser = await userLogin(server, user)
700 })
701
702 it('Should be able to update another user password', async function () {
703 await updateUser({
704 url: server.url,
705 userId,
706 accessToken,
707 password: 'password updated'
708 })
709
710 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401)
711
712 await userLogin(server, user, 400)
713
714 user.password = 'password updated'
715 accessTokenUser = await userLogin(server, user)
716 })
717 })
718
719 describe('Video blacklists', function () {
720 it('Should be able to list video blacklist by a moderator', async function () {
721 await getBlacklistedVideosList({ url: server.url, token: accessTokenUser })
722 })
723 })
724
725 describe('Remove a user', function () {
726 it('Should be able to remove this user', async function () {
727 await removeUser(server.url, userId, accessToken)
728 })
729
730 it('Should not be able to login with this user', async function () {
731 await userLogin(server, user, 400)
732 })
733
734 it('Should not have videos of this user', async function () {
735 const res = await getVideosList(server.url)
736
737 expect(res.body.total).to.equal(1)
738
739 const video = res.body.data[0]
740 expect(video.account.name).to.equal('root')
741 })
742 })
743
744 describe('Registering a new user', function () {
745 let user15AccessToken
746
747 it('Should register a new user', async function () {
748 const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' }
749 const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' }
750
751 await registerUserWithChannel({ url: server.url, user, channel })
752 })
753
754 it('Should be able to login with this registered user', async function () {
755 const user15 = {
756 username: 'user_15',
757 password: 'my super password'
758 }
759
760 user15AccessToken = await userLogin(server, user15)
761 })
762
763 it('Should have the correct display name', async function () {
764 const res = await getMyUserInformation(server.url, user15AccessToken)
765 const user: User = res.body
766
767 expect(user.account.displayName).to.equal('super user 15')
768 })
769
770 it('Should have the correct video quota', async function () {
771 const res = await getMyUserInformation(server.url, user15AccessToken)
772 const user = res.body
773
774 expect(user.videoQuota).to.equal(5 * 1024 * 1024)
775 })
776
777 it('Should have created the channel', async function () {
778 const res = await getVideoChannel(server.url, 'my_user_15_channel')
779
780 expect(res.body.displayName).to.equal('my channel rocks')
781 })
782
783 it('Should remove me', async function () {
784 {
785 const res = await getUsersList(server.url, server.accessToken)
786 expect(res.body.data.find(u => u.username === 'user_15')).to.not.be.undefined
787 }
788
789 await deleteMe(server.url, user15AccessToken)
790
791 {
792 const res = await getUsersList(server.url, server.accessToken)
793 expect(res.body.data.find(u => u.username === 'user_15')).to.be.undefined
794 }
795 })
796 })
797
798 describe('User blocking', function () {
799 let user16Id
800 let user16AccessToken
801
802 it('Should block and unblock a user', async function () {
803 const user16 = {
804 username: 'user_16',
805 password: 'my super password'
806 }
807 const resUser = await createUser({
808 url: server.url,
809 accessToken: server.accessToken,
810 username: user16.username,
811 password: user16.password
812 })
813 user16Id = resUser.body.user.id
814
815 user16AccessToken = await userLogin(server, user16)
816
817 await getMyUserInformation(server.url, user16AccessToken, 200)
818 await blockUser(server.url, user16Id, server.accessToken)
819
820 await getMyUserInformation(server.url, user16AccessToken, 401)
821 await userLogin(server, user16, 400)
822
823 await unblockUser(server.url, user16Id, server.accessToken)
824 user16AccessToken = await userLogin(server, user16)
825 await getMyUserInformation(server.url, user16AccessToken, 200)
826 })
827 })
828
829 describe('User stats', function () {
830 let user17Id
831 let user17AccessToken
832
833 it('Should report correct initial statistics about a user', async function () {
834 const user17 = {
835 username: 'user_17',
836 password: 'my super password'
837 }
838 const resUser = await createUser({
839 url: server.url,
840 accessToken: server.accessToken,
841 username: user17.username,
842 password: user17.password
843 })
844
845 user17Id = resUser.body.user.id
846 user17AccessToken = await userLogin(server, user17)
847
848 const res = await getUserInformation(server.url, server.accessToken, user17Id, true)
849 const user: User = res.body
850
851 expect(user.videosCount).to.equal(0)
852 expect(user.videoCommentsCount).to.equal(0)
853 expect(user.videoAbusesCount).to.equal(0)
854 expect(user.videoAbusesCreatedCount).to.equal(0)
855 expect(user.videoAbusesAcceptedCount).to.equal(0)
856 })
857
858 it('Should report correct videos count', async function () {
859 const videoAttributes = {
860 name: 'video to test user stats'
861 }
862 await uploadVideo(server.url, user17AccessToken, videoAttributes)
863 const res1 = await getVideosList(server.url)
864 videoId = res1.body.data.find(video => video.name === videoAttributes.name).id
865
866 const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true)
867 const user: User = res2.body
868
869 expect(user.videosCount).to.equal(1)
870 })
871
872 it('Should report correct video comments for user', async function () {
873 const text = 'super comment'
874 await addVideoCommentThread(server.url, user17AccessToken, videoId, text)
875
876 const res = await getUserInformation(server.url, server.accessToken, user17Id, true)
877 const user: User = res.body
878
879 expect(user.videoCommentsCount).to.equal(1)
880 })
881
882 it('Should report correct video abuses counts', async function () {
883 const reason = 'my super bad reason'
884 await reportVideoAbuse(server.url, user17AccessToken, videoId, reason)
885
886 const res1 = await getVideoAbusesList(server.url, server.accessToken)
887 const abuseId = res1.body.data[0].id
888
889 const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true)
890 const user2: User = res2.body
891
892 expect(user2.videoAbusesCount).to.equal(1) // number of incriminations
893 expect(user2.videoAbusesCreatedCount).to.equal(1) // number of reports created
894
895 const body: VideoAbuseUpdate = { state: VideoAbuseState.ACCEPTED }
896 await updateVideoAbuse(server.url, server.accessToken, videoId, abuseId, body)
897
898 const res3 = await getUserInformation(server.url, server.accessToken, user17Id, true)
899 const user3: User = res3.body
900
901 expect(user3.videoAbusesAcceptedCount).to.equal(1) // number of reports created accepted
902 })
903 })
904
905 after(async function () {
906 await cleanupTests([ server ])
907 })
908 })