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'
16 getBlacklistedVideosList,
19 getMyUserVideoQuotaUsed,
24 getUsersListPaginationAndSort,
34 registerUserWithChannel,
39 setAccessTokensToServers,
43 updateCustomSubConfig,
50 } from '@shared/extra-utils'
51 import { AbuseState, CustomConfig, MyUser, OAuth2ErrorCode, User, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models'
53 const expect = chai.expect
55 describe('Test users', function () {
56 let server: ServerInfo
57 let accessToken: string
58 let accessTokenUser: string
63 password: 'super password'
66 before(async function () {
69 server = await flushAndRunServer(1, {
77 await setAccessTokensToServers([ server ])
79 await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-theme-background-red' })
82 describe('OAuth client', function () {
83 it('Should create a new client')
85 it('Should return the first client')
87 it('Should remove the last client')
89 it('Should not login with an invalid client id', async function () {
90 const client = { id: 'client', secret: server.client.secret }
91 const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400)
93 expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT)
94 expect(res.body.error).to.contain('client is invalid')
95 expect(res.body.type.startsWith('https://')).to.be.true
96 expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT)
99 it('Should not login with an invalid client secret', async function () {
100 const client = { id: server.client.id, secret: 'coucou' }
101 const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400)
103 expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT)
104 expect(res.body.error).to.contain('client is invalid')
105 expect(res.body.type.startsWith('https://')).to.be.true
106 expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT)
110 describe('Login', function () {
112 it('Should not login with an invalid username', async function () {
113 const user = { username: 'captain crochet', password: server.user.password }
114 const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400)
116 expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT)
117 expect(res.body.error).to.contain('credentials are invalid')
118 expect(res.body.type.startsWith('https://')).to.be.true
119 expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT)
122 it('Should not login with an invalid password', async function () {
123 const user = { username: server.user.username, password: 'mew_three' }
124 const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400)
126 expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT)
127 expect(res.body.error).to.contain('credentials are invalid')
128 expect(res.body.type.startsWith('https://')).to.be.true
129 expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT)
132 it('Should not be able to upload a video', async function () {
133 accessToken = 'my_super_token'
135 const videoAttributes = {}
136 await uploadVideo(server.url, accessToken, videoAttributes, HttpStatusCode.UNAUTHORIZED_401)
139 it('Should not be able to follow', async function () {
140 accessToken = 'my_super_token'
141 await follow(server.url, [ 'http://example.com' ], accessToken, HttpStatusCode.UNAUTHORIZED_401)
144 it('Should not be able to unfollow')
146 it('Should be able to login', async function () {
147 const res = await login(server.url, server.client, server.user, HttpStatusCode.OK_200)
149 accessToken = res.body.access_token
152 it('Should be able to login with an insensitive username', async function () {
153 const user = { username: 'RoOt', password: server.user.password }
154 await login(server.url, server.client, user, HttpStatusCode.OK_200)
156 const user2 = { username: 'rOoT', password: server.user.password }
157 await login(server.url, server.client, user2, HttpStatusCode.OK_200)
159 const user3 = { username: 'ROOt', password: server.user.password }
160 await login(server.url, server.client, user3, HttpStatusCode.OK_200)
164 describe('Upload', function () {
166 it('Should upload the video with the correct token', async function () {
167 const videoAttributes = {}
168 await uploadVideo(server.url, accessToken, videoAttributes)
169 const res = await getVideosList(server.url)
170 const video = res.body.data[0]
172 expect(video.account.name).to.equal('root')
176 it('Should upload the video again with the correct token', async function () {
177 const videoAttributes = {}
178 await uploadVideo(server.url, accessToken, videoAttributes)
182 describe('Ratings', function () {
184 it('Should retrieve a video rating', async function () {
185 await rateVideo(server.url, accessToken, videoId, 'like')
186 const res = await getMyUserVideoRating(server.url, accessToken, videoId)
187 const rating = res.body
189 expect(rating.videoId).to.equal(videoId)
190 expect(rating.rating).to.equal('like')
193 it('Should retrieve ratings list', async function () {
194 await rateVideo(server.url, accessToken, videoId, 'like')
196 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, HttpStatusCode.OK_200)
197 const ratings = res.body
199 expect(ratings.total).to.equal(1)
200 expect(ratings.data[0].video.id).to.equal(videoId)
201 expect(ratings.data[0].rating).to.equal('like')
204 it('Should retrieve ratings list by rating type', async function () {
206 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'like')
207 const ratings = res.body
208 expect(ratings.data.length).to.equal(1)
212 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'dislike')
213 const ratings = res.body
214 expect(ratings.data.length).to.equal(0)
219 describe('Remove video', function () {
220 it('Should not be able to remove the video with an incorrect token', async function () {
221 await removeVideo(server.url, 'bad_token', videoId, HttpStatusCode.UNAUTHORIZED_401)
224 it('Should not be able to remove the video with the token of another account')
226 it('Should be able to remove the video with the correct token', async function () {
227 await removeVideo(server.url, accessToken, videoId)
231 describe('Logout', function () {
232 it('Should logout (revoke token)', async function () {
233 await logout(server.url, server.accessToken)
236 it('Should not be able to get the user information', async function () {
237 await getMyUserInformation(server.url, server.accessToken, HttpStatusCode.UNAUTHORIZED_401)
240 it('Should not be able to upload a video', async function () {
241 await uploadVideo(server.url, server.accessToken, { name: 'video' }, HttpStatusCode.UNAUTHORIZED_401)
244 it('Should not be able to rate a video', async function () {
245 const path = '/api/v1/videos/'
252 path: path + videoId,
253 token: 'wrong token',
255 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
257 await makePutBodyRequest(options)
260 it('Should be able to login again', async function () {
261 const res = await login(server.url, server.client, server.user)
262 server.accessToken = res.body.access_token
263 server.refreshToken = res.body.refresh_token
266 it('Should be able to get my user information again', async function () {
267 await getMyUserInformation(server.url, server.accessToken)
270 it('Should have an expired access token', async function () {
273 await setTokenField(server.internalServerNumber, server.accessToken, 'accessTokenExpiresAt', new Date().toISOString())
274 await setTokenField(server.internalServerNumber, server.accessToken, 'refreshTokenExpiresAt', new Date().toISOString())
276 killallServers([ server ])
277 await reRunServer(server)
279 await getMyUserInformation(server.url, server.accessToken, 401)
282 it('Should not be able to refresh an access token with an expired refresh token', async function () {
283 await refreshToken(server, server.refreshToken, 400)
286 it('Should refresh the token', async function () {
289 const futureDate = new Date(new Date().getTime() + 1000 * 60).toISOString()
290 await setTokenField(server.internalServerNumber, server.accessToken, 'refreshTokenExpiresAt', futureDate)
292 killallServers([ server ])
293 await reRunServer(server)
295 const res = await refreshToken(server, server.refreshToken)
296 server.accessToken = res.body.access_token
297 server.refreshToken = res.body.refresh_token
300 it('Should be able to get my user information again', async function () {
301 await getMyUserInformation(server.url, server.accessToken)
305 describe('Creating a user', function () {
307 it('Should be able to create a new user', async function () {
310 accessToken: accessToken,
311 username: user.username,
312 password: user.password,
313 videoQuota: 2 * 1024 * 1024,
314 adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST
318 it('Should be able to login with this user', async function () {
319 accessTokenUser = await userLogin(server, user)
322 it('Should be able to get user information', async function () {
323 const res1 = await getMyUserInformation(server.url, accessTokenUser)
324 const userMe: MyUser = res1.body
326 const res2 = await getUserInformation(server.url, server.accessToken, userMe.id, true)
327 const userGet: User = res2.body
329 for (const user of [ userMe, userGet ]) {
330 expect(user.username).to.equal('user_1')
331 expect(user.email).to.equal('user_1@example.com')
332 expect(user.nsfwPolicy).to.equal('display')
333 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
334 expect(user.roleLabel).to.equal('User')
335 expect(user.id).to.be.a('number')
336 expect(user.account.displayName).to.equal('user_1')
337 expect(user.account.description).to.be.null
340 expect(userMe.adminFlags).to.be.undefined
341 expect(userGet.adminFlags).to.equal(UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST)
343 expect(userMe.specialPlaylists).to.have.lengthOf(1)
344 expect(userMe.specialPlaylists[0].type).to.equal(VideoPlaylistType.WATCH_LATER)
346 // Check stats are included with withStats
347 expect(userGet.videosCount).to.be.a('number')
348 expect(userGet.videosCount).to.equal(0)
349 expect(userGet.videoCommentsCount).to.be.a('number')
350 expect(userGet.videoCommentsCount).to.equal(0)
351 expect(userGet.abusesCount).to.be.a('number')
352 expect(userGet.abusesCount).to.equal(0)
353 expect(userGet.abusesAcceptedCount).to.be.a('number')
354 expect(userGet.abusesAcceptedCount).to.equal(0)
358 describe('My videos & quotas', function () {
360 it('Should be able to upload a video with this user', async function () {
363 const videoAttributes = {
364 name: 'super user video',
365 fixture: 'video_short.webm'
367 await uploadVideo(server.url, accessTokenUser, videoAttributes)
370 it('Should have video quota updated', async function () {
371 const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser)
372 const data = res.body
374 expect(data.videoQuotaUsed).to.equal(218910)
376 const resUsers = await getUsersList(server.url, server.accessToken)
378 const users: User[] = resUsers.body.data
379 const tmpUser = users.find(u => u.username === user.username)
380 expect(tmpUser.videoQuotaUsed).to.equal(218910)
383 it('Should be able to list my videos', async function () {
384 const res = await getMyVideos(server.url, accessTokenUser, 0, 5)
385 expect(res.body.total).to.equal(1)
387 const videos = res.body.data
388 expect(videos).to.have.lengthOf(1)
390 const video: Video = videos[0]
391 expect(video.name).to.equal('super user video')
392 expect(video.thumbnailPath).to.not.be.null
393 expect(video.previewPath).to.not.be.null
396 it('Should be able to search in my videos', async function () {
398 const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'user video')
399 expect(res.body.total).to.equal(1)
401 const videos = res.body.data
402 expect(videos).to.have.lengthOf(1)
406 const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'toto')
407 expect(res.body.total).to.equal(0)
409 const videos = res.body.data
410 expect(videos).to.have.lengthOf(0)
414 it('Should disable webtorrent, enable HLS, and update my quota', async function () {
418 const res = await getCustomConfig(server.url, server.accessToken)
419 const config = res.body as CustomConfig
420 config.transcoding.webtorrent.enabled = false
421 config.transcoding.hls.enabled = true
422 config.transcoding.enabled = true
423 await updateCustomSubConfig(server.url, server.accessToken, config)
427 const videoAttributes = {
428 name: 'super user video 2',
429 fixture: 'video_short.webm'
431 await uploadVideo(server.url, accessTokenUser, videoAttributes)
433 await waitJobs([ server ])
437 const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser)
438 const data = res.body
440 expect(data.videoQuotaUsed).to.be.greaterThan(220000)
445 describe('Users listing', function () {
447 it('Should list all the users', async function () {
448 const res = await getUsersList(server.url, server.accessToken)
449 const result = res.body
450 const total = result.total
451 const users = result.data
453 expect(total).to.equal(2)
454 expect(users).to.be.an('array')
455 expect(users.length).to.equal(2)
457 const user = users[0]
458 expect(user.username).to.equal('user_1')
459 expect(user.email).to.equal('user_1@example.com')
460 expect(user.nsfwPolicy).to.equal('display')
462 const rootUser = users[1]
463 expect(rootUser.username).to.equal('root')
464 expect(rootUser.email).to.equal('admin' + server.internalServerNumber + '@example.com')
465 expect(user.nsfwPolicy).to.equal('display')
467 expect(rootUser.lastLoginDate).to.exist
468 expect(user.lastLoginDate).to.exist
473 it('Should list only the first user by username asc', async function () {
474 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, 'username')
476 const result = res.body
477 const total = result.total
478 const users = result.data
480 expect(total).to.equal(2)
481 expect(users.length).to.equal(1)
483 const user = users[0]
484 expect(user.username).to.equal('root')
485 expect(user.email).to.equal('admin' + server.internalServerNumber + '@example.com')
486 expect(user.roleLabel).to.equal('Administrator')
487 expect(user.nsfwPolicy).to.equal('display')
490 it('Should list only the first user by username desc', async function () {
491 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-username')
492 const result = res.body
493 const total = result.total
494 const users = result.data
496 expect(total).to.equal(2)
497 expect(users.length).to.equal(1)
499 const user = users[0]
500 expect(user.username).to.equal('user_1')
501 expect(user.email).to.equal('user_1@example.com')
502 expect(user.nsfwPolicy).to.equal('display')
505 it('Should list only the second user by createdAt desc', async function () {
506 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-createdAt')
507 const result = res.body
508 const total = result.total
509 const users = result.data
511 expect(total).to.equal(2)
512 expect(users.length).to.equal(1)
514 const user = users[0]
515 expect(user.username).to.equal('user_1')
516 expect(user.email).to.equal('user_1@example.com')
517 expect(user.nsfwPolicy).to.equal('display')
520 it('Should list all the users by createdAt asc', async function () {
521 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt')
522 const result = res.body
523 const total = result.total
524 const users = result.data
526 expect(total).to.equal(2)
527 expect(users.length).to.equal(2)
529 expect(users[0].username).to.equal('root')
530 expect(users[0].email).to.equal('admin' + server.internalServerNumber + '@example.com')
531 expect(users[0].nsfwPolicy).to.equal('display')
533 expect(users[1].username).to.equal('user_1')
534 expect(users[1].email).to.equal('user_1@example.com')
535 expect(users[1].nsfwPolicy).to.equal('display')
538 it('Should search user by username', async function () {
539 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'oot')
540 const users = res.body.data as User[]
542 expect(res.body.total).to.equal(1)
543 expect(users.length).to.equal(1)
545 expect(users[0].username).to.equal('root')
548 it('Should search user by email', async function () {
550 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'r_1@exam')
551 const users = res.body.data as User[]
553 expect(res.body.total).to.equal(1)
554 expect(users.length).to.equal(1)
556 expect(users[0].username).to.equal('user_1')
557 expect(users[0].email).to.equal('user_1@example.com')
561 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'example')
562 const users = res.body.data as User[]
564 expect(res.body.total).to.equal(2)
565 expect(users.length).to.equal(2)
567 expect(users[0].username).to.equal('root')
568 expect(users[1].username).to.equal('user_1')
573 describe('Update my account', function () {
574 it('Should update my password', async function () {
577 accessToken: accessTokenUser,
578 currentPassword: 'super password',
579 password: 'new password'
581 user.password = 'new password'
583 await userLogin(server, user, HttpStatusCode.OK_200)
586 it('Should be able to change the NSFW display attribute', async function () {
589 accessToken: accessTokenUser,
590 nsfwPolicy: 'do_not_list'
593 const res = await getMyUserInformation(server.url, accessTokenUser)
594 const user = res.body
596 expect(user.username).to.equal('user_1')
597 expect(user.email).to.equal('user_1@example.com')
598 expect(user.nsfwPolicy).to.equal('do_not_list')
599 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
600 expect(user.id).to.be.a('number')
601 expect(user.account.displayName).to.equal('user_1')
602 expect(user.account.description).to.be.null
605 it('Should be able to change the autoPlayVideo attribute', async function () {
608 accessToken: accessTokenUser,
612 const res = await getMyUserInformation(server.url, accessTokenUser)
613 const user = res.body
615 expect(user.autoPlayVideo).to.be.false
618 it('Should be able to change the autoPlayNextVideo attribute', async function () {
621 accessToken: accessTokenUser,
622 autoPlayNextVideo: true
625 const res = await getMyUserInformation(server.url, accessTokenUser)
626 const user = res.body
628 expect(user.autoPlayNextVideo).to.be.true
631 it('Should be able to change the email attribute', async function () {
634 accessToken: accessTokenUser,
635 currentPassword: 'new password',
636 email: 'updated@example.com'
639 const res = await getMyUserInformation(server.url, accessTokenUser)
640 const user = res.body
642 expect(user.username).to.equal('user_1')
643 expect(user.email).to.equal('updated@example.com')
644 expect(user.nsfwPolicy).to.equal('do_not_list')
645 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
646 expect(user.id).to.be.a('number')
647 expect(user.account.displayName).to.equal('user_1')
648 expect(user.account.description).to.be.null
651 it('Should be able to update my avatar with a gif', async function () {
652 const fixture = 'avatar.gif'
654 await updateMyAvatar({
656 accessToken: accessTokenUser,
660 const res = await getMyUserInformation(server.url, accessTokenUser)
661 const user = res.body
663 await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif')
666 it('Should be able to update my avatar with a gif, and then a png', async function () {
667 for (const extension of [ '.png', '.gif' ]) {
668 const fixture = 'avatar' + extension
670 await updateMyAvatar({
672 accessToken: accessTokenUser,
676 const res = await getMyUserInformation(server.url, accessTokenUser)
677 const user = res.body
679 await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension)
683 it('Should be able to update my display name', async function () {
686 accessToken: accessTokenUser,
687 displayName: 'new display name'
690 const res = await getMyUserInformation(server.url, accessTokenUser)
691 const user = res.body
693 expect(user.username).to.equal('user_1')
694 expect(user.email).to.equal('updated@example.com')
695 expect(user.nsfwPolicy).to.equal('do_not_list')
696 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
697 expect(user.id).to.be.a('number')
698 expect(user.account.displayName).to.equal('new display name')
699 expect(user.account.description).to.be.null
702 it('Should be able to update my description', async function () {
705 accessToken: accessTokenUser,
706 description: 'my super description updated'
709 const res = await getMyUserInformation(server.url, accessTokenUser)
710 const user: User = res.body
712 expect(user.username).to.equal('user_1')
713 expect(user.email).to.equal('updated@example.com')
714 expect(user.nsfwPolicy).to.equal('do_not_list')
715 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
716 expect(user.id).to.be.a('number')
717 expect(user.account.displayName).to.equal('new display name')
718 expect(user.account.description).to.equal('my super description updated')
719 expect(user.noWelcomeModal).to.be.false
720 expect(user.noInstanceConfigWarningModal).to.be.false
723 it('Should be able to update my theme', async function () {
724 for (const theme of [ 'background-red', 'default', 'instance-default' ]) {
727 accessToken: accessTokenUser,
731 const res = await getMyUserInformation(server.url, accessTokenUser)
732 const body: User = res.body
734 expect(body.theme).to.equal(theme)
738 it('Should be able to update my modal preferences', async function () {
741 accessToken: accessTokenUser,
742 noInstanceConfigWarningModal: true,
746 const res = await getMyUserInformation(server.url, accessTokenUser)
747 const user: User = res.body
749 expect(user.noWelcomeModal).to.be.true
750 expect(user.noInstanceConfigWarningModal).to.be.true
754 describe('Updating another user', function () {
755 it('Should be able to update another user', async function () {
760 email: 'updated2@example.com',
763 role: UserRole.MODERATOR,
764 adminFlags: UserAdminFlag.NONE,
768 const res = await getUserInformation(server.url, accessToken, userId)
769 const user = res.body as User
771 expect(user.username).to.equal('user_1')
772 expect(user.email).to.equal('updated2@example.com')
773 expect(user.emailVerified).to.be.true
774 expect(user.nsfwPolicy).to.equal('do_not_list')
775 expect(user.videoQuota).to.equal(42)
776 expect(user.roleLabel).to.equal('Moderator')
777 expect(user.id).to.be.a('number')
778 expect(user.adminFlags).to.equal(UserAdminFlag.NONE)
779 expect(user.pluginAuth).to.equal('toto')
782 it('Should reset the auth plugin', async function () {
783 await updateUser({ url: server.url, userId, accessToken, pluginAuth: null })
785 const res = await getUserInformation(server.url, accessToken, userId)
786 const user = res.body as User
787 expect(user.pluginAuth).to.be.null
790 it('Should have removed the user token', async function () {
791 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401)
793 accessTokenUser = await userLogin(server, user)
796 it('Should be able to update another user password', async function () {
801 password: 'password updated'
804 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401)
806 await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400)
808 user.password = 'password updated'
809 accessTokenUser = await userLogin(server, user)
813 describe('Video blacklists', function () {
814 it('Should be able to list video blacklist by a moderator', async function () {
815 await getBlacklistedVideosList({ url: server.url, token: accessTokenUser })
819 describe('Remove a user', function () {
820 it('Should be able to remove this user', async function () {
821 await removeUser(server.url, userId, accessToken)
824 it('Should not be able to login with this user', async function () {
825 await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400)
828 it('Should not have videos of this user', async function () {
829 const res = await getVideosList(server.url)
831 expect(res.body.total).to.equal(1)
833 const video = res.body.data[0]
834 expect(video.account.name).to.equal('root')
838 describe('Registering a new user', function () {
839 let user15AccessToken
841 it('Should register a new user', async function () {
842 const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' }
843 const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' }
845 await registerUserWithChannel({ url: server.url, user, channel })
848 it('Should be able to login with this registered user', async function () {
851 password: 'my super password'
854 user15AccessToken = await userLogin(server, user15)
857 it('Should have the correct display name', async function () {
858 const res = await getMyUserInformation(server.url, user15AccessToken)
859 const user: User = res.body
861 expect(user.account.displayName).to.equal('super user 15')
864 it('Should have the correct video quota', async function () {
865 const res = await getMyUserInformation(server.url, user15AccessToken)
866 const user = res.body
868 expect(user.videoQuota).to.equal(5 * 1024 * 1024)
871 it('Should have created the channel', async function () {
872 const res = await getVideoChannel(server.url, 'my_user_15_channel')
874 expect(res.body.displayName).to.equal('my channel rocks')
877 it('Should remove me', async function () {
879 const res = await getUsersList(server.url, server.accessToken)
880 expect(res.body.data.find(u => u.username === 'user_15')).to.not.be.undefined
883 await deleteMe(server.url, user15AccessToken)
886 const res = await getUsersList(server.url, server.accessToken)
887 expect(res.body.data.find(u => u.username === 'user_15')).to.be.undefined
892 describe('User blocking', function () {
894 let user16AccessToken
897 password: 'my super password'
900 it('Should block a user', async function () {
901 const resUser = await createUser({
903 accessToken: server.accessToken,
904 username: user16.username,
905 password: user16.password
907 user16Id = resUser.body.user.id
909 user16AccessToken = await userLogin(server, user16)
911 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200)
912 await blockUser(server.url, user16Id, server.accessToken)
914 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.UNAUTHORIZED_401)
915 await userLogin(server, user16, HttpStatusCode.BAD_REQUEST_400)
918 it('Should search user by banned status', async function () {
920 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', undefined, true)
921 const users = res.body.data as User[]
923 expect(res.body.total).to.equal(1)
924 expect(users.length).to.equal(1)
926 expect(users[0].username).to.equal(user16.username)
930 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', undefined, false)
931 const users = res.body.data as User[]
933 expect(res.body.total).to.equal(1)
934 expect(users.length).to.equal(1)
936 expect(users[0].username).to.not.equal(user16.username)
940 it('Should unblock a user', async function () {
941 await unblockUser(server.url, user16Id, server.accessToken)
942 user16AccessToken = await userLogin(server, user16)
943 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200)
947 describe('User stats', function () {
949 let user17AccessToken
951 it('Should report correct initial statistics about a user', async function () {
954 password: 'my super password'
956 const resUser = await createUser({
958 accessToken: server.accessToken,
959 username: user17.username,
960 password: user17.password
963 user17Id = resUser.body.user.id
964 user17AccessToken = await userLogin(server, user17)
966 const res = await getUserInformation(server.url, server.accessToken, user17Id, true)
967 const user: User = res.body
969 expect(user.videosCount).to.equal(0)
970 expect(user.videoCommentsCount).to.equal(0)
971 expect(user.abusesCount).to.equal(0)
972 expect(user.abusesCreatedCount).to.equal(0)
973 expect(user.abusesAcceptedCount).to.equal(0)
976 it('Should report correct videos count', async function () {
977 const videoAttributes = {
978 name: 'video to test user stats'
980 await uploadVideo(server.url, user17AccessToken, videoAttributes)
981 const res1 = await getVideosList(server.url)
982 videoId = res1.body.data.find(video => video.name === videoAttributes.name).id
984 const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true)
985 const user: User = res2.body
987 expect(user.videosCount).to.equal(1)
990 it('Should report correct video comments for user', async function () {
991 const text = 'super comment'
992 await addVideoCommentThread(server.url, user17AccessToken, videoId, text)
994 const res = await getUserInformation(server.url, server.accessToken, user17Id, true)
995 const user: User = res.body
997 expect(user.videoCommentsCount).to.equal(1)
1000 it('Should report correct abuses counts', async function () {
1001 const reason = 'my super bad reason'
1002 await server.abusesCommand.report({ token: user17AccessToken, videoId, reason })
1004 const body1 = await server.abusesCommand.getAdminList()
1005 const abuseId = body1.data[0].id
1007 const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true)
1008 const user2: User = res2.body
1010 expect(user2.abusesCount).to.equal(1) // number of incriminations
1011 expect(user2.abusesCreatedCount).to.equal(1) // number of reports created
1013 await server.abusesCommand.update({ abuseId, body: { state: AbuseState.ACCEPTED } })
1015 const res3 = await getUserInformation(server.url, server.accessToken, user17Id, true)
1016 const user3: User = res3.body
1018 expect(user3.abusesAcceptedCount).to.equal(1) // number of reports created accepted
1022 after(async function () {
1023 await closeAllSequelize([ server ])
1024 await cleanupTests([ server ])