1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { HttpStatusCode } from '@shared/core-utils'
15 getMyUserVideoQuotaUsed,
20 getUsersListPaginationAndSort,
29 registerUserWithChannel,
34 setAccessTokensToServers,
44 } from '@shared/extra-utils'
45 import { AbuseState, MyUser, OAuth2ErrorCode, User, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models'
47 const expect = chai.expect
49 describe('Test users', function () {
50 let server: ServerInfo
51 let accessToken: string
52 let accessTokenUser: string
57 password: 'super password'
60 before(async function () {
63 server = await flushAndRunServer(1, {
71 await setAccessTokensToServers([ server ])
73 await server.pluginsCommand.install({ npmName: 'peertube-theme-background-red' })
76 describe('OAuth client', function () {
77 it('Should create a new client')
79 it('Should return the first client')
81 it('Should remove the last client')
83 it('Should not login with an invalid client id', async function () {
84 const client = { id: 'client', secret: server.client.secret }
85 const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400)
87 expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT)
88 expect(res.body.error).to.contain('client is invalid')
89 expect(res.body.type.startsWith('https://')).to.be.true
90 expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT)
93 it('Should not login with an invalid client secret', async function () {
94 const client = { id: server.client.id, secret: 'coucou' }
95 const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400)
97 expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT)
98 expect(res.body.error).to.contain('client is invalid')
99 expect(res.body.type.startsWith('https://')).to.be.true
100 expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT)
104 describe('Login', function () {
106 it('Should not login with an invalid username', async function () {
107 const user = { username: 'captain crochet', password: server.user.password }
108 const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400)
110 expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT)
111 expect(res.body.error).to.contain('credentials are invalid')
112 expect(res.body.type.startsWith('https://')).to.be.true
113 expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT)
116 it('Should not login with an invalid password', async function () {
117 const user = { username: server.user.username, password: 'mew_three' }
118 const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400)
120 expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT)
121 expect(res.body.error).to.contain('credentials are invalid')
122 expect(res.body.type.startsWith('https://')).to.be.true
123 expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT)
126 it('Should not be able to upload a video', async function () {
127 accessToken = 'my_super_token'
129 const videoAttributes = {}
130 await uploadVideo(server.url, accessToken, videoAttributes, HttpStatusCode.UNAUTHORIZED_401)
133 it('Should not be able to follow', async function () {
134 accessToken = 'my_super_token'
136 await server.followsCommand.follow({
137 targets: [ 'http://example.com' ],
139 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
143 it('Should not be able to unfollow')
145 it('Should be able to login', async function () {
146 const res = await login(server.url, server.client, server.user, HttpStatusCode.OK_200)
148 accessToken = res.body.access_token
151 it('Should be able to login with an insensitive username', async function () {
152 const user = { username: 'RoOt', password: server.user.password }
153 await login(server.url, server.client, user, HttpStatusCode.OK_200)
155 const user2 = { username: 'rOoT', password: server.user.password }
156 await login(server.url, server.client, user2, HttpStatusCode.OK_200)
158 const user3 = { username: 'ROOt', password: server.user.password }
159 await login(server.url, server.client, user3, HttpStatusCode.OK_200)
163 describe('Upload', function () {
165 it('Should upload the video with the correct token', async function () {
166 const videoAttributes = {}
167 await uploadVideo(server.url, accessToken, videoAttributes)
168 const res = await getVideosList(server.url)
169 const video = res.body.data[0]
171 expect(video.account.name).to.equal('root')
175 it('Should upload the video again with the correct token', async function () {
176 const videoAttributes = {}
177 await uploadVideo(server.url, accessToken, videoAttributes)
181 describe('Ratings', function () {
183 it('Should retrieve a video rating', async function () {
184 await rateVideo(server.url, accessToken, videoId, 'like')
185 const res = await getMyUserVideoRating(server.url, accessToken, videoId)
186 const rating = res.body
188 expect(rating.videoId).to.equal(videoId)
189 expect(rating.rating).to.equal('like')
192 it('Should retrieve ratings list', async function () {
193 await rateVideo(server.url, accessToken, videoId, 'like')
195 const body = await server.accountsCommand.listRatings({ accountName: server.user.username })
197 expect(body.total).to.equal(1)
198 expect(body.data[0].video.id).to.equal(videoId)
199 expect(body.data[0].rating).to.equal('like')
202 it('Should retrieve ratings list by rating type', async function () {
204 const body = await server.accountsCommand.listRatings({ accountName: server.user.username, rating: 'like' })
205 expect(body.data.length).to.equal(1)
209 const body = await server.accountsCommand.listRatings({ accountName: server.user.username, rating: 'dislike' })
210 expect(body.data.length).to.equal(0)
215 describe('Remove video', function () {
216 it('Should not be able to remove the video with an incorrect token', async function () {
217 await removeVideo(server.url, 'bad_token', videoId, HttpStatusCode.UNAUTHORIZED_401)
220 it('Should not be able to remove the video with the token of another account')
222 it('Should be able to remove the video with the correct token', async function () {
223 await removeVideo(server.url, accessToken, videoId)
227 describe('Logout', function () {
228 it('Should logout (revoke token)', async function () {
229 await logout(server.url, server.accessToken)
232 it('Should not be able to get the user information', async function () {
233 await getMyUserInformation(server.url, server.accessToken, HttpStatusCode.UNAUTHORIZED_401)
236 it('Should not be able to upload a video', async function () {
237 await uploadVideo(server.url, server.accessToken, { name: 'video' }, HttpStatusCode.UNAUTHORIZED_401)
240 it('Should not be able to rate a video', async function () {
241 const path = '/api/v1/videos/'
248 path: path + videoId,
249 token: 'wrong token',
251 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
253 await makePutBodyRequest(options)
256 it('Should be able to login again', async function () {
257 const res = await login(server.url, server.client, server.user)
258 server.accessToken = res.body.access_token
259 server.refreshToken = res.body.refresh_token
262 it('Should be able to get my user information again', async function () {
263 await getMyUserInformation(server.url, server.accessToken)
266 it('Should have an expired access token', async function () {
269 await setTokenField(server.internalServerNumber, server.accessToken, 'accessTokenExpiresAt', new Date().toISOString())
270 await setTokenField(server.internalServerNumber, server.accessToken, 'refreshTokenExpiresAt', new Date().toISOString())
272 killallServers([ server ])
273 await reRunServer(server)
275 await getMyUserInformation(server.url, server.accessToken, 401)
278 it('Should not be able to refresh an access token with an expired refresh token', async function () {
279 await refreshToken(server, server.refreshToken, 400)
282 it('Should refresh the token', async function () {
285 const futureDate = new Date(new Date().getTime() + 1000 * 60).toISOString()
286 await setTokenField(server.internalServerNumber, server.accessToken, 'refreshTokenExpiresAt', futureDate)
288 killallServers([ server ])
289 await reRunServer(server)
291 const res = await refreshToken(server, server.refreshToken)
292 server.accessToken = res.body.access_token
293 server.refreshToken = res.body.refresh_token
296 it('Should be able to get my user information again', async function () {
297 await getMyUserInformation(server.url, server.accessToken)
301 describe('Creating a user', function () {
303 it('Should be able to create a new user', async function () {
306 accessToken: accessToken,
307 username: user.username,
308 password: user.password,
309 videoQuota: 2 * 1024 * 1024,
310 adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST
314 it('Should be able to login with this user', async function () {
315 accessTokenUser = await userLogin(server, user)
318 it('Should be able to get user information', async function () {
319 const res1 = await getMyUserInformation(server.url, accessTokenUser)
320 const userMe: MyUser = res1.body
322 const res2 = await getUserInformation(server.url, server.accessToken, userMe.id, true)
323 const userGet: User = res2.body
325 for (const user of [ userMe, userGet ]) {
326 expect(user.username).to.equal('user_1')
327 expect(user.email).to.equal('user_1@example.com')
328 expect(user.nsfwPolicy).to.equal('display')
329 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
330 expect(user.roleLabel).to.equal('User')
331 expect(user.id).to.be.a('number')
332 expect(user.account.displayName).to.equal('user_1')
333 expect(user.account.description).to.be.null
336 expect(userMe.adminFlags).to.be.undefined
337 expect(userGet.adminFlags).to.equal(UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST)
339 expect(userMe.specialPlaylists).to.have.lengthOf(1)
340 expect(userMe.specialPlaylists[0].type).to.equal(VideoPlaylistType.WATCH_LATER)
342 // Check stats are included with withStats
343 expect(userGet.videosCount).to.be.a('number')
344 expect(userGet.videosCount).to.equal(0)
345 expect(userGet.videoCommentsCount).to.be.a('number')
346 expect(userGet.videoCommentsCount).to.equal(0)
347 expect(userGet.abusesCount).to.be.a('number')
348 expect(userGet.abusesCount).to.equal(0)
349 expect(userGet.abusesAcceptedCount).to.be.a('number')
350 expect(userGet.abusesAcceptedCount).to.equal(0)
354 describe('My videos & quotas', function () {
356 it('Should be able to upload a video with this user', async function () {
359 const videoAttributes = {
360 name: 'super user video',
361 fixture: 'video_short.webm'
363 await uploadVideo(server.url, accessTokenUser, videoAttributes)
366 it('Should have video quota updated', async function () {
367 const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser)
368 const data = res.body
370 expect(data.videoQuotaUsed).to.equal(218910)
372 const resUsers = await getUsersList(server.url, server.accessToken)
374 const users: User[] = resUsers.body.data
375 const tmpUser = users.find(u => u.username === user.username)
376 expect(tmpUser.videoQuotaUsed).to.equal(218910)
379 it('Should be able to list my videos', async function () {
380 const res = await getMyVideos(server.url, accessTokenUser, 0, 5)
381 expect(res.body.total).to.equal(1)
383 const videos = res.body.data
384 expect(videos).to.have.lengthOf(1)
386 const video: Video = videos[0]
387 expect(video.name).to.equal('super user video')
388 expect(video.thumbnailPath).to.not.be.null
389 expect(video.previewPath).to.not.be.null
392 it('Should be able to search in my videos', async function () {
394 const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'user video')
395 expect(res.body.total).to.equal(1)
397 const videos = res.body.data
398 expect(videos).to.have.lengthOf(1)
402 const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'toto')
403 expect(res.body.total).to.equal(0)
405 const videos = res.body.data
406 expect(videos).to.have.lengthOf(0)
410 it('Should disable webtorrent, enable HLS, and update my quota', async function () {
414 const config = await server.configCommand.getCustomConfig()
415 config.transcoding.webtorrent.enabled = false
416 config.transcoding.hls.enabled = true
417 config.transcoding.enabled = true
418 await server.configCommand.updateCustomSubConfig({ newConfig: 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 server.blacklistCommand.list({ 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 server.abusesCommand.report({ token: user17AccessToken, videoId, reason })
999 const body1 = await server.abusesCommand.getAdminList()
1000 const abuseId = body1.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 await server.abusesCommand.update({ abuseId, body: { state: AbuseState.ACCEPTED } })
1010 const res3 = await getUserInformation(server.url, server.accessToken, user17Id, true)
1011 const user3: User = res3.body
1013 expect(user3.abusesAcceptedCount).to.equal(1) // number of reports created accepted
1017 after(async function () {
1018 await closeAllSequelize([ server ])
1019 await cleanupTests([ server ])