1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { HttpStatusCode } from '@shared/core-utils'
15 getBlacklistedVideosList,
18 getMyUserVideoQuotaUsed,
23 getUsersListPaginationAndSort,
33 registerUserWithChannel,
38 setAccessTokensToServers,
42 updateCustomSubConfig,
49 } from '@shared/extra-utils'
50 import { AbuseState, CustomConfig, MyUser, OAuth2ErrorCode, User, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models'
52 const expect = chai.expect
54 describe('Test users', function () {
55 let server: ServerInfo
56 let accessToken: string
57 let accessTokenUser: string
62 password: 'super password'
65 before(async function () {
68 server = await flushAndRunServer(1, {
76 await setAccessTokensToServers([ server ])
78 await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-theme-background-red' })
81 describe('OAuth client', function () {
82 it('Should create a new client')
84 it('Should return the first client')
86 it('Should remove the last client')
88 it('Should not login with an invalid client id', async function () {
89 const client = { id: 'client', secret: server.client.secret }
90 const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400)
92 expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT)
93 expect(res.body.error).to.contain('client is invalid')
94 expect(res.body.type.startsWith('https://')).to.be.true
95 expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT)
98 it('Should not login with an invalid client secret', async function () {
99 const client = { id: server.client.id, secret: 'coucou' }
100 const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400)
102 expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT)
103 expect(res.body.error).to.contain('client is invalid')
104 expect(res.body.type.startsWith('https://')).to.be.true
105 expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT)
109 describe('Login', function () {
111 it('Should not login with an invalid username', async function () {
112 const user = { username: 'captain crochet', password: server.user.password }
113 const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400)
115 expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT)
116 expect(res.body.error).to.contain('credentials are invalid')
117 expect(res.body.type.startsWith('https://')).to.be.true
118 expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT)
121 it('Should not login with an invalid password', async function () {
122 const user = { username: server.user.username, password: 'mew_three' }
123 const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400)
125 expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT)
126 expect(res.body.error).to.contain('credentials are invalid')
127 expect(res.body.type.startsWith('https://')).to.be.true
128 expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT)
131 it('Should not be able to upload a video', async function () {
132 accessToken = 'my_super_token'
134 const videoAttributes = {}
135 await uploadVideo(server.url, accessToken, videoAttributes, HttpStatusCode.UNAUTHORIZED_401)
138 it('Should not be able to follow', async function () {
139 accessToken = 'my_super_token'
141 await server.followsCommand.follow({
142 targets: [ 'http://example.com' ],
144 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
148 it('Should not be able to unfollow')
150 it('Should be able to login', async function () {
151 const res = await login(server.url, server.client, server.user, HttpStatusCode.OK_200)
153 accessToken = res.body.access_token
156 it('Should be able to login with an insensitive username', async function () {
157 const user = { username: 'RoOt', password: server.user.password }
158 await login(server.url, server.client, user, HttpStatusCode.OK_200)
160 const user2 = { username: 'rOoT', password: server.user.password }
161 await login(server.url, server.client, user2, HttpStatusCode.OK_200)
163 const user3 = { username: 'ROOt', password: server.user.password }
164 await login(server.url, server.client, user3, HttpStatusCode.OK_200)
168 describe('Upload', function () {
170 it('Should upload the video with the correct token', async function () {
171 const videoAttributes = {}
172 await uploadVideo(server.url, accessToken, videoAttributes)
173 const res = await getVideosList(server.url)
174 const video = res.body.data[0]
176 expect(video.account.name).to.equal('root')
180 it('Should upload the video again with the correct token', async function () {
181 const videoAttributes = {}
182 await uploadVideo(server.url, accessToken, videoAttributes)
186 describe('Ratings', function () {
188 it('Should retrieve a video rating', async function () {
189 await rateVideo(server.url, accessToken, videoId, 'like')
190 const res = await getMyUserVideoRating(server.url, accessToken, videoId)
191 const rating = res.body
193 expect(rating.videoId).to.equal(videoId)
194 expect(rating.rating).to.equal('like')
197 it('Should retrieve ratings list', async function () {
198 await rateVideo(server.url, accessToken, videoId, 'like')
200 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, HttpStatusCode.OK_200)
201 const ratings = res.body
203 expect(ratings.total).to.equal(1)
204 expect(ratings.data[0].video.id).to.equal(videoId)
205 expect(ratings.data[0].rating).to.equal('like')
208 it('Should retrieve ratings list by rating type', async function () {
210 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'like')
211 const ratings = res.body
212 expect(ratings.data.length).to.equal(1)
216 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'dislike')
217 const ratings = res.body
218 expect(ratings.data.length).to.equal(0)
223 describe('Remove video', function () {
224 it('Should not be able to remove the video with an incorrect token', async function () {
225 await removeVideo(server.url, 'bad_token', videoId, HttpStatusCode.UNAUTHORIZED_401)
228 it('Should not be able to remove the video with the token of another account')
230 it('Should be able to remove the video with the correct token', async function () {
231 await removeVideo(server.url, accessToken, videoId)
235 describe('Logout', function () {
236 it('Should logout (revoke token)', async function () {
237 await logout(server.url, server.accessToken)
240 it('Should not be able to get the user information', async function () {
241 await getMyUserInformation(server.url, server.accessToken, HttpStatusCode.UNAUTHORIZED_401)
244 it('Should not be able to upload a video', async function () {
245 await uploadVideo(server.url, server.accessToken, { name: 'video' }, HttpStatusCode.UNAUTHORIZED_401)
248 it('Should not be able to rate a video', async function () {
249 const path = '/api/v1/videos/'
256 path: path + videoId,
257 token: 'wrong token',
259 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
261 await makePutBodyRequest(options)
264 it('Should be able to login again', async function () {
265 const res = await login(server.url, server.client, server.user)
266 server.accessToken = res.body.access_token
267 server.refreshToken = res.body.refresh_token
270 it('Should be able to get my user information again', async function () {
271 await getMyUserInformation(server.url, server.accessToken)
274 it('Should have an expired access token', async function () {
277 await setTokenField(server.internalServerNumber, server.accessToken, 'accessTokenExpiresAt', new Date().toISOString())
278 await setTokenField(server.internalServerNumber, server.accessToken, 'refreshTokenExpiresAt', new Date().toISOString())
280 killallServers([ server ])
281 await reRunServer(server)
283 await getMyUserInformation(server.url, server.accessToken, 401)
286 it('Should not be able to refresh an access token with an expired refresh token', async function () {
287 await refreshToken(server, server.refreshToken, 400)
290 it('Should refresh the token', async function () {
293 const futureDate = new Date(new Date().getTime() + 1000 * 60).toISOString()
294 await setTokenField(server.internalServerNumber, server.accessToken, 'refreshTokenExpiresAt', futureDate)
296 killallServers([ server ])
297 await reRunServer(server)
299 const res = await refreshToken(server, server.refreshToken)
300 server.accessToken = res.body.access_token
301 server.refreshToken = res.body.refresh_token
304 it('Should be able to get my user information again', async function () {
305 await getMyUserInformation(server.url, server.accessToken)
309 describe('Creating a user', function () {
311 it('Should be able to create a new user', async function () {
314 accessToken: accessToken,
315 username: user.username,
316 password: user.password,
317 videoQuota: 2 * 1024 * 1024,
318 adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST
322 it('Should be able to login with this user', async function () {
323 accessTokenUser = await userLogin(server, user)
326 it('Should be able to get user information', async function () {
327 const res1 = await getMyUserInformation(server.url, accessTokenUser)
328 const userMe: MyUser = res1.body
330 const res2 = await getUserInformation(server.url, server.accessToken, userMe.id, true)
331 const userGet: User = res2.body
333 for (const user of [ userMe, userGet ]) {
334 expect(user.username).to.equal('user_1')
335 expect(user.email).to.equal('user_1@example.com')
336 expect(user.nsfwPolicy).to.equal('display')
337 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
338 expect(user.roleLabel).to.equal('User')
339 expect(user.id).to.be.a('number')
340 expect(user.account.displayName).to.equal('user_1')
341 expect(user.account.description).to.be.null
344 expect(userMe.adminFlags).to.be.undefined
345 expect(userGet.adminFlags).to.equal(UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST)
347 expect(userMe.specialPlaylists).to.have.lengthOf(1)
348 expect(userMe.specialPlaylists[0].type).to.equal(VideoPlaylistType.WATCH_LATER)
350 // Check stats are included with withStats
351 expect(userGet.videosCount).to.be.a('number')
352 expect(userGet.videosCount).to.equal(0)
353 expect(userGet.videoCommentsCount).to.be.a('number')
354 expect(userGet.videoCommentsCount).to.equal(0)
355 expect(userGet.abusesCount).to.be.a('number')
356 expect(userGet.abusesCount).to.equal(0)
357 expect(userGet.abusesAcceptedCount).to.be.a('number')
358 expect(userGet.abusesAcceptedCount).to.equal(0)
362 describe('My videos & quotas', function () {
364 it('Should be able to upload a video with this user', async function () {
367 const videoAttributes = {
368 name: 'super user video',
369 fixture: 'video_short.webm'
371 await uploadVideo(server.url, accessTokenUser, videoAttributes)
374 it('Should have video quota updated', async function () {
375 const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser)
376 const data = res.body
378 expect(data.videoQuotaUsed).to.equal(218910)
380 const resUsers = await getUsersList(server.url, server.accessToken)
382 const users: User[] = resUsers.body.data
383 const tmpUser = users.find(u => u.username === user.username)
384 expect(tmpUser.videoQuotaUsed).to.equal(218910)
387 it('Should be able to list my videos', async function () {
388 const res = await getMyVideos(server.url, accessTokenUser, 0, 5)
389 expect(res.body.total).to.equal(1)
391 const videos = res.body.data
392 expect(videos).to.have.lengthOf(1)
394 const video: Video = videos[0]
395 expect(video.name).to.equal('super user video')
396 expect(video.thumbnailPath).to.not.be.null
397 expect(video.previewPath).to.not.be.null
400 it('Should be able to search in my videos', async function () {
402 const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'user video')
403 expect(res.body.total).to.equal(1)
405 const videos = res.body.data
406 expect(videos).to.have.lengthOf(1)
410 const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'toto')
411 expect(res.body.total).to.equal(0)
413 const videos = res.body.data
414 expect(videos).to.have.lengthOf(0)
418 it('Should disable webtorrent, enable HLS, and update my quota', async function () {
422 const res = await getCustomConfig(server.url, server.accessToken)
423 const config = res.body as CustomConfig
424 config.transcoding.webtorrent.enabled = false
425 config.transcoding.hls.enabled = true
426 config.transcoding.enabled = true
427 await updateCustomSubConfig(server.url, server.accessToken, config)
431 const videoAttributes = {
432 name: 'super user video 2',
433 fixture: 'video_short.webm'
435 await uploadVideo(server.url, accessTokenUser, videoAttributes)
437 await waitJobs([ server ])
441 const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser)
442 const data = res.body
444 expect(data.videoQuotaUsed).to.be.greaterThan(220000)
449 describe('Users listing', function () {
451 it('Should list all the users', async function () {
452 const res = await getUsersList(server.url, server.accessToken)
453 const result = res.body
454 const total = result.total
455 const users = result.data
457 expect(total).to.equal(2)
458 expect(users).to.be.an('array')
459 expect(users.length).to.equal(2)
461 const user = users[0]
462 expect(user.username).to.equal('user_1')
463 expect(user.email).to.equal('user_1@example.com')
464 expect(user.nsfwPolicy).to.equal('display')
466 const rootUser = users[1]
467 expect(rootUser.username).to.equal('root')
468 expect(rootUser.email).to.equal('admin' + server.internalServerNumber + '@example.com')
469 expect(user.nsfwPolicy).to.equal('display')
471 expect(rootUser.lastLoginDate).to.exist
472 expect(user.lastLoginDate).to.exist
477 it('Should list only the first user by username asc', async function () {
478 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, 'username')
480 const result = res.body
481 const total = result.total
482 const users = result.data
484 expect(total).to.equal(2)
485 expect(users.length).to.equal(1)
487 const user = users[0]
488 expect(user.username).to.equal('root')
489 expect(user.email).to.equal('admin' + server.internalServerNumber + '@example.com')
490 expect(user.roleLabel).to.equal('Administrator')
491 expect(user.nsfwPolicy).to.equal('display')
494 it('Should list only the first user by username desc', async function () {
495 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-username')
496 const result = res.body
497 const total = result.total
498 const users = result.data
500 expect(total).to.equal(2)
501 expect(users.length).to.equal(1)
503 const user = users[0]
504 expect(user.username).to.equal('user_1')
505 expect(user.email).to.equal('user_1@example.com')
506 expect(user.nsfwPolicy).to.equal('display')
509 it('Should list only the second user by createdAt desc', async function () {
510 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-createdAt')
511 const result = res.body
512 const total = result.total
513 const users = result.data
515 expect(total).to.equal(2)
516 expect(users.length).to.equal(1)
518 const user = users[0]
519 expect(user.username).to.equal('user_1')
520 expect(user.email).to.equal('user_1@example.com')
521 expect(user.nsfwPolicy).to.equal('display')
524 it('Should list all the users by createdAt asc', async function () {
525 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt')
526 const result = res.body
527 const total = result.total
528 const users = result.data
530 expect(total).to.equal(2)
531 expect(users.length).to.equal(2)
533 expect(users[0].username).to.equal('root')
534 expect(users[0].email).to.equal('admin' + server.internalServerNumber + '@example.com')
535 expect(users[0].nsfwPolicy).to.equal('display')
537 expect(users[1].username).to.equal('user_1')
538 expect(users[1].email).to.equal('user_1@example.com')
539 expect(users[1].nsfwPolicy).to.equal('display')
542 it('Should search user by username', async function () {
543 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'oot')
544 const users = res.body.data as User[]
546 expect(res.body.total).to.equal(1)
547 expect(users.length).to.equal(1)
549 expect(users[0].username).to.equal('root')
552 it('Should search user by email', async function () {
554 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'r_1@exam')
555 const users = res.body.data as User[]
557 expect(res.body.total).to.equal(1)
558 expect(users.length).to.equal(1)
560 expect(users[0].username).to.equal('user_1')
561 expect(users[0].email).to.equal('user_1@example.com')
565 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'example')
566 const users = res.body.data as User[]
568 expect(res.body.total).to.equal(2)
569 expect(users.length).to.equal(2)
571 expect(users[0].username).to.equal('root')
572 expect(users[1].username).to.equal('user_1')
577 describe('Update my account', function () {
578 it('Should update my password', async function () {
581 accessToken: accessTokenUser,
582 currentPassword: 'super password',
583 password: 'new password'
585 user.password = 'new password'
587 await userLogin(server, user, HttpStatusCode.OK_200)
590 it('Should be able to change the NSFW display attribute', async function () {
593 accessToken: accessTokenUser,
594 nsfwPolicy: 'do_not_list'
597 const res = await getMyUserInformation(server.url, accessTokenUser)
598 const user = res.body
600 expect(user.username).to.equal('user_1')
601 expect(user.email).to.equal('user_1@example.com')
602 expect(user.nsfwPolicy).to.equal('do_not_list')
603 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
604 expect(user.id).to.be.a('number')
605 expect(user.account.displayName).to.equal('user_1')
606 expect(user.account.description).to.be.null
609 it('Should be able to change the autoPlayVideo attribute', async function () {
612 accessToken: accessTokenUser,
616 const res = await getMyUserInformation(server.url, accessTokenUser)
617 const user = res.body
619 expect(user.autoPlayVideo).to.be.false
622 it('Should be able to change the autoPlayNextVideo attribute', async function () {
625 accessToken: accessTokenUser,
626 autoPlayNextVideo: true
629 const res = await getMyUserInformation(server.url, accessTokenUser)
630 const user = res.body
632 expect(user.autoPlayNextVideo).to.be.true
635 it('Should be able to change the email attribute', async function () {
638 accessToken: accessTokenUser,
639 currentPassword: 'new password',
640 email: 'updated@example.com'
643 const res = await getMyUserInformation(server.url, accessTokenUser)
644 const user = res.body
646 expect(user.username).to.equal('user_1')
647 expect(user.email).to.equal('updated@example.com')
648 expect(user.nsfwPolicy).to.equal('do_not_list')
649 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
650 expect(user.id).to.be.a('number')
651 expect(user.account.displayName).to.equal('user_1')
652 expect(user.account.description).to.be.null
655 it('Should be able to update my avatar with a gif', async function () {
656 const fixture = 'avatar.gif'
658 await updateMyAvatar({
660 accessToken: accessTokenUser,
664 const res = await getMyUserInformation(server.url, accessTokenUser)
665 const user = res.body
667 await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif')
670 it('Should be able to update my avatar with a gif, and then a png', async function () {
671 for (const extension of [ '.png', '.gif' ]) {
672 const fixture = 'avatar' + extension
674 await updateMyAvatar({
676 accessToken: accessTokenUser,
680 const res = await getMyUserInformation(server.url, accessTokenUser)
681 const user = res.body
683 await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension)
687 it('Should be able to update my display name', async function () {
690 accessToken: accessTokenUser,
691 displayName: 'new display name'
694 const res = await getMyUserInformation(server.url, accessTokenUser)
695 const user = res.body
697 expect(user.username).to.equal('user_1')
698 expect(user.email).to.equal('updated@example.com')
699 expect(user.nsfwPolicy).to.equal('do_not_list')
700 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
701 expect(user.id).to.be.a('number')
702 expect(user.account.displayName).to.equal('new display name')
703 expect(user.account.description).to.be.null
706 it('Should be able to update my description', async function () {
709 accessToken: accessTokenUser,
710 description: 'my super description updated'
713 const res = await getMyUserInformation(server.url, accessTokenUser)
714 const user: User = res.body
716 expect(user.username).to.equal('user_1')
717 expect(user.email).to.equal('updated@example.com')
718 expect(user.nsfwPolicy).to.equal('do_not_list')
719 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
720 expect(user.id).to.be.a('number')
721 expect(user.account.displayName).to.equal('new display name')
722 expect(user.account.description).to.equal('my super description updated')
723 expect(user.noWelcomeModal).to.be.false
724 expect(user.noInstanceConfigWarningModal).to.be.false
727 it('Should be able to update my theme', async function () {
728 for (const theme of [ 'background-red', 'default', 'instance-default' ]) {
731 accessToken: accessTokenUser,
735 const res = await getMyUserInformation(server.url, accessTokenUser)
736 const body: User = res.body
738 expect(body.theme).to.equal(theme)
742 it('Should be able to update my modal preferences', async function () {
745 accessToken: accessTokenUser,
746 noInstanceConfigWarningModal: true,
750 const res = await getMyUserInformation(server.url, accessTokenUser)
751 const user: User = res.body
753 expect(user.noWelcomeModal).to.be.true
754 expect(user.noInstanceConfigWarningModal).to.be.true
758 describe('Updating another user', function () {
759 it('Should be able to update another user', async function () {
764 email: 'updated2@example.com',
767 role: UserRole.MODERATOR,
768 adminFlags: UserAdminFlag.NONE,
772 const res = await getUserInformation(server.url, accessToken, userId)
773 const user = res.body as User
775 expect(user.username).to.equal('user_1')
776 expect(user.email).to.equal('updated2@example.com')
777 expect(user.emailVerified).to.be.true
778 expect(user.nsfwPolicy).to.equal('do_not_list')
779 expect(user.videoQuota).to.equal(42)
780 expect(user.roleLabel).to.equal('Moderator')
781 expect(user.id).to.be.a('number')
782 expect(user.adminFlags).to.equal(UserAdminFlag.NONE)
783 expect(user.pluginAuth).to.equal('toto')
786 it('Should reset the auth plugin', async function () {
787 await updateUser({ url: server.url, userId, accessToken, pluginAuth: null })
789 const res = await getUserInformation(server.url, accessToken, userId)
790 const user = res.body as User
791 expect(user.pluginAuth).to.be.null
794 it('Should have removed the user token', async function () {
795 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401)
797 accessTokenUser = await userLogin(server, user)
800 it('Should be able to update another user password', async function () {
805 password: 'password updated'
808 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401)
810 await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400)
812 user.password = 'password updated'
813 accessTokenUser = await userLogin(server, user)
817 describe('Video blacklists', function () {
818 it('Should be able to list video blacklist by a moderator', async function () {
819 await getBlacklistedVideosList({ url: server.url, token: accessTokenUser })
823 describe('Remove a user', function () {
824 it('Should be able to remove this user', async function () {
825 await removeUser(server.url, userId, accessToken)
828 it('Should not be able to login with this user', async function () {
829 await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400)
832 it('Should not have videos of this user', async function () {
833 const res = await getVideosList(server.url)
835 expect(res.body.total).to.equal(1)
837 const video = res.body.data[0]
838 expect(video.account.name).to.equal('root')
842 describe('Registering a new user', function () {
843 let user15AccessToken
845 it('Should register a new user', async function () {
846 const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' }
847 const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' }
849 await registerUserWithChannel({ url: server.url, user, channel })
852 it('Should be able to login with this registered user', async function () {
855 password: 'my super password'
858 user15AccessToken = await userLogin(server, user15)
861 it('Should have the correct display name', async function () {
862 const res = await getMyUserInformation(server.url, user15AccessToken)
863 const user: User = res.body
865 expect(user.account.displayName).to.equal('super user 15')
868 it('Should have the correct video quota', async function () {
869 const res = await getMyUserInformation(server.url, user15AccessToken)
870 const user = res.body
872 expect(user.videoQuota).to.equal(5 * 1024 * 1024)
875 it('Should have created the channel', async function () {
876 const res = await getVideoChannel(server.url, 'my_user_15_channel')
878 expect(res.body.displayName).to.equal('my channel rocks')
881 it('Should remove me', async function () {
883 const res = await getUsersList(server.url, server.accessToken)
884 expect(res.body.data.find(u => u.username === 'user_15')).to.not.be.undefined
887 await deleteMe(server.url, user15AccessToken)
890 const res = await getUsersList(server.url, server.accessToken)
891 expect(res.body.data.find(u => u.username === 'user_15')).to.be.undefined
896 describe('User blocking', function () {
898 let user16AccessToken
901 password: 'my super password'
904 it('Should block a user', async function () {
905 const resUser = await createUser({
907 accessToken: server.accessToken,
908 username: user16.username,
909 password: user16.password
911 user16Id = resUser.body.user.id
913 user16AccessToken = await userLogin(server, user16)
915 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200)
916 await blockUser(server.url, user16Id, server.accessToken)
918 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.UNAUTHORIZED_401)
919 await userLogin(server, user16, HttpStatusCode.BAD_REQUEST_400)
922 it('Should search user by banned status', async function () {
924 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', undefined, true)
925 const users = res.body.data as User[]
927 expect(res.body.total).to.equal(1)
928 expect(users.length).to.equal(1)
930 expect(users[0].username).to.equal(user16.username)
934 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', undefined, false)
935 const users = res.body.data as User[]
937 expect(res.body.total).to.equal(1)
938 expect(users.length).to.equal(1)
940 expect(users[0].username).to.not.equal(user16.username)
944 it('Should unblock a user', async function () {
945 await unblockUser(server.url, user16Id, server.accessToken)
946 user16AccessToken = await userLogin(server, user16)
947 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200)
951 describe('User stats', function () {
953 let user17AccessToken
955 it('Should report correct initial statistics about a user', async function () {
958 password: 'my super password'
960 const resUser = await createUser({
962 accessToken: server.accessToken,
963 username: user17.username,
964 password: user17.password
967 user17Id = resUser.body.user.id
968 user17AccessToken = await userLogin(server, user17)
970 const res = await getUserInformation(server.url, server.accessToken, user17Id, true)
971 const user: User = res.body
973 expect(user.videosCount).to.equal(0)
974 expect(user.videoCommentsCount).to.equal(0)
975 expect(user.abusesCount).to.equal(0)
976 expect(user.abusesCreatedCount).to.equal(0)
977 expect(user.abusesAcceptedCount).to.equal(0)
980 it('Should report correct videos count', async function () {
981 const videoAttributes = {
982 name: 'video to test user stats'
984 await uploadVideo(server.url, user17AccessToken, videoAttributes)
985 const res1 = await getVideosList(server.url)
986 videoId = res1.body.data.find(video => video.name === videoAttributes.name).id
988 const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true)
989 const user: User = res2.body
991 expect(user.videosCount).to.equal(1)
994 it('Should report correct video comments for user', async function () {
995 const text = 'super comment'
996 await addVideoCommentThread(server.url, user17AccessToken, videoId, text)
998 const res = await getUserInformation(server.url, server.accessToken, user17Id, true)
999 const user: User = res.body
1001 expect(user.videoCommentsCount).to.equal(1)
1004 it('Should report correct abuses counts', async function () {
1005 const reason = 'my super bad reason'
1006 await server.abusesCommand.report({ token: user17AccessToken, videoId, reason })
1008 const body1 = await server.abusesCommand.getAdminList()
1009 const abuseId = body1.data[0].id
1011 const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true)
1012 const user2: User = res2.body
1014 expect(user2.abusesCount).to.equal(1) // number of incriminations
1015 expect(user2.abusesCreatedCount).to.equal(1) // number of reports created
1017 await server.abusesCommand.update({ abuseId, body: { state: AbuseState.ACCEPTED } })
1019 const res3 = await getUserInformation(server.url, server.accessToken, user17Id, true)
1020 const user3: User = res3.body
1022 expect(user3.abusesAcceptedCount).to.equal(1) // number of reports created accepted
1026 after(async function () {
1027 await closeAllSequelize([ server ])
1028 await cleanupTests([ server ])