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, OAuth2ErrorCode } 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(OAuth2ErrorCode.INVALID_CLIENT)
97 expect(res.body.error).to.contain('client is invalid')
98 expect(res.body.type.startsWith('https://')).to.be.true
99 expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT)
102 it('Should not login with an invalid client secret', async function () {
103 const client = { id: server.client.id, secret: 'coucou' }
104 const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400)
106 expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT)
107 expect(res.body.error).to.contain('client is invalid')
108 expect(res.body.type.startsWith('https://')).to.be.true
109 expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT)
113 describe('Login', function () {
115 it('Should not login with an invalid username', async function () {
116 const user = { username: 'captain crochet', password: server.user.password }
117 const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400)
119 expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT)
120 expect(res.body.error).to.contain('credentials are invalid')
121 expect(res.body.type.startsWith('https://')).to.be.true
122 expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT)
125 it('Should not login with an invalid password', async function () {
126 const user = { username: server.user.username, password: 'mew_three' }
127 const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400)
129 expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT)
130 expect(res.body.error).to.contain('credentials are invalid')
131 expect(res.body.type.startsWith('https://')).to.be.true
132 expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT)
135 it('Should not be able to upload a video', async function () {
136 accessToken = 'my_super_token'
138 const videoAttributes = {}
139 await uploadVideo(server.url, accessToken, videoAttributes, HttpStatusCode.UNAUTHORIZED_401)
142 it('Should not be able to follow', async function () {
143 accessToken = 'my_super_token'
144 await follow(server.url, [ 'http://example.com' ], accessToken, HttpStatusCode.UNAUTHORIZED_401)
147 it('Should not be able to unfollow')
149 it('Should be able to login', async function () {
150 const res = await login(server.url, server.client, server.user, HttpStatusCode.OK_200)
152 accessToken = res.body.access_token
155 it('Should be able to login with an insensitive username', async function () {
156 const user = { username: 'RoOt', password: server.user.password }
157 await login(server.url, server.client, user, HttpStatusCode.OK_200)
159 const user2 = { username: 'rOoT', password: server.user.password }
160 await login(server.url, server.client, user2, HttpStatusCode.OK_200)
162 const user3 = { username: 'ROOt', password: server.user.password }
163 await login(server.url, server.client, user3, HttpStatusCode.OK_200)
167 describe('Upload', function () {
169 it('Should upload the video with the correct token', async function () {
170 const videoAttributes = {}
171 await uploadVideo(server.url, accessToken, videoAttributes)
172 const res = await getVideosList(server.url)
173 const video = res.body.data[0]
175 expect(video.account.name).to.equal('root')
179 it('Should upload the video again with the correct token', async function () {
180 const videoAttributes = {}
181 await uploadVideo(server.url, accessToken, videoAttributes)
185 describe('Ratings', function () {
187 it('Should retrieve a video rating', async function () {
188 await rateVideo(server.url, accessToken, videoId, 'like')
189 const res = await getMyUserVideoRating(server.url, accessToken, videoId)
190 const rating = res.body
192 expect(rating.videoId).to.equal(videoId)
193 expect(rating.rating).to.equal('like')
196 it('Should retrieve ratings list', async function () {
197 await rateVideo(server.url, accessToken, videoId, 'like')
199 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, HttpStatusCode.OK_200)
200 const ratings = res.body
202 expect(ratings.total).to.equal(1)
203 expect(ratings.data[0].video.id).to.equal(videoId)
204 expect(ratings.data[0].rating).to.equal('like')
207 it('Should retrieve ratings list by rating type', async function () {
209 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'like')
210 const ratings = res.body
211 expect(ratings.data.length).to.equal(1)
215 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'dislike')
216 const ratings = res.body
217 expect(ratings.data.length).to.equal(0)
222 describe('Remove video', function () {
223 it('Should not be able to remove the video with an incorrect token', async function () {
224 await removeVideo(server.url, 'bad_token', videoId, HttpStatusCode.UNAUTHORIZED_401)
227 it('Should not be able to remove the video with the token of another account')
229 it('Should be able to remove the video with the correct token', async function () {
230 await removeVideo(server.url, accessToken, videoId)
234 describe('Logout', function () {
235 it('Should logout (revoke token)', async function () {
236 await logout(server.url, server.accessToken)
239 it('Should not be able to get the user information', async function () {
240 await getMyUserInformation(server.url, server.accessToken, HttpStatusCode.UNAUTHORIZED_401)
243 it('Should not be able to upload a video', async function () {
244 await uploadVideo(server.url, server.accessToken, { name: 'video' }, HttpStatusCode.UNAUTHORIZED_401)
247 it('Should not be able to rate a video', async function () {
248 const path = '/api/v1/videos/'
255 path: path + videoId,
256 token: 'wrong token',
258 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
260 await makePutBodyRequest(options)
263 it('Should be able to login again', async function () {
264 const res = await login(server.url, server.client, server.user)
265 server.accessToken = res.body.access_token
266 server.refreshToken = res.body.refresh_token
269 it('Should be able to get my user information again', async function () {
270 await getMyUserInformation(server.url, server.accessToken)
273 it('Should have an expired access token', async function () {
276 await setTokenField(server.internalServerNumber, server.accessToken, 'accessTokenExpiresAt', new Date().toISOString())
277 await setTokenField(server.internalServerNumber, server.accessToken, 'refreshTokenExpiresAt', new Date().toISOString())
279 killallServers([ server ])
280 await reRunServer(server)
282 await getMyUserInformation(server.url, server.accessToken, 401)
285 it('Should not be able to refresh an access token with an expired refresh token', async function () {
286 await refreshToken(server, server.refreshToken, 400)
289 it('Should refresh the token', async function () {
292 const futureDate = new Date(new Date().getTime() + 1000 * 60).toISOString()
293 await setTokenField(server.internalServerNumber, server.accessToken, 'refreshTokenExpiresAt', futureDate)
295 killallServers([ server ])
296 await reRunServer(server)
298 const res = await refreshToken(server, server.refreshToken)
299 server.accessToken = res.body.access_token
300 server.refreshToken = res.body.refresh_token
303 it('Should be able to get my user information again', async function () {
304 await getMyUserInformation(server.url, server.accessToken)
308 describe('Creating a user', function () {
310 it('Should be able to create a new user', async function () {
313 accessToken: accessToken,
314 username: user.username,
315 password: user.password,
316 videoQuota: 2 * 1024 * 1024,
317 adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST
321 it('Should be able to login with this user', async function () {
322 accessTokenUser = await userLogin(server, user)
325 it('Should be able to get user information', async function () {
326 const res1 = await getMyUserInformation(server.url, accessTokenUser)
327 const userMe: MyUser = res1.body
329 const res2 = await getUserInformation(server.url, server.accessToken, userMe.id, true)
330 const userGet: User = res2.body
332 for (const user of [ userMe, userGet ]) {
333 expect(user.username).to.equal('user_1')
334 expect(user.email).to.equal('user_1@example.com')
335 expect(user.nsfwPolicy).to.equal('display')
336 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
337 expect(user.roleLabel).to.equal('User')
338 expect(user.id).to.be.a('number')
339 expect(user.account.displayName).to.equal('user_1')
340 expect(user.account.description).to.be.null
343 expect(userMe.adminFlags).to.be.undefined
344 expect(userGet.adminFlags).to.equal(UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST)
346 expect(userMe.specialPlaylists).to.have.lengthOf(1)
347 expect(userMe.specialPlaylists[0].type).to.equal(VideoPlaylistType.WATCH_LATER)
349 // Check stats are included with withStats
350 expect(userGet.videosCount).to.be.a('number')
351 expect(userGet.videosCount).to.equal(0)
352 expect(userGet.videoCommentsCount).to.be.a('number')
353 expect(userGet.videoCommentsCount).to.equal(0)
354 expect(userGet.abusesCount).to.be.a('number')
355 expect(userGet.abusesCount).to.equal(0)
356 expect(userGet.abusesAcceptedCount).to.be.a('number')
357 expect(userGet.abusesAcceptedCount).to.equal(0)
361 describe('My videos & quotas', function () {
363 it('Should be able to upload a video with this user', async function () {
366 const videoAttributes = {
367 name: 'super user video',
368 fixture: 'video_short.webm'
370 await uploadVideo(server.url, accessTokenUser, videoAttributes)
373 it('Should have video quota updated', async function () {
374 const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser)
375 const data = res.body
377 expect(data.videoQuotaUsed).to.equal(218910)
379 const resUsers = await getUsersList(server.url, server.accessToken)
381 const users: User[] = resUsers.body.data
382 const tmpUser = users.find(u => u.username === user.username)
383 expect(tmpUser.videoQuotaUsed).to.equal(218910)
386 it('Should be able to list my videos', async function () {
387 const res = await getMyVideos(server.url, accessTokenUser, 0, 5)
388 expect(res.body.total).to.equal(1)
390 const videos = res.body.data
391 expect(videos).to.have.lengthOf(1)
393 const video: Video = videos[0]
394 expect(video.name).to.equal('super user video')
395 expect(video.thumbnailPath).to.not.be.null
396 expect(video.previewPath).to.not.be.null
399 it('Should be able to search in my videos', async function () {
401 const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'user video')
402 expect(res.body.total).to.equal(1)
404 const videos = res.body.data
405 expect(videos).to.have.lengthOf(1)
409 const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'toto')
410 expect(res.body.total).to.equal(0)
412 const videos = res.body.data
413 expect(videos).to.have.lengthOf(0)
417 it('Should disable webtorrent, enable HLS, and update my quota', async function () {
421 const res = await getCustomConfig(server.url, server.accessToken)
422 const config = res.body as CustomConfig
423 config.transcoding.webtorrent.enabled = false
424 config.transcoding.hls.enabled = true
425 config.transcoding.enabled = true
426 await updateCustomSubConfig(server.url, server.accessToken, config)
430 const videoAttributes = {
431 name: 'super user video 2',
432 fixture: 'video_short.webm'
434 await uploadVideo(server.url, accessTokenUser, videoAttributes)
436 await waitJobs([ server ])
440 const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser)
441 const data = res.body
443 expect(data.videoQuotaUsed).to.be.greaterThan(220000)
448 describe('Users listing', function () {
450 it('Should list all the users', async function () {
451 const res = await getUsersList(server.url, server.accessToken)
452 const result = res.body
453 const total = result.total
454 const users = result.data
456 expect(total).to.equal(2)
457 expect(users).to.be.an('array')
458 expect(users.length).to.equal(2)
460 const user = users[0]
461 expect(user.username).to.equal('user_1')
462 expect(user.email).to.equal('user_1@example.com')
463 expect(user.nsfwPolicy).to.equal('display')
465 const rootUser = users[1]
466 expect(rootUser.username).to.equal('root')
467 expect(rootUser.email).to.equal('admin' + server.internalServerNumber + '@example.com')
468 expect(user.nsfwPolicy).to.equal('display')
470 expect(rootUser.lastLoginDate).to.exist
471 expect(user.lastLoginDate).to.exist
476 it('Should list only the first user by username asc', async function () {
477 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, 'username')
479 const result = res.body
480 const total = result.total
481 const users = result.data
483 expect(total).to.equal(2)
484 expect(users.length).to.equal(1)
486 const user = users[0]
487 expect(user.username).to.equal('root')
488 expect(user.email).to.equal('admin' + server.internalServerNumber + '@example.com')
489 expect(user.roleLabel).to.equal('Administrator')
490 expect(user.nsfwPolicy).to.equal('display')
493 it('Should list only the first user by username desc', async function () {
494 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-username')
495 const result = res.body
496 const total = result.total
497 const users = result.data
499 expect(total).to.equal(2)
500 expect(users.length).to.equal(1)
502 const user = users[0]
503 expect(user.username).to.equal('user_1')
504 expect(user.email).to.equal('user_1@example.com')
505 expect(user.nsfwPolicy).to.equal('display')
508 it('Should list only the second user by createdAt desc', async function () {
509 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-createdAt')
510 const result = res.body
511 const total = result.total
512 const users = result.data
514 expect(total).to.equal(2)
515 expect(users.length).to.equal(1)
517 const user = users[0]
518 expect(user.username).to.equal('user_1')
519 expect(user.email).to.equal('user_1@example.com')
520 expect(user.nsfwPolicy).to.equal('display')
523 it('Should list all the users by createdAt asc', async function () {
524 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt')
525 const result = res.body
526 const total = result.total
527 const users = result.data
529 expect(total).to.equal(2)
530 expect(users.length).to.equal(2)
532 expect(users[0].username).to.equal('root')
533 expect(users[0].email).to.equal('admin' + server.internalServerNumber + '@example.com')
534 expect(users[0].nsfwPolicy).to.equal('display')
536 expect(users[1].username).to.equal('user_1')
537 expect(users[1].email).to.equal('user_1@example.com')
538 expect(users[1].nsfwPolicy).to.equal('display')
541 it('Should search user by username', async function () {
542 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'oot')
543 const users = res.body.data as User[]
545 expect(res.body.total).to.equal(1)
546 expect(users.length).to.equal(1)
548 expect(users[0].username).to.equal('root')
551 it('Should search user by email', async function () {
553 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'r_1@exam')
554 const users = res.body.data as User[]
556 expect(res.body.total).to.equal(1)
557 expect(users.length).to.equal(1)
559 expect(users[0].username).to.equal('user_1')
560 expect(users[0].email).to.equal('user_1@example.com')
564 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'example')
565 const users = res.body.data as User[]
567 expect(res.body.total).to.equal(2)
568 expect(users.length).to.equal(2)
570 expect(users[0].username).to.equal('root')
571 expect(users[1].username).to.equal('user_1')
576 describe('Update my account', function () {
577 it('Should update my password', async function () {
580 accessToken: accessTokenUser,
581 currentPassword: 'super password',
582 password: 'new password'
584 user.password = 'new password'
586 await userLogin(server, user, HttpStatusCode.OK_200)
589 it('Should be able to change the NSFW display attribute', async function () {
592 accessToken: accessTokenUser,
593 nsfwPolicy: 'do_not_list'
596 const res = await getMyUserInformation(server.url, accessTokenUser)
597 const user = res.body
599 expect(user.username).to.equal('user_1')
600 expect(user.email).to.equal('user_1@example.com')
601 expect(user.nsfwPolicy).to.equal('do_not_list')
602 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
603 expect(user.id).to.be.a('number')
604 expect(user.account.displayName).to.equal('user_1')
605 expect(user.account.description).to.be.null
608 it('Should be able to change the autoPlayVideo attribute', async function () {
611 accessToken: accessTokenUser,
615 const res = await getMyUserInformation(server.url, accessTokenUser)
616 const user = res.body
618 expect(user.autoPlayVideo).to.be.false
621 it('Should be able to change the autoPlayNextVideo attribute', async function () {
624 accessToken: accessTokenUser,
625 autoPlayNextVideo: true
628 const res = await getMyUserInformation(server.url, accessTokenUser)
629 const user = res.body
631 expect(user.autoPlayNextVideo).to.be.true
634 it('Should be able to change the email attribute', async function () {
637 accessToken: accessTokenUser,
638 currentPassword: 'new password',
639 email: 'updated@example.com'
642 const res = await getMyUserInformation(server.url, accessTokenUser)
643 const user = res.body
645 expect(user.username).to.equal('user_1')
646 expect(user.email).to.equal('updated@example.com')
647 expect(user.nsfwPolicy).to.equal('do_not_list')
648 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
649 expect(user.id).to.be.a('number')
650 expect(user.account.displayName).to.equal('user_1')
651 expect(user.account.description).to.be.null
654 it('Should be able to update my avatar with a gif', async function () {
655 const fixture = 'avatar.gif'
657 await updateMyAvatar({
659 accessToken: accessTokenUser,
663 const res = await getMyUserInformation(server.url, accessTokenUser)
664 const user = res.body
666 await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif')
669 it('Should be able to update my avatar with a gif, and then a png', async function () {
670 for (const extension of [ '.png', '.gif' ]) {
671 const fixture = 'avatar' + extension
673 await updateMyAvatar({
675 accessToken: accessTokenUser,
679 const res = await getMyUserInformation(server.url, accessTokenUser)
680 const user = res.body
682 await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension)
686 it('Should be able to update my display name', async function () {
689 accessToken: accessTokenUser,
690 displayName: 'new display name'
693 const res = await getMyUserInformation(server.url, accessTokenUser)
694 const user = res.body
696 expect(user.username).to.equal('user_1')
697 expect(user.email).to.equal('updated@example.com')
698 expect(user.nsfwPolicy).to.equal('do_not_list')
699 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
700 expect(user.id).to.be.a('number')
701 expect(user.account.displayName).to.equal('new display name')
702 expect(user.account.description).to.be.null
705 it('Should be able to update my description', async function () {
708 accessToken: accessTokenUser,
709 description: 'my super description updated'
712 const res = await getMyUserInformation(server.url, accessTokenUser)
713 const user: User = res.body
715 expect(user.username).to.equal('user_1')
716 expect(user.email).to.equal('updated@example.com')
717 expect(user.nsfwPolicy).to.equal('do_not_list')
718 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
719 expect(user.id).to.be.a('number')
720 expect(user.account.displayName).to.equal('new display name')
721 expect(user.account.description).to.equal('my super description updated')
722 expect(user.noWelcomeModal).to.be.false
723 expect(user.noInstanceConfigWarningModal).to.be.false
726 it('Should be able to update my theme', async function () {
727 for (const theme of [ 'background-red', 'default', 'instance-default' ]) {
730 accessToken: accessTokenUser,
734 const res = await getMyUserInformation(server.url, accessTokenUser)
735 const body: User = res.body
737 expect(body.theme).to.equal(theme)
741 it('Should be able to update my modal preferences', async function () {
744 accessToken: accessTokenUser,
745 noInstanceConfigWarningModal: true,
749 const res = await getMyUserInformation(server.url, accessTokenUser)
750 const user: User = res.body
752 expect(user.noWelcomeModal).to.be.true
753 expect(user.noInstanceConfigWarningModal).to.be.true
757 describe('Updating another user', function () {
758 it('Should be able to update another user', async function () {
763 email: 'updated2@example.com',
766 role: UserRole.MODERATOR,
767 adminFlags: UserAdminFlag.NONE,
771 const res = await getUserInformation(server.url, accessToken, userId)
772 const user = res.body as User
774 expect(user.username).to.equal('user_1')
775 expect(user.email).to.equal('updated2@example.com')
776 expect(user.emailVerified).to.be.true
777 expect(user.nsfwPolicy).to.equal('do_not_list')
778 expect(user.videoQuota).to.equal(42)
779 expect(user.roleLabel).to.equal('Moderator')
780 expect(user.id).to.be.a('number')
781 expect(user.adminFlags).to.equal(UserAdminFlag.NONE)
782 expect(user.pluginAuth).to.equal('toto')
785 it('Should reset the auth plugin', async function () {
786 await updateUser({ url: server.url, userId, accessToken, pluginAuth: null })
788 const res = await getUserInformation(server.url, accessToken, userId)
789 const user = res.body as User
790 expect(user.pluginAuth).to.be.null
793 it('Should have removed the user token', async function () {
794 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401)
796 accessTokenUser = await userLogin(server, user)
799 it('Should be able to update another user password', async function () {
804 password: 'password updated'
807 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401)
809 await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400)
811 user.password = 'password updated'
812 accessTokenUser = await userLogin(server, user)
816 describe('Video blacklists', function () {
817 it('Should be able to list video blacklist by a moderator', async function () {
818 await getBlacklistedVideosList({ url: server.url, token: accessTokenUser })
822 describe('Remove a user', function () {
823 it('Should be able to remove this user', async function () {
824 await removeUser(server.url, userId, accessToken)
827 it('Should not be able to login with this user', async function () {
828 await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400)
831 it('Should not have videos of this user', async function () {
832 const res = await getVideosList(server.url)
834 expect(res.body.total).to.equal(1)
836 const video = res.body.data[0]
837 expect(video.account.name).to.equal('root')
841 describe('Registering a new user', function () {
842 let user15AccessToken
844 it('Should register a new user', async function () {
845 const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' }
846 const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' }
848 await registerUserWithChannel({ url: server.url, user, channel })
851 it('Should be able to login with this registered user', async function () {
854 password: 'my super password'
857 user15AccessToken = await userLogin(server, user15)
860 it('Should have the correct display name', async function () {
861 const res = await getMyUserInformation(server.url, user15AccessToken)
862 const user: User = res.body
864 expect(user.account.displayName).to.equal('super user 15')
867 it('Should have the correct video quota', async function () {
868 const res = await getMyUserInformation(server.url, user15AccessToken)
869 const user = res.body
871 expect(user.videoQuota).to.equal(5 * 1024 * 1024)
874 it('Should have created the channel', async function () {
875 const res = await getVideoChannel(server.url, 'my_user_15_channel')
877 expect(res.body.displayName).to.equal('my channel rocks')
880 it('Should remove me', async function () {
882 const res = await getUsersList(server.url, server.accessToken)
883 expect(res.body.data.find(u => u.username === 'user_15')).to.not.be.undefined
886 await deleteMe(server.url, user15AccessToken)
889 const res = await getUsersList(server.url, server.accessToken)
890 expect(res.body.data.find(u => u.username === 'user_15')).to.be.undefined
895 describe('User blocking', function () {
897 let user16AccessToken
900 password: 'my super password'
903 it('Should block a user', async function () {
904 const resUser = await createUser({
906 accessToken: server.accessToken,
907 username: user16.username,
908 password: user16.password
910 user16Id = resUser.body.user.id
912 user16AccessToken = await userLogin(server, user16)
914 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200)
915 await blockUser(server.url, user16Id, server.accessToken)
917 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.UNAUTHORIZED_401)
918 await userLogin(server, user16, HttpStatusCode.BAD_REQUEST_400)
921 it('Should search user by banned status', async function () {
923 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', undefined, true)
924 const users = res.body.data as User[]
926 expect(res.body.total).to.equal(1)
927 expect(users.length).to.equal(1)
929 expect(users[0].username).to.equal(user16.username)
933 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', undefined, false)
934 const users = res.body.data as User[]
936 expect(res.body.total).to.equal(1)
937 expect(users.length).to.equal(1)
939 expect(users[0].username).to.not.equal(user16.username)
943 it('Should unblock a user', async function () {
944 await unblockUser(server.url, user16Id, server.accessToken)
945 user16AccessToken = await userLogin(server, user16)
946 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200)
950 describe('User stats', function () {
952 let user17AccessToken
954 it('Should report correct initial statistics about a user', async function () {
957 password: 'my super password'
959 const resUser = await createUser({
961 accessToken: server.accessToken,
962 username: user17.username,
963 password: user17.password
966 user17Id = resUser.body.user.id
967 user17AccessToken = await userLogin(server, user17)
969 const res = await getUserInformation(server.url, server.accessToken, user17Id, true)
970 const user: User = res.body
972 expect(user.videosCount).to.equal(0)
973 expect(user.videoCommentsCount).to.equal(0)
974 expect(user.abusesCount).to.equal(0)
975 expect(user.abusesCreatedCount).to.equal(0)
976 expect(user.abusesAcceptedCount).to.equal(0)
979 it('Should report correct videos count', async function () {
980 const videoAttributes = {
981 name: 'video to test user stats'
983 await uploadVideo(server.url, user17AccessToken, videoAttributes)
984 const res1 = await getVideosList(server.url)
985 videoId = res1.body.data.find(video => video.name === videoAttributes.name).id
987 const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true)
988 const user: User = res2.body
990 expect(user.videosCount).to.equal(1)
993 it('Should report correct video comments for user', async function () {
994 const text = 'super comment'
995 await addVideoCommentThread(server.url, user17AccessToken, videoId, text)
997 const res = await getUserInformation(server.url, server.accessToken, user17Id, true)
998 const user: User = res.body
1000 expect(user.videoCommentsCount).to.equal(1)
1003 it('Should report correct abuses counts', async function () {
1004 const reason = 'my super bad reason'
1005 await reportAbuse({ url: server.url, token: user17AccessToken, videoId, reason })
1007 const res1 = await getAdminAbusesList({ url: server.url, token: server.accessToken })
1008 const abuseId = res1.body.data[0].id
1010 const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true)
1011 const user2: User = res2.body
1013 expect(user2.abusesCount).to.equal(1) // number of incriminations
1014 expect(user2.abusesCreatedCount).to.equal(1) // number of reports created
1016 const body: AbuseUpdate = { state: AbuseState.ACCEPTED }
1017 await updateAbuse(server.url, server.accessToken, abuseId, body)
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 ])