1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { AbuseState, AbuseUpdate, MyUser, User, UserRole, Video, VideoPlaylistType } from '@shared/models'
6 import { CustomConfig } from '@shared/models/server'
16 getBlacklistedVideosList,
19 getMyUserVideoQuotaUsed,
23 getUsersListPaginationAndSort,
30 registerUserWithChannel,
38 updateCustomSubConfig,
45 } from '../../../../shared/extra-utils'
46 import { follow } from '../../../../shared/extra-utils/server/follows'
47 import { logout, serverLogin, setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
48 import { getMyVideos } from '../../../../shared/extra-utils/videos/videos'
49 import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
50 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
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.error).to.contain('client is invalid')
95 it('Should not login with an invalid client secret', async function () {
96 const client = { id: server.client.id, secret: 'coucou' }
97 const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400)
99 expect(res.body.error).to.contain('client is invalid')
103 describe('Login', function () {
105 it('Should not login with an invalid username', async function () {
106 const user = { username: 'captain crochet', password: server.user.password }
107 const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400)
109 expect(res.body.error).to.contain('credentials are invalid')
112 it('Should not login with an invalid password', async function () {
113 const user = { username: server.user.username, password: 'mew_three' }
114 const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400)
116 expect(res.body.error).to.contain('credentials are invalid')
119 it('Should not be able to upload a video', async function () {
120 accessToken = 'my_super_token'
122 const videoAttributes = {}
123 await uploadVideo(server.url, accessToken, videoAttributes, HttpStatusCode.UNAUTHORIZED_401)
126 it('Should not be able to follow', async function () {
127 accessToken = 'my_super_token'
128 await follow(server.url, [ 'http://example.com' ], accessToken, HttpStatusCode.UNAUTHORIZED_401)
131 it('Should not be able to unfollow')
133 it('Should be able to login', async function () {
134 const res = await login(server.url, server.client, server.user, HttpStatusCode.OK_200)
136 accessToken = res.body.access_token
139 it('Should be able to login with an insensitive username', async function () {
140 const user = { username: 'RoOt', password: server.user.password }
141 await login(server.url, server.client, user, HttpStatusCode.OK_200)
143 const user2 = { username: 'rOoT', password: server.user.password }
144 await login(server.url, server.client, user2, HttpStatusCode.OK_200)
146 const user3 = { username: 'ROOt', password: server.user.password }
147 await login(server.url, server.client, user3, HttpStatusCode.OK_200)
151 describe('Upload', function () {
153 it('Should upload the video with the correct token', async function () {
154 const videoAttributes = {}
155 await uploadVideo(server.url, accessToken, videoAttributes)
156 const res = await getVideosList(server.url)
157 const video = res.body.data[0]
159 expect(video.account.name).to.equal('root')
163 it('Should upload the video again with the correct token', async function () {
164 const videoAttributes = {}
165 await uploadVideo(server.url, accessToken, videoAttributes)
169 describe('Ratings', function () {
171 it('Should retrieve a video rating', async function () {
172 await rateVideo(server.url, accessToken, videoId, 'like')
173 const res = await getMyUserVideoRating(server.url, accessToken, videoId)
174 const rating = res.body
176 expect(rating.videoId).to.equal(videoId)
177 expect(rating.rating).to.equal('like')
180 it('Should retrieve ratings list', async function () {
181 await rateVideo(server.url, accessToken, videoId, 'like')
183 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, HttpStatusCode.OK_200)
184 const ratings = res.body
186 expect(ratings.total).to.equal(1)
187 expect(ratings.data[0].video.id).to.equal(videoId)
188 expect(ratings.data[0].rating).to.equal('like')
191 it('Should retrieve ratings list by rating type', async function () {
193 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'like')
194 const ratings = res.body
195 expect(ratings.data.length).to.equal(1)
199 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'dislike')
200 const ratings = res.body
201 expect(ratings.data.length).to.equal(0)
206 describe('Remove video', function () {
207 it('Should not be able to remove the video with an incorrect token', async function () {
208 await removeVideo(server.url, 'bad_token', videoId, HttpStatusCode.UNAUTHORIZED_401)
211 it('Should not be able to remove the video with the token of another account')
213 it('Should be able to remove the video with the correct token', async function () {
214 await removeVideo(server.url, accessToken, videoId)
218 describe('Logout', function () {
219 it('Should logout (revoke token)', async function () {
220 await logout(server.url, server.accessToken)
223 it('Should not be able to get the user information', async function () {
224 await getMyUserInformation(server.url, server.accessToken, HttpStatusCode.UNAUTHORIZED_401)
227 it('Should not be able to upload a video', async function () {
228 await uploadVideo(server.url, server.accessToken, { name: 'video' }, HttpStatusCode.UNAUTHORIZED_401)
231 it('Should not be able to rate a video', async function () {
232 const path = '/api/v1/videos/'
239 path: path + videoId,
240 token: 'wrong token',
242 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
244 await makePutBodyRequest(options)
247 it('Should be able to login again', async function () {
248 server.accessToken = await serverLogin(server)
251 it('Should have an expired access token')
253 it('Should refresh the token')
255 it('Should be able to get my user information again', async function () {
256 await getMyUserInformation(server.url, server.accessToken)
260 describe('Creating a user', function () {
262 it('Should be able to create a new user', async function () {
265 accessToken: accessToken,
266 username: user.username,
267 password: user.password,
268 videoQuota: 2 * 1024 * 1024,
269 adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST
273 it('Should be able to login with this user', async function () {
274 accessTokenUser = await userLogin(server, user)
277 it('Should be able to get user information', async function () {
278 const res1 = await getMyUserInformation(server.url, accessTokenUser)
279 const userMe: MyUser = res1.body
281 const res2 = await getUserInformation(server.url, server.accessToken, userMe.id, true)
282 const userGet: User = res2.body
284 for (const user of [ userMe, userGet ]) {
285 expect(user.username).to.equal('user_1')
286 expect(user.email).to.equal('user_1@example.com')
287 expect(user.nsfwPolicy).to.equal('display')
288 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
289 expect(user.roleLabel).to.equal('User')
290 expect(user.id).to.be.a('number')
291 expect(user.account.displayName).to.equal('user_1')
292 expect(user.account.description).to.be.null
295 expect(userMe.adminFlags).to.be.undefined
296 expect(userGet.adminFlags).to.equal(UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST)
298 expect(userMe.specialPlaylists).to.have.lengthOf(1)
299 expect(userMe.specialPlaylists[0].type).to.equal(VideoPlaylistType.WATCH_LATER)
301 // Check stats are included with withStats
302 expect(userGet.videosCount).to.be.a('number')
303 expect(userGet.videosCount).to.equal(0)
304 expect(userGet.videoCommentsCount).to.be.a('number')
305 expect(userGet.videoCommentsCount).to.equal(0)
306 expect(userGet.abusesCount).to.be.a('number')
307 expect(userGet.abusesCount).to.equal(0)
308 expect(userGet.abusesAcceptedCount).to.be.a('number')
309 expect(userGet.abusesAcceptedCount).to.equal(0)
313 describe('My videos & quotas', function () {
315 it('Should be able to upload a video with this user', async function () {
318 const videoAttributes = {
319 name: 'super user video',
320 fixture: 'video_short.webm'
322 await uploadVideo(server.url, accessTokenUser, videoAttributes)
325 it('Should have video quota updated', async function () {
326 const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser)
327 const data = res.body
329 expect(data.videoQuotaUsed).to.equal(218910)
331 const resUsers = await getUsersList(server.url, server.accessToken)
333 const users: User[] = resUsers.body.data
334 const tmpUser = users.find(u => u.username === user.username)
335 expect(tmpUser.videoQuotaUsed).to.equal(218910)
338 it('Should be able to list my videos', async function () {
339 const res = await getMyVideos(server.url, accessTokenUser, 0, 5)
340 expect(res.body.total).to.equal(1)
342 const videos = res.body.data
343 expect(videos).to.have.lengthOf(1)
345 const video: Video = videos[0]
346 expect(video.name).to.equal('super user video')
347 expect(video.thumbnailPath).to.not.be.null
348 expect(video.previewPath).to.not.be.null
351 it('Should be able to search in my videos', async function () {
353 const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'user video')
354 expect(res.body.total).to.equal(1)
356 const videos = res.body.data
357 expect(videos).to.have.lengthOf(1)
361 const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'toto')
362 expect(res.body.total).to.equal(0)
364 const videos = res.body.data
365 expect(videos).to.have.lengthOf(0)
369 it('Should disable webtorrent, enable HLS, and update my quota', async function () {
373 const res = await getCustomConfig(server.url, server.accessToken)
374 const config = res.body as CustomConfig
375 config.transcoding.webtorrent.enabled = false
376 config.transcoding.hls.enabled = true
377 config.transcoding.enabled = true
378 await updateCustomSubConfig(server.url, server.accessToken, config)
382 const videoAttributes = {
383 name: 'super user video 2',
384 fixture: 'video_short.webm'
386 await uploadVideo(server.url, accessTokenUser, videoAttributes)
388 await waitJobs([ server ])
392 const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser)
393 const data = res.body
395 expect(data.videoQuotaUsed).to.be.greaterThan(220000)
400 describe('Users listing', function () {
402 it('Should list all the users', async function () {
403 const res = await getUsersList(server.url, server.accessToken)
404 const result = res.body
405 const total = result.total
406 const users = result.data
408 expect(total).to.equal(2)
409 expect(users).to.be.an('array')
410 expect(users.length).to.equal(2)
412 const user = users[0]
413 expect(user.username).to.equal('user_1')
414 expect(user.email).to.equal('user_1@example.com')
415 expect(user.nsfwPolicy).to.equal('display')
417 const rootUser = users[1]
418 expect(rootUser.username).to.equal('root')
419 expect(rootUser.email).to.equal('admin' + server.internalServerNumber + '@example.com')
420 expect(user.nsfwPolicy).to.equal('display')
422 expect(rootUser.lastLoginDate).to.exist
423 expect(user.lastLoginDate).to.exist
428 it('Should list only the first user by username asc', async function () {
429 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, 'username')
431 const result = res.body
432 const total = result.total
433 const users = result.data
435 expect(total).to.equal(2)
436 expect(users.length).to.equal(1)
438 const user = users[0]
439 expect(user.username).to.equal('root')
440 expect(user.email).to.equal('admin' + server.internalServerNumber + '@example.com')
441 expect(user.roleLabel).to.equal('Administrator')
442 expect(user.nsfwPolicy).to.equal('display')
445 it('Should list only the first user by username desc', async function () {
446 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-username')
447 const result = res.body
448 const total = result.total
449 const users = result.data
451 expect(total).to.equal(2)
452 expect(users.length).to.equal(1)
454 const user = users[0]
455 expect(user.username).to.equal('user_1')
456 expect(user.email).to.equal('user_1@example.com')
457 expect(user.nsfwPolicy).to.equal('display')
460 it('Should list only the second user by createdAt desc', async function () {
461 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-createdAt')
462 const result = res.body
463 const total = result.total
464 const users = result.data
466 expect(total).to.equal(2)
467 expect(users.length).to.equal(1)
469 const user = users[0]
470 expect(user.username).to.equal('user_1')
471 expect(user.email).to.equal('user_1@example.com')
472 expect(user.nsfwPolicy).to.equal('display')
475 it('Should list all the users by createdAt asc', async function () {
476 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt')
477 const result = res.body
478 const total = result.total
479 const users = result.data
481 expect(total).to.equal(2)
482 expect(users.length).to.equal(2)
484 expect(users[0].username).to.equal('root')
485 expect(users[0].email).to.equal('admin' + server.internalServerNumber + '@example.com')
486 expect(users[0].nsfwPolicy).to.equal('display')
488 expect(users[1].username).to.equal('user_1')
489 expect(users[1].email).to.equal('user_1@example.com')
490 expect(users[1].nsfwPolicy).to.equal('display')
493 it('Should search user by username', async function () {
494 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'oot')
495 const users = res.body.data as User[]
497 expect(res.body.total).to.equal(1)
498 expect(users.length).to.equal(1)
500 expect(users[0].username).to.equal('root')
503 it('Should search user by email', async function () {
505 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'r_1@exam')
506 const users = res.body.data as User[]
508 expect(res.body.total).to.equal(1)
509 expect(users.length).to.equal(1)
511 expect(users[0].username).to.equal('user_1')
512 expect(users[0].email).to.equal('user_1@example.com')
516 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'example')
517 const users = res.body.data as User[]
519 expect(res.body.total).to.equal(2)
520 expect(users.length).to.equal(2)
522 expect(users[0].username).to.equal('root')
523 expect(users[1].username).to.equal('user_1')
528 describe('Update my account', function () {
529 it('Should update my password', async function () {
532 accessToken: accessTokenUser,
533 currentPassword: 'super password',
534 password: 'new password'
536 user.password = 'new password'
538 await userLogin(server, user, HttpStatusCode.OK_200)
541 it('Should be able to change the NSFW display attribute', async function () {
544 accessToken: accessTokenUser,
545 nsfwPolicy: 'do_not_list'
548 const res = await getMyUserInformation(server.url, accessTokenUser)
549 const user = res.body
551 expect(user.username).to.equal('user_1')
552 expect(user.email).to.equal('user_1@example.com')
553 expect(user.nsfwPolicy).to.equal('do_not_list')
554 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
555 expect(user.id).to.be.a('number')
556 expect(user.account.displayName).to.equal('user_1')
557 expect(user.account.description).to.be.null
560 it('Should be able to change the autoPlayVideo attribute', async function () {
563 accessToken: accessTokenUser,
567 const res = await getMyUserInformation(server.url, accessTokenUser)
568 const user = res.body
570 expect(user.autoPlayVideo).to.be.false
573 it('Should be able to change the autoPlayNextVideo attribute', async function () {
576 accessToken: accessTokenUser,
577 autoPlayNextVideo: true
580 const res = await getMyUserInformation(server.url, accessTokenUser)
581 const user = res.body
583 expect(user.autoPlayNextVideo).to.be.true
586 it('Should be able to change the email attribute', async function () {
589 accessToken: accessTokenUser,
590 currentPassword: 'new password',
591 email: 'updated@example.com'
594 const res = await getMyUserInformation(server.url, accessTokenUser)
595 const user = res.body
597 expect(user.username).to.equal('user_1')
598 expect(user.email).to.equal('updated@example.com')
599 expect(user.nsfwPolicy).to.equal('do_not_list')
600 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
601 expect(user.id).to.be.a('number')
602 expect(user.account.displayName).to.equal('user_1')
603 expect(user.account.description).to.be.null
606 it('Should be able to update my avatar with a gif', async function () {
607 const fixture = 'avatar.gif'
609 await updateMyAvatar({
611 accessToken: accessTokenUser,
615 const res = await getMyUserInformation(server.url, accessTokenUser)
616 const user = res.body
618 await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif')
621 it('Should be able to update my avatar with a gif, and then a png', async function () {
622 for (const extension of [ '.png', '.gif' ]) {
623 const fixture = 'avatar' + extension
625 await updateMyAvatar({
627 accessToken: accessTokenUser,
631 const res = await getMyUserInformation(server.url, accessTokenUser)
632 const user = res.body
634 await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension)
638 it('Should be able to update my display name', async function () {
641 accessToken: accessTokenUser,
642 displayName: 'new display name'
645 const res = await getMyUserInformation(server.url, accessTokenUser)
646 const user = res.body
648 expect(user.username).to.equal('user_1')
649 expect(user.email).to.equal('updated@example.com')
650 expect(user.nsfwPolicy).to.equal('do_not_list')
651 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
652 expect(user.id).to.be.a('number')
653 expect(user.account.displayName).to.equal('new display name')
654 expect(user.account.description).to.be.null
657 it('Should be able to update my description', async function () {
660 accessToken: accessTokenUser,
661 description: 'my super description updated'
664 const res = await getMyUserInformation(server.url, accessTokenUser)
665 const user: User = res.body
667 expect(user.username).to.equal('user_1')
668 expect(user.email).to.equal('updated@example.com')
669 expect(user.nsfwPolicy).to.equal('do_not_list')
670 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
671 expect(user.id).to.be.a('number')
672 expect(user.account.displayName).to.equal('new display name')
673 expect(user.account.description).to.equal('my super description updated')
674 expect(user.noWelcomeModal).to.be.false
675 expect(user.noInstanceConfigWarningModal).to.be.false
678 it('Should be able to update my theme', async function () {
679 for (const theme of [ 'background-red', 'default', 'instance-default' ]) {
682 accessToken: accessTokenUser,
686 const res = await getMyUserInformation(server.url, accessTokenUser)
687 const body: User = res.body
689 expect(body.theme).to.equal(theme)
693 it('Should be able to update my modal preferences', async function () {
696 accessToken: accessTokenUser,
697 noInstanceConfigWarningModal: true,
701 const res = await getMyUserInformation(server.url, accessTokenUser)
702 const user: User = res.body
704 expect(user.noWelcomeModal).to.be.true
705 expect(user.noInstanceConfigWarningModal).to.be.true
709 describe('Updating another user', function () {
710 it('Should be able to update another user', async function () {
715 email: 'updated2@example.com',
718 role: UserRole.MODERATOR,
719 adminFlags: UserAdminFlag.NONE,
723 const res = await getUserInformation(server.url, accessToken, userId)
724 const user = res.body as User
726 expect(user.username).to.equal('user_1')
727 expect(user.email).to.equal('updated2@example.com')
728 expect(user.emailVerified).to.be.true
729 expect(user.nsfwPolicy).to.equal('do_not_list')
730 expect(user.videoQuota).to.equal(42)
731 expect(user.roleLabel).to.equal('Moderator')
732 expect(user.id).to.be.a('number')
733 expect(user.adminFlags).to.equal(UserAdminFlag.NONE)
734 expect(user.pluginAuth).to.equal('toto')
737 it('Should reset the auth plugin', async function () {
738 await updateUser({ url: server.url, userId, accessToken, pluginAuth: null })
740 const res = await getUserInformation(server.url, accessToken, userId)
741 const user = res.body as User
742 expect(user.pluginAuth).to.be.null
745 it('Should have removed the user token', async function () {
746 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401)
748 accessTokenUser = await userLogin(server, user)
751 it('Should be able to update another user password', async function () {
756 password: 'password updated'
759 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401)
761 await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400)
763 user.password = 'password updated'
764 accessTokenUser = await userLogin(server, user)
768 describe('Video blacklists', function () {
769 it('Should be able to list video blacklist by a moderator', async function () {
770 await getBlacklistedVideosList({ url: server.url, token: accessTokenUser })
774 describe('Remove a user', function () {
775 it('Should be able to remove this user', async function () {
776 await removeUser(server.url, userId, accessToken)
779 it('Should not be able to login with this user', async function () {
780 await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400)
783 it('Should not have videos of this user', async function () {
784 const res = await getVideosList(server.url)
786 expect(res.body.total).to.equal(1)
788 const video = res.body.data[0]
789 expect(video.account.name).to.equal('root')
793 describe('Registering a new user', function () {
794 let user15AccessToken
796 it('Should register a new user', async function () {
797 const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' }
798 const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' }
800 await registerUserWithChannel({ url: server.url, user, channel })
803 it('Should be able to login with this registered user', async function () {
806 password: 'my super password'
809 user15AccessToken = await userLogin(server, user15)
812 it('Should have the correct display name', async function () {
813 const res = await getMyUserInformation(server.url, user15AccessToken)
814 const user: User = res.body
816 expect(user.account.displayName).to.equal('super user 15')
819 it('Should have the correct video quota', async function () {
820 const res = await getMyUserInformation(server.url, user15AccessToken)
821 const user = res.body
823 expect(user.videoQuota).to.equal(5 * 1024 * 1024)
826 it('Should have created the channel', async function () {
827 const res = await getVideoChannel(server.url, 'my_user_15_channel')
829 expect(res.body.displayName).to.equal('my channel rocks')
832 it('Should remove me', async function () {
834 const res = await getUsersList(server.url, server.accessToken)
835 expect(res.body.data.find(u => u.username === 'user_15')).to.not.be.undefined
838 await deleteMe(server.url, user15AccessToken)
841 const res = await getUsersList(server.url, server.accessToken)
842 expect(res.body.data.find(u => u.username === 'user_15')).to.be.undefined
847 describe('User blocking', function () {
849 let user16AccessToken
852 password: 'my super password'
855 it('Should block a user', async function () {
856 const resUser = await createUser({
858 accessToken: server.accessToken,
859 username: user16.username,
860 password: user16.password
862 user16Id = resUser.body.user.id
864 user16AccessToken = await userLogin(server, user16)
866 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200)
867 await blockUser(server.url, user16Id, server.accessToken)
869 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.UNAUTHORIZED_401)
870 await userLogin(server, user16, HttpStatusCode.BAD_REQUEST_400)
873 it('Should search user by banned status', async function () {
875 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', undefined, true)
876 const users = res.body.data as User[]
878 expect(res.body.total).to.equal(1)
879 expect(users.length).to.equal(1)
881 expect(users[0].username).to.equal(user16.username)
885 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', undefined, false)
886 const users = res.body.data as User[]
888 expect(res.body.total).to.equal(1)
889 expect(users.length).to.equal(1)
891 expect(users[0].username).to.not.equal(user16.username)
895 it('Should unblock a user', async function () {
896 await unblockUser(server.url, user16Id, server.accessToken)
897 user16AccessToken = await userLogin(server, user16)
898 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200)
902 describe('User stats', function () {
904 let user17AccessToken
906 it('Should report correct initial statistics about a user', async function () {
909 password: 'my super password'
911 const resUser = await createUser({
913 accessToken: server.accessToken,
914 username: user17.username,
915 password: user17.password
918 user17Id = resUser.body.user.id
919 user17AccessToken = await userLogin(server, user17)
921 const res = await getUserInformation(server.url, server.accessToken, user17Id, true)
922 const user: User = res.body
924 expect(user.videosCount).to.equal(0)
925 expect(user.videoCommentsCount).to.equal(0)
926 expect(user.abusesCount).to.equal(0)
927 expect(user.abusesCreatedCount).to.equal(0)
928 expect(user.abusesAcceptedCount).to.equal(0)
931 it('Should report correct videos count', async function () {
932 const videoAttributes = {
933 name: 'video to test user stats'
935 await uploadVideo(server.url, user17AccessToken, videoAttributes)
936 const res1 = await getVideosList(server.url)
937 videoId = res1.body.data.find(video => video.name === videoAttributes.name).id
939 const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true)
940 const user: User = res2.body
942 expect(user.videosCount).to.equal(1)
945 it('Should report correct video comments for user', async function () {
946 const text = 'super comment'
947 await addVideoCommentThread(server.url, user17AccessToken, videoId, text)
949 const res = await getUserInformation(server.url, server.accessToken, user17Id, true)
950 const user: User = res.body
952 expect(user.videoCommentsCount).to.equal(1)
955 it('Should report correct abuses counts', async function () {
956 const reason = 'my super bad reason'
957 await reportAbuse({ url: server.url, token: user17AccessToken, videoId, reason })
959 const res1 = await getAdminAbusesList({ url: server.url, token: server.accessToken })
960 const abuseId = res1.body.data[0].id
962 const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true)
963 const user2: User = res2.body
965 expect(user2.abusesCount).to.equal(1) // number of incriminations
966 expect(user2.abusesCreatedCount).to.equal(1) // number of reports created
968 const body: AbuseUpdate = { state: AbuseState.ACCEPTED }
969 await updateAbuse(server.url, server.accessToken, abuseId, body)
971 const res3 = await getUserInformation(server.url, server.accessToken, user17Id, true)
972 const user3: User = res3.body
974 expect(user3.abusesAcceptedCount).to.equal(1) // number of reports created accepted
978 after(async function () {
979 await cleanupTests([ server ])