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'
7 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
18 getBlacklistedVideosList,
21 getMyUserVideoQuotaUsed,
25 getUsersListPaginationAndSort,
33 registerUserWithChannel,
43 updateCustomSubConfig,
50 } from '../../../../shared/extra-utils'
51 import { follow } from '../../../../shared/extra-utils/server/follows'
52 import { logout, refreshToken, setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
53 import { getMyVideos } from '../../../../shared/extra-utils/videos/videos'
54 import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
56 const expect = chai.expect
58 describe('Test users', function () {
59 let server: ServerInfo
60 let accessToken: string
61 let accessTokenUser: string
66 password: 'super password'
69 before(async function () {
72 server = await flushAndRunServer(1, {
80 await setAccessTokensToServers([ server ])
82 await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-theme-background-red' })
85 describe('OAuth client', function () {
86 it('Should create a new client')
88 it('Should return the first client')
90 it('Should remove the last client')
92 it('Should not login with an invalid client id', async function () {
93 const client = { id: 'client', secret: server.client.secret }
94 const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400)
96 expect(res.body.code).to.equal('invalid_client')
97 expect(res.body.error).to.contain('client is invalid')
100 it('Should not login with an invalid client secret', async function () {
101 const client = { id: server.client.id, secret: 'coucou' }
102 const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400)
104 expect(res.body.code).to.equal('invalid_client')
105 expect(res.body.error).to.contain('client is invalid')
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('invalid_grant')
116 expect(res.body.error).to.contain('credentials are invalid')
119 it('Should not login with an invalid password', async function () {
120 const user = { username: server.user.username, password: 'mew_three' }
121 const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400)
123 expect(res.body.code).to.equal('invalid_grant')
124 expect(res.body.error).to.contain('credentials are invalid')
127 it('Should not be able to upload a video', async function () {
128 accessToken = 'my_super_token'
130 const videoAttributes = {}
131 await uploadVideo(server.url, accessToken, videoAttributes, HttpStatusCode.UNAUTHORIZED_401)
134 it('Should not be able to follow', async function () {
135 accessToken = 'my_super_token'
136 await follow(server.url, [ 'http://example.com' ], accessToken, HttpStatusCode.UNAUTHORIZED_401)
139 it('Should not be able to unfollow')
141 it('Should be able to login', async function () {
142 const res = await login(server.url, server.client, server.user, HttpStatusCode.OK_200)
144 accessToken = res.body.access_token
147 it('Should be able to login with an insensitive username', async function () {
148 const user = { username: 'RoOt', password: server.user.password }
149 await login(server.url, server.client, user, HttpStatusCode.OK_200)
151 const user2 = { username: 'rOoT', password: server.user.password }
152 await login(server.url, server.client, user2, HttpStatusCode.OK_200)
154 const user3 = { username: 'ROOt', password: server.user.password }
155 await login(server.url, server.client, user3, HttpStatusCode.OK_200)
159 describe('Upload', function () {
161 it('Should upload the video with the correct token', async function () {
162 const videoAttributes = {}
163 await uploadVideo(server.url, accessToken, videoAttributes)
164 const res = await getVideosList(server.url)
165 const video = res.body.data[0]
167 expect(video.account.name).to.equal('root')
171 it('Should upload the video again with the correct token', async function () {
172 const videoAttributes = {}
173 await uploadVideo(server.url, accessToken, videoAttributes)
177 describe('Ratings', function () {
179 it('Should retrieve a video rating', async function () {
180 await rateVideo(server.url, accessToken, videoId, 'like')
181 const res = await getMyUserVideoRating(server.url, accessToken, videoId)
182 const rating = res.body
184 expect(rating.videoId).to.equal(videoId)
185 expect(rating.rating).to.equal('like')
188 it('Should retrieve ratings list', async function () {
189 await rateVideo(server.url, accessToken, videoId, 'like')
191 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, HttpStatusCode.OK_200)
192 const ratings = res.body
194 expect(ratings.total).to.equal(1)
195 expect(ratings.data[0].video.id).to.equal(videoId)
196 expect(ratings.data[0].rating).to.equal('like')
199 it('Should retrieve ratings list by rating type', async function () {
201 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'like')
202 const ratings = res.body
203 expect(ratings.data.length).to.equal(1)
207 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'dislike')
208 const ratings = res.body
209 expect(ratings.data.length).to.equal(0)
214 describe('Remove video', function () {
215 it('Should not be able to remove the video with an incorrect token', async function () {
216 await removeVideo(server.url, 'bad_token', videoId, HttpStatusCode.UNAUTHORIZED_401)
219 it('Should not be able to remove the video with the token of another account')
221 it('Should be able to remove the video with the correct token', async function () {
222 await removeVideo(server.url, accessToken, videoId)
226 describe('Logout', function () {
227 it('Should logout (revoke token)', async function () {
228 await logout(server.url, server.accessToken)
231 it('Should not be able to get the user information', async function () {
232 await getMyUserInformation(server.url, server.accessToken, HttpStatusCode.UNAUTHORIZED_401)
235 it('Should not be able to upload a video', async function () {
236 await uploadVideo(server.url, server.accessToken, { name: 'video' }, HttpStatusCode.UNAUTHORIZED_401)
239 it('Should not be able to rate a video', async function () {
240 const path = '/api/v1/videos/'
247 path: path + videoId,
248 token: 'wrong token',
250 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
252 await makePutBodyRequest(options)
255 it('Should be able to login again', async function () {
256 const res = await login(server.url, server.client, server.user)
257 server.accessToken = res.body.access_token
258 server.refreshToken = res.body.refresh_token
261 it('Should be able to get my user information again', async function () {
262 await getMyUserInformation(server.url, server.accessToken)
265 it('Should have an expired access token', async function () {
268 await setTokenField(server.internalServerNumber, server.accessToken, 'accessTokenExpiresAt', new Date().toISOString())
269 await setTokenField(server.internalServerNumber, server.accessToken, 'refreshTokenExpiresAt', new Date().toISOString())
271 killallServers([ server ])
272 await reRunServer(server)
274 await getMyUserInformation(server.url, server.accessToken, 401)
277 it('Should not be able to refresh an access token with an expired refresh token', async function () {
278 await refreshToken(server, server.refreshToken, 400)
281 it('Should refresh the token', async function () {
284 const futureDate = new Date(new Date().getTime() + 1000 * 60).toISOString()
285 await setTokenField(server.internalServerNumber, server.accessToken, 'refreshTokenExpiresAt', futureDate)
287 killallServers([ server ])
288 await reRunServer(server)
290 const res = await refreshToken(server, server.refreshToken)
291 server.accessToken = res.body.access_token
292 server.refreshToken = res.body.refresh_token
295 it('Should be able to get my user information again', async function () {
296 await getMyUserInformation(server.url, server.accessToken)
300 describe('Creating a user', function () {
302 it('Should be able to create a new user', async function () {
305 accessToken: accessToken,
306 username: user.username,
307 password: user.password,
308 videoQuota: 2 * 1024 * 1024,
309 adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST
313 it('Should be able to login with this user', async function () {
314 accessTokenUser = await userLogin(server, user)
317 it('Should be able to get user information', async function () {
318 const res1 = await getMyUserInformation(server.url, accessTokenUser)
319 const userMe: MyUser = res1.body
321 const res2 = await getUserInformation(server.url, server.accessToken, userMe.id, true)
322 const userGet: User = res2.body
324 for (const user of [ userMe, userGet ]) {
325 expect(user.username).to.equal('user_1')
326 expect(user.email).to.equal('user_1@example.com')
327 expect(user.nsfwPolicy).to.equal('display')
328 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
329 expect(user.roleLabel).to.equal('User')
330 expect(user.id).to.be.a('number')
331 expect(user.account.displayName).to.equal('user_1')
332 expect(user.account.description).to.be.null
335 expect(userMe.adminFlags).to.be.undefined
336 expect(userGet.adminFlags).to.equal(UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST)
338 expect(userMe.specialPlaylists).to.have.lengthOf(1)
339 expect(userMe.specialPlaylists[0].type).to.equal(VideoPlaylistType.WATCH_LATER)
341 // Check stats are included with withStats
342 expect(userGet.videosCount).to.be.a('number')
343 expect(userGet.videosCount).to.equal(0)
344 expect(userGet.videoCommentsCount).to.be.a('number')
345 expect(userGet.videoCommentsCount).to.equal(0)
346 expect(userGet.abusesCount).to.be.a('number')
347 expect(userGet.abusesCount).to.equal(0)
348 expect(userGet.abusesAcceptedCount).to.be.a('number')
349 expect(userGet.abusesAcceptedCount).to.equal(0)
353 describe('My videos & quotas', function () {
355 it('Should be able to upload a video with this user', async function () {
358 const videoAttributes = {
359 name: 'super user video',
360 fixture: 'video_short.webm'
362 await uploadVideo(server.url, accessTokenUser, videoAttributes)
365 it('Should have video quota updated', async function () {
366 const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser)
367 const data = res.body
369 expect(data.videoQuotaUsed).to.equal(218910)
371 const resUsers = await getUsersList(server.url, server.accessToken)
373 const users: User[] = resUsers.body.data
374 const tmpUser = users.find(u => u.username === user.username)
375 expect(tmpUser.videoQuotaUsed).to.equal(218910)
378 it('Should be able to list my videos', async function () {
379 const res = await getMyVideos(server.url, accessTokenUser, 0, 5)
380 expect(res.body.total).to.equal(1)
382 const videos = res.body.data
383 expect(videos).to.have.lengthOf(1)
385 const video: Video = videos[0]
386 expect(video.name).to.equal('super user video')
387 expect(video.thumbnailPath).to.not.be.null
388 expect(video.previewPath).to.not.be.null
391 it('Should be able to search in my videos', async function () {
393 const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'user video')
394 expect(res.body.total).to.equal(1)
396 const videos = res.body.data
397 expect(videos).to.have.lengthOf(1)
401 const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'toto')
402 expect(res.body.total).to.equal(0)
404 const videos = res.body.data
405 expect(videos).to.have.lengthOf(0)
409 it('Should disable webtorrent, enable HLS, and update my quota', async function () {
413 const res = await getCustomConfig(server.url, server.accessToken)
414 const config = res.body as CustomConfig
415 config.transcoding.webtorrent.enabled = false
416 config.transcoding.hls.enabled = true
417 config.transcoding.enabled = true
418 await updateCustomSubConfig(server.url, server.accessToken, config)
422 const videoAttributes = {
423 name: 'super user video 2',
424 fixture: 'video_short.webm'
426 await uploadVideo(server.url, accessTokenUser, videoAttributes)
428 await waitJobs([ server ])
432 const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser)
433 const data = res.body
435 expect(data.videoQuotaUsed).to.be.greaterThan(220000)
440 describe('Users listing', function () {
442 it('Should list all the users', async function () {
443 const res = await getUsersList(server.url, server.accessToken)
444 const result = res.body
445 const total = result.total
446 const users = result.data
448 expect(total).to.equal(2)
449 expect(users).to.be.an('array')
450 expect(users.length).to.equal(2)
452 const user = users[0]
453 expect(user.username).to.equal('user_1')
454 expect(user.email).to.equal('user_1@example.com')
455 expect(user.nsfwPolicy).to.equal('display')
457 const rootUser = users[1]
458 expect(rootUser.username).to.equal('root')
459 expect(rootUser.email).to.equal('admin' + server.internalServerNumber + '@example.com')
460 expect(user.nsfwPolicy).to.equal('display')
462 expect(rootUser.lastLoginDate).to.exist
463 expect(user.lastLoginDate).to.exist
468 it('Should list only the first user by username asc', async function () {
469 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, 'username')
471 const result = res.body
472 const total = result.total
473 const users = result.data
475 expect(total).to.equal(2)
476 expect(users.length).to.equal(1)
478 const user = users[0]
479 expect(user.username).to.equal('root')
480 expect(user.email).to.equal('admin' + server.internalServerNumber + '@example.com')
481 expect(user.roleLabel).to.equal('Administrator')
482 expect(user.nsfwPolicy).to.equal('display')
485 it('Should list only the first user by username desc', async function () {
486 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-username')
487 const result = res.body
488 const total = result.total
489 const users = result.data
491 expect(total).to.equal(2)
492 expect(users.length).to.equal(1)
494 const user = users[0]
495 expect(user.username).to.equal('user_1')
496 expect(user.email).to.equal('user_1@example.com')
497 expect(user.nsfwPolicy).to.equal('display')
500 it('Should list only the second user by createdAt desc', async function () {
501 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-createdAt')
502 const result = res.body
503 const total = result.total
504 const users = result.data
506 expect(total).to.equal(2)
507 expect(users.length).to.equal(1)
509 const user = users[0]
510 expect(user.username).to.equal('user_1')
511 expect(user.email).to.equal('user_1@example.com')
512 expect(user.nsfwPolicy).to.equal('display')
515 it('Should list all the users by createdAt asc', async function () {
516 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt')
517 const result = res.body
518 const total = result.total
519 const users = result.data
521 expect(total).to.equal(2)
522 expect(users.length).to.equal(2)
524 expect(users[0].username).to.equal('root')
525 expect(users[0].email).to.equal('admin' + server.internalServerNumber + '@example.com')
526 expect(users[0].nsfwPolicy).to.equal('display')
528 expect(users[1].username).to.equal('user_1')
529 expect(users[1].email).to.equal('user_1@example.com')
530 expect(users[1].nsfwPolicy).to.equal('display')
533 it('Should search user by username', async function () {
534 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'oot')
535 const users = res.body.data as User[]
537 expect(res.body.total).to.equal(1)
538 expect(users.length).to.equal(1)
540 expect(users[0].username).to.equal('root')
543 it('Should search user by email', async function () {
545 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'r_1@exam')
546 const users = res.body.data as User[]
548 expect(res.body.total).to.equal(1)
549 expect(users.length).to.equal(1)
551 expect(users[0].username).to.equal('user_1')
552 expect(users[0].email).to.equal('user_1@example.com')
556 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'example')
557 const users = res.body.data as User[]
559 expect(res.body.total).to.equal(2)
560 expect(users.length).to.equal(2)
562 expect(users[0].username).to.equal('root')
563 expect(users[1].username).to.equal('user_1')
568 describe('Update my account', function () {
569 it('Should update my password', async function () {
572 accessToken: accessTokenUser,
573 currentPassword: 'super password',
574 password: 'new password'
576 user.password = 'new password'
578 await userLogin(server, user, HttpStatusCode.OK_200)
581 it('Should be able to change the NSFW display attribute', async function () {
584 accessToken: accessTokenUser,
585 nsfwPolicy: 'do_not_list'
588 const res = await getMyUserInformation(server.url, accessTokenUser)
589 const user = res.body
591 expect(user.username).to.equal('user_1')
592 expect(user.email).to.equal('user_1@example.com')
593 expect(user.nsfwPolicy).to.equal('do_not_list')
594 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
595 expect(user.id).to.be.a('number')
596 expect(user.account.displayName).to.equal('user_1')
597 expect(user.account.description).to.be.null
600 it('Should be able to change the autoPlayVideo attribute', async function () {
603 accessToken: accessTokenUser,
607 const res = await getMyUserInformation(server.url, accessTokenUser)
608 const user = res.body
610 expect(user.autoPlayVideo).to.be.false
613 it('Should be able to change the autoPlayNextVideo attribute', async function () {
616 accessToken: accessTokenUser,
617 autoPlayNextVideo: true
620 const res = await getMyUserInformation(server.url, accessTokenUser)
621 const user = res.body
623 expect(user.autoPlayNextVideo).to.be.true
626 it('Should be able to change the email attribute', async function () {
629 accessToken: accessTokenUser,
630 currentPassword: 'new password',
631 email: 'updated@example.com'
634 const res = await getMyUserInformation(server.url, accessTokenUser)
635 const user = res.body
637 expect(user.username).to.equal('user_1')
638 expect(user.email).to.equal('updated@example.com')
639 expect(user.nsfwPolicy).to.equal('do_not_list')
640 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
641 expect(user.id).to.be.a('number')
642 expect(user.account.displayName).to.equal('user_1')
643 expect(user.account.description).to.be.null
646 it('Should be able to update my avatar with a gif', async function () {
647 const fixture = 'avatar.gif'
649 await updateMyAvatar({
651 accessToken: accessTokenUser,
655 const res = await getMyUserInformation(server.url, accessTokenUser)
656 const user = res.body
658 await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif')
661 it('Should be able to update my avatar with a gif, and then a png', async function () {
662 for (const extension of [ '.png', '.gif' ]) {
663 const fixture = 'avatar' + extension
665 await updateMyAvatar({
667 accessToken: accessTokenUser,
671 const res = await getMyUserInformation(server.url, accessTokenUser)
672 const user = res.body
674 await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension)
678 it('Should be able to update my display name', async function () {
681 accessToken: accessTokenUser,
682 displayName: 'new display name'
685 const res = await getMyUserInformation(server.url, accessTokenUser)
686 const user = res.body
688 expect(user.username).to.equal('user_1')
689 expect(user.email).to.equal('updated@example.com')
690 expect(user.nsfwPolicy).to.equal('do_not_list')
691 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
692 expect(user.id).to.be.a('number')
693 expect(user.account.displayName).to.equal('new display name')
694 expect(user.account.description).to.be.null
697 it('Should be able to update my description', async function () {
700 accessToken: accessTokenUser,
701 description: 'my super description updated'
704 const res = await getMyUserInformation(server.url, accessTokenUser)
705 const user: User = res.body
707 expect(user.username).to.equal('user_1')
708 expect(user.email).to.equal('updated@example.com')
709 expect(user.nsfwPolicy).to.equal('do_not_list')
710 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
711 expect(user.id).to.be.a('number')
712 expect(user.account.displayName).to.equal('new display name')
713 expect(user.account.description).to.equal('my super description updated')
714 expect(user.noWelcomeModal).to.be.false
715 expect(user.noInstanceConfigWarningModal).to.be.false
718 it('Should be able to update my theme', async function () {
719 for (const theme of [ 'background-red', 'default', 'instance-default' ]) {
722 accessToken: accessTokenUser,
726 const res = await getMyUserInformation(server.url, accessTokenUser)
727 const body: User = res.body
729 expect(body.theme).to.equal(theme)
733 it('Should be able to update my modal preferences', async function () {
736 accessToken: accessTokenUser,
737 noInstanceConfigWarningModal: true,
741 const res = await getMyUserInformation(server.url, accessTokenUser)
742 const user: User = res.body
744 expect(user.noWelcomeModal).to.be.true
745 expect(user.noInstanceConfigWarningModal).to.be.true
749 describe('Updating another user', function () {
750 it('Should be able to update another user', async function () {
755 email: 'updated2@example.com',
758 role: UserRole.MODERATOR,
759 adminFlags: UserAdminFlag.NONE,
763 const res = await getUserInformation(server.url, accessToken, userId)
764 const user = res.body as User
766 expect(user.username).to.equal('user_1')
767 expect(user.email).to.equal('updated2@example.com')
768 expect(user.emailVerified).to.be.true
769 expect(user.nsfwPolicy).to.equal('do_not_list')
770 expect(user.videoQuota).to.equal(42)
771 expect(user.roleLabel).to.equal('Moderator')
772 expect(user.id).to.be.a('number')
773 expect(user.adminFlags).to.equal(UserAdminFlag.NONE)
774 expect(user.pluginAuth).to.equal('toto')
777 it('Should reset the auth plugin', async function () {
778 await updateUser({ url: server.url, userId, accessToken, pluginAuth: null })
780 const res = await getUserInformation(server.url, accessToken, userId)
781 const user = res.body as User
782 expect(user.pluginAuth).to.be.null
785 it('Should have removed the user token', async function () {
786 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401)
788 accessTokenUser = await userLogin(server, user)
791 it('Should be able to update another user password', async function () {
796 password: 'password updated'
799 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401)
801 await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400)
803 user.password = 'password updated'
804 accessTokenUser = await userLogin(server, user)
808 describe('Video blacklists', function () {
809 it('Should be able to list video blacklist by a moderator', async function () {
810 await getBlacklistedVideosList({ url: server.url, token: accessTokenUser })
814 describe('Remove a user', function () {
815 it('Should be able to remove this user', async function () {
816 await removeUser(server.url, userId, accessToken)
819 it('Should not be able to login with this user', async function () {
820 await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400)
823 it('Should not have videos of this user', async function () {
824 const res = await getVideosList(server.url)
826 expect(res.body.total).to.equal(1)
828 const video = res.body.data[0]
829 expect(video.account.name).to.equal('root')
833 describe('Registering a new user', function () {
834 let user15AccessToken
836 it('Should register a new user', async function () {
837 const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' }
838 const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' }
840 await registerUserWithChannel({ url: server.url, user, channel })
843 it('Should be able to login with this registered user', async function () {
846 password: 'my super password'
849 user15AccessToken = await userLogin(server, user15)
852 it('Should have the correct display name', async function () {
853 const res = await getMyUserInformation(server.url, user15AccessToken)
854 const user: User = res.body
856 expect(user.account.displayName).to.equal('super user 15')
859 it('Should have the correct video quota', async function () {
860 const res = await getMyUserInformation(server.url, user15AccessToken)
861 const user = res.body
863 expect(user.videoQuota).to.equal(5 * 1024 * 1024)
866 it('Should have created the channel', async function () {
867 const res = await getVideoChannel(server.url, 'my_user_15_channel')
869 expect(res.body.displayName).to.equal('my channel rocks')
872 it('Should remove me', async function () {
874 const res = await getUsersList(server.url, server.accessToken)
875 expect(res.body.data.find(u => u.username === 'user_15')).to.not.be.undefined
878 await deleteMe(server.url, user15AccessToken)
881 const res = await getUsersList(server.url, server.accessToken)
882 expect(res.body.data.find(u => u.username === 'user_15')).to.be.undefined
887 describe('User blocking', function () {
889 let user16AccessToken
892 password: 'my super password'
895 it('Should block a user', async function () {
896 const resUser = await createUser({
898 accessToken: server.accessToken,
899 username: user16.username,
900 password: user16.password
902 user16Id = resUser.body.user.id
904 user16AccessToken = await userLogin(server, user16)
906 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200)
907 await blockUser(server.url, user16Id, server.accessToken)
909 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.UNAUTHORIZED_401)
910 await userLogin(server, user16, HttpStatusCode.BAD_REQUEST_400)
913 it('Should search user by banned status', async function () {
915 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', undefined, true)
916 const users = res.body.data as User[]
918 expect(res.body.total).to.equal(1)
919 expect(users.length).to.equal(1)
921 expect(users[0].username).to.equal(user16.username)
925 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', undefined, false)
926 const users = res.body.data as User[]
928 expect(res.body.total).to.equal(1)
929 expect(users.length).to.equal(1)
931 expect(users[0].username).to.not.equal(user16.username)
935 it('Should unblock a user', async function () {
936 await unblockUser(server.url, user16Id, server.accessToken)
937 user16AccessToken = await userLogin(server, user16)
938 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200)
942 describe('User stats', function () {
944 let user17AccessToken
946 it('Should report correct initial statistics about a user', async function () {
949 password: 'my super password'
951 const resUser = await createUser({
953 accessToken: server.accessToken,
954 username: user17.username,
955 password: user17.password
958 user17Id = resUser.body.user.id
959 user17AccessToken = await userLogin(server, user17)
961 const res = await getUserInformation(server.url, server.accessToken, user17Id, true)
962 const user: User = res.body
964 expect(user.videosCount).to.equal(0)
965 expect(user.videoCommentsCount).to.equal(0)
966 expect(user.abusesCount).to.equal(0)
967 expect(user.abusesCreatedCount).to.equal(0)
968 expect(user.abusesAcceptedCount).to.equal(0)
971 it('Should report correct videos count', async function () {
972 const videoAttributes = {
973 name: 'video to test user stats'
975 await uploadVideo(server.url, user17AccessToken, videoAttributes)
976 const res1 = await getVideosList(server.url)
977 videoId = res1.body.data.find(video => video.name === videoAttributes.name).id
979 const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true)
980 const user: User = res2.body
982 expect(user.videosCount).to.equal(1)
985 it('Should report correct video comments for user', async function () {
986 const text = 'super comment'
987 await addVideoCommentThread(server.url, user17AccessToken, videoId, text)
989 const res = await getUserInformation(server.url, server.accessToken, user17Id, true)
990 const user: User = res.body
992 expect(user.videoCommentsCount).to.equal(1)
995 it('Should report correct abuses counts', async function () {
996 const reason = 'my super bad reason'
997 await reportAbuse({ url: server.url, token: user17AccessToken, videoId, reason })
999 const res1 = await getAdminAbusesList({ url: server.url, token: server.accessToken })
1000 const abuseId = res1.body.data[0].id
1002 const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true)
1003 const user2: User = res2.body
1005 expect(user2.abusesCount).to.equal(1) // number of incriminations
1006 expect(user2.abusesCreatedCount).to.equal(1) // number of reports created
1008 const body: AbuseUpdate = { state: AbuseState.ACCEPTED }
1009 await updateAbuse(server.url, server.accessToken, abuseId, body)
1011 const res3 = await getUserInformation(server.url, server.accessToken, user17Id, true)
1012 const user3: User = res3.body
1014 expect(user3.abusesAcceptedCount).to.equal(1) // number of reports created accepted
1018 after(async function () {
1019 await closeAllSequelize([ server ])
1020 await cleanupTests([ server ])