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,
28 registerUserWithChannel,
33 setAccessTokensToServers,
43 } from '@shared/extra-utils'
44 import { AbuseState, MyUser, OAuth2ErrorCode, User, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models'
46 const expect = chai.expect
48 describe('Test users', function () {
49 let server: ServerInfo
50 let accessToken: string
51 let accessTokenUser: string
56 password: 'super password'
59 before(async function () {
62 server = await flushAndRunServer(1, {
70 await setAccessTokensToServers([ server ])
72 await server.pluginsCommand.install({ npmName: 'peertube-theme-background-red' })
75 describe('OAuth client', function () {
76 it('Should create a new client')
78 it('Should return the first client')
80 it('Should remove the last client')
82 it('Should not login with an invalid client id', async function () {
83 const client = { id: 'client', secret: server.client.secret }
84 const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400)
86 expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT)
87 expect(res.body.error).to.contain('client is invalid')
88 expect(res.body.type.startsWith('https://')).to.be.true
89 expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT)
92 it('Should not login with an invalid client secret', async function () {
93 const client = { id: server.client.id, secret: 'coucou' }
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)
103 describe('Login', function () {
105 it('Should not login with an invalid username', async function () {
106 const user = { username: 'captain crochet', password: server.user.password }
107 const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400)
109 expect(res.body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT)
110 expect(res.body.error).to.contain('credentials are invalid')
111 expect(res.body.type.startsWith('https://')).to.be.true
112 expect(res.body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT)
115 it('Should not login with an invalid password', async function () {
116 const user = { username: server.user.username, password: 'mew_three' }
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 be able to upload a video', async function () {
126 accessToken = 'my_super_token'
128 const videoAttributes = {}
129 await uploadVideo(server.url, accessToken, videoAttributes, HttpStatusCode.UNAUTHORIZED_401)
132 it('Should not be able to follow', async function () {
133 accessToken = 'my_super_token'
135 await server.followsCommand.follow({
136 targets: [ 'http://example.com' ],
138 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
142 it('Should not be able to unfollow')
144 it('Should be able to login', async function () {
145 const res = await login(server.url, server.client, server.user, HttpStatusCode.OK_200)
147 accessToken = res.body.access_token
150 it('Should be able to login with an insensitive username', async function () {
151 const user = { username: 'RoOt', password: server.user.password }
152 await login(server.url, server.client, user, HttpStatusCode.OK_200)
154 const user2 = { username: 'rOoT', password: server.user.password }
155 await login(server.url, server.client, user2, HttpStatusCode.OK_200)
157 const user3 = { username: 'ROOt', password: server.user.password }
158 await login(server.url, server.client, user3, HttpStatusCode.OK_200)
162 describe('Upload', function () {
164 it('Should upload the video with the correct token', async function () {
165 const videoAttributes = {}
166 await uploadVideo(server.url, accessToken, videoAttributes)
167 const res = await getVideosList(server.url)
168 const video = res.body.data[0]
170 expect(video.account.name).to.equal('root')
174 it('Should upload the video again with the correct token', async function () {
175 const videoAttributes = {}
176 await uploadVideo(server.url, accessToken, videoAttributes)
180 describe('Ratings', function () {
182 it('Should retrieve a video rating', async function () {
183 await rateVideo(server.url, accessToken, videoId, 'like')
184 const res = await getMyUserVideoRating(server.url, accessToken, videoId)
185 const rating = res.body
187 expect(rating.videoId).to.equal(videoId)
188 expect(rating.rating).to.equal('like')
191 it('Should retrieve ratings list', async function () {
192 await rateVideo(server.url, accessToken, videoId, 'like')
194 const body = await server.accountsCommand.listRatings({ accountName: server.user.username })
196 expect(body.total).to.equal(1)
197 expect(body.data[0].video.id).to.equal(videoId)
198 expect(body.data[0].rating).to.equal('like')
201 it('Should retrieve ratings list by rating type', async function () {
203 const body = await server.accountsCommand.listRatings({ accountName: server.user.username, rating: 'like' })
204 expect(body.data.length).to.equal(1)
208 const body = await server.accountsCommand.listRatings({ accountName: server.user.username, rating: 'dislike' })
209 expect(body.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 config = await server.configCommand.getCustomConfig()
414 config.transcoding.webtorrent.enabled = false
415 config.transcoding.hls.enabled = true
416 config.transcoding.enabled = true
417 await server.configCommand.updateCustomSubConfig({ newConfig: config })
421 const videoAttributes = {
422 name: 'super user video 2',
423 fixture: 'video_short.webm'
425 await uploadVideo(server.url, accessTokenUser, videoAttributes)
427 await waitJobs([ server ])
431 const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser)
432 const data = res.body
434 expect(data.videoQuotaUsed).to.be.greaterThan(220000)
439 describe('Users listing', function () {
441 it('Should list all the users', async function () {
442 const res = await getUsersList(server.url, server.accessToken)
443 const result = res.body
444 const total = result.total
445 const users = result.data
447 expect(total).to.equal(2)
448 expect(users).to.be.an('array')
449 expect(users.length).to.equal(2)
451 const user = users[0]
452 expect(user.username).to.equal('user_1')
453 expect(user.email).to.equal('user_1@example.com')
454 expect(user.nsfwPolicy).to.equal('display')
456 const rootUser = users[1]
457 expect(rootUser.username).to.equal('root')
458 expect(rootUser.email).to.equal('admin' + server.internalServerNumber + '@example.com')
459 expect(user.nsfwPolicy).to.equal('display')
461 expect(rootUser.lastLoginDate).to.exist
462 expect(user.lastLoginDate).to.exist
467 it('Should list only the first user by username asc', async function () {
468 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, 'username')
470 const result = res.body
471 const total = result.total
472 const users = result.data
474 expect(total).to.equal(2)
475 expect(users.length).to.equal(1)
477 const user = users[0]
478 expect(user.username).to.equal('root')
479 expect(user.email).to.equal('admin' + server.internalServerNumber + '@example.com')
480 expect(user.roleLabel).to.equal('Administrator')
481 expect(user.nsfwPolicy).to.equal('display')
484 it('Should list only the first user by username desc', async function () {
485 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-username')
486 const result = res.body
487 const total = result.total
488 const users = result.data
490 expect(total).to.equal(2)
491 expect(users.length).to.equal(1)
493 const user = users[0]
494 expect(user.username).to.equal('user_1')
495 expect(user.email).to.equal('user_1@example.com')
496 expect(user.nsfwPolicy).to.equal('display')
499 it('Should list only the second user by createdAt desc', async function () {
500 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-createdAt')
501 const result = res.body
502 const total = result.total
503 const users = result.data
505 expect(total).to.equal(2)
506 expect(users.length).to.equal(1)
508 const user = users[0]
509 expect(user.username).to.equal('user_1')
510 expect(user.email).to.equal('user_1@example.com')
511 expect(user.nsfwPolicy).to.equal('display')
514 it('Should list all the users by createdAt asc', async function () {
515 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt')
516 const result = res.body
517 const total = result.total
518 const users = result.data
520 expect(total).to.equal(2)
521 expect(users.length).to.equal(2)
523 expect(users[0].username).to.equal('root')
524 expect(users[0].email).to.equal('admin' + server.internalServerNumber + '@example.com')
525 expect(users[0].nsfwPolicy).to.equal('display')
527 expect(users[1].username).to.equal('user_1')
528 expect(users[1].email).to.equal('user_1@example.com')
529 expect(users[1].nsfwPolicy).to.equal('display')
532 it('Should search user by username', async function () {
533 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'oot')
534 const users = res.body.data as User[]
536 expect(res.body.total).to.equal(1)
537 expect(users.length).to.equal(1)
539 expect(users[0].username).to.equal('root')
542 it('Should search user by email', async function () {
544 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'r_1@exam')
545 const users = res.body.data as User[]
547 expect(res.body.total).to.equal(1)
548 expect(users.length).to.equal(1)
550 expect(users[0].username).to.equal('user_1')
551 expect(users[0].email).to.equal('user_1@example.com')
555 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'example')
556 const users = res.body.data as User[]
558 expect(res.body.total).to.equal(2)
559 expect(users.length).to.equal(2)
561 expect(users[0].username).to.equal('root')
562 expect(users[1].username).to.equal('user_1')
567 describe('Update my account', function () {
568 it('Should update my password', async function () {
571 accessToken: accessTokenUser,
572 currentPassword: 'super password',
573 password: 'new password'
575 user.password = 'new password'
577 await userLogin(server, user, HttpStatusCode.OK_200)
580 it('Should be able to change the NSFW display attribute', async function () {
583 accessToken: accessTokenUser,
584 nsfwPolicy: 'do_not_list'
587 const res = await getMyUserInformation(server.url, accessTokenUser)
588 const user = res.body
590 expect(user.username).to.equal('user_1')
591 expect(user.email).to.equal('user_1@example.com')
592 expect(user.nsfwPolicy).to.equal('do_not_list')
593 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
594 expect(user.id).to.be.a('number')
595 expect(user.account.displayName).to.equal('user_1')
596 expect(user.account.description).to.be.null
599 it('Should be able to change the autoPlayVideo attribute', async function () {
602 accessToken: accessTokenUser,
606 const res = await getMyUserInformation(server.url, accessTokenUser)
607 const user = res.body
609 expect(user.autoPlayVideo).to.be.false
612 it('Should be able to change the autoPlayNextVideo attribute', async function () {
615 accessToken: accessTokenUser,
616 autoPlayNextVideo: true
619 const res = await getMyUserInformation(server.url, accessTokenUser)
620 const user = res.body
622 expect(user.autoPlayNextVideo).to.be.true
625 it('Should be able to change the email attribute', async function () {
628 accessToken: accessTokenUser,
629 currentPassword: 'new password',
630 email: 'updated@example.com'
633 const res = await getMyUserInformation(server.url, accessTokenUser)
634 const user = res.body
636 expect(user.username).to.equal('user_1')
637 expect(user.email).to.equal('updated@example.com')
638 expect(user.nsfwPolicy).to.equal('do_not_list')
639 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
640 expect(user.id).to.be.a('number')
641 expect(user.account.displayName).to.equal('user_1')
642 expect(user.account.description).to.be.null
645 it('Should be able to update my avatar with a gif', async function () {
646 const fixture = 'avatar.gif'
648 await updateMyAvatar({
650 accessToken: accessTokenUser,
654 const res = await getMyUserInformation(server.url, accessTokenUser)
655 const user = res.body
657 await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif')
660 it('Should be able to update my avatar with a gif, and then a png', async function () {
661 for (const extension of [ '.png', '.gif' ]) {
662 const fixture = 'avatar' + extension
664 await updateMyAvatar({
666 accessToken: accessTokenUser,
670 const res = await getMyUserInformation(server.url, accessTokenUser)
671 const user = res.body
673 await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension)
677 it('Should be able to update my display name', async function () {
680 accessToken: accessTokenUser,
681 displayName: 'new display name'
684 const res = await getMyUserInformation(server.url, accessTokenUser)
685 const user = res.body
687 expect(user.username).to.equal('user_1')
688 expect(user.email).to.equal('updated@example.com')
689 expect(user.nsfwPolicy).to.equal('do_not_list')
690 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
691 expect(user.id).to.be.a('number')
692 expect(user.account.displayName).to.equal('new display name')
693 expect(user.account.description).to.be.null
696 it('Should be able to update my description', async function () {
699 accessToken: accessTokenUser,
700 description: 'my super description updated'
703 const res = await getMyUserInformation(server.url, accessTokenUser)
704 const user: User = res.body
706 expect(user.username).to.equal('user_1')
707 expect(user.email).to.equal('updated@example.com')
708 expect(user.nsfwPolicy).to.equal('do_not_list')
709 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
710 expect(user.id).to.be.a('number')
711 expect(user.account.displayName).to.equal('new display name')
712 expect(user.account.description).to.equal('my super description updated')
713 expect(user.noWelcomeModal).to.be.false
714 expect(user.noInstanceConfigWarningModal).to.be.false
717 it('Should be able to update my theme', async function () {
718 for (const theme of [ 'background-red', 'default', 'instance-default' ]) {
721 accessToken: accessTokenUser,
725 const res = await getMyUserInformation(server.url, accessTokenUser)
726 const body: User = res.body
728 expect(body.theme).to.equal(theme)
732 it('Should be able to update my modal preferences', async function () {
735 accessToken: accessTokenUser,
736 noInstanceConfigWarningModal: true,
740 const res = await getMyUserInformation(server.url, accessTokenUser)
741 const user: User = res.body
743 expect(user.noWelcomeModal).to.be.true
744 expect(user.noInstanceConfigWarningModal).to.be.true
748 describe('Updating another user', function () {
749 it('Should be able to update another user', async function () {
754 email: 'updated2@example.com',
757 role: UserRole.MODERATOR,
758 adminFlags: UserAdminFlag.NONE,
762 const res = await getUserInformation(server.url, accessToken, userId)
763 const user = res.body as User
765 expect(user.username).to.equal('user_1')
766 expect(user.email).to.equal('updated2@example.com')
767 expect(user.emailVerified).to.be.true
768 expect(user.nsfwPolicy).to.equal('do_not_list')
769 expect(user.videoQuota).to.equal(42)
770 expect(user.roleLabel).to.equal('Moderator')
771 expect(user.id).to.be.a('number')
772 expect(user.adminFlags).to.equal(UserAdminFlag.NONE)
773 expect(user.pluginAuth).to.equal('toto')
776 it('Should reset the auth plugin', async function () {
777 await updateUser({ url: server.url, userId, accessToken, pluginAuth: null })
779 const res = await getUserInformation(server.url, accessToken, userId)
780 const user = res.body as User
781 expect(user.pluginAuth).to.be.null
784 it('Should have removed the user token', async function () {
785 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401)
787 accessTokenUser = await userLogin(server, user)
790 it('Should be able to update another user password', async function () {
795 password: 'password updated'
798 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401)
800 await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400)
802 user.password = 'password updated'
803 accessTokenUser = await userLogin(server, user)
807 describe('Video blacklists', function () {
808 it('Should be able to list video blacklist by a moderator', async function () {
809 await server.blacklistCommand.list({ token: accessTokenUser })
813 describe('Remove a user', function () {
814 it('Should be able to remove this user', async function () {
815 await removeUser(server.url, userId, accessToken)
818 it('Should not be able to login with this user', async function () {
819 await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400)
822 it('Should not have videos of this user', async function () {
823 const res = await getVideosList(server.url)
825 expect(res.body.total).to.equal(1)
827 const video = res.body.data[0]
828 expect(video.account.name).to.equal('root')
832 describe('Registering a new user', function () {
833 let user15AccessToken
835 it('Should register a new user', async function () {
836 const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' }
837 const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' }
839 await registerUserWithChannel({ url: server.url, user, channel })
842 it('Should be able to login with this registered user', async function () {
845 password: 'my super password'
848 user15AccessToken = await userLogin(server, user15)
851 it('Should have the correct display name', async function () {
852 const res = await getMyUserInformation(server.url, user15AccessToken)
853 const user: User = res.body
855 expect(user.account.displayName).to.equal('super user 15')
858 it('Should have the correct video quota', async function () {
859 const res = await getMyUserInformation(server.url, user15AccessToken)
860 const user = res.body
862 expect(user.videoQuota).to.equal(5 * 1024 * 1024)
865 it('Should have created the channel', async function () {
866 const { displayName } = await server.channelsCommand.get({ channelName: 'my_user_15_channel' })
868 expect(displayName).to.equal('my channel rocks')
871 it('Should remove me', async function () {
873 const res = await getUsersList(server.url, server.accessToken)
874 expect(res.body.data.find(u => u.username === 'user_15')).to.not.be.undefined
877 await deleteMe(server.url, user15AccessToken)
880 const res = await getUsersList(server.url, server.accessToken)
881 expect(res.body.data.find(u => u.username === 'user_15')).to.be.undefined
886 describe('User blocking', function () {
888 let user16AccessToken
891 password: 'my super password'
894 it('Should block a user', async function () {
895 const resUser = await createUser({
897 accessToken: server.accessToken,
898 username: user16.username,
899 password: user16.password
901 user16Id = resUser.body.user.id
903 user16AccessToken = await userLogin(server, user16)
905 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200)
906 await blockUser(server.url, user16Id, server.accessToken)
908 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.UNAUTHORIZED_401)
909 await userLogin(server, user16, HttpStatusCode.BAD_REQUEST_400)
912 it('Should search user by banned status', async function () {
914 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', undefined, true)
915 const users = res.body.data as User[]
917 expect(res.body.total).to.equal(1)
918 expect(users.length).to.equal(1)
920 expect(users[0].username).to.equal(user16.username)
924 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', undefined, false)
925 const users = res.body.data as User[]
927 expect(res.body.total).to.equal(1)
928 expect(users.length).to.equal(1)
930 expect(users[0].username).to.not.equal(user16.username)
934 it('Should unblock a user', async function () {
935 await unblockUser(server.url, user16Id, server.accessToken)
936 user16AccessToken = await userLogin(server, user16)
937 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200)
941 describe('User stats', function () {
943 let user17AccessToken
945 it('Should report correct initial statistics about a user', async function () {
948 password: 'my super password'
950 const resUser = await createUser({
952 accessToken: server.accessToken,
953 username: user17.username,
954 password: user17.password
957 user17Id = resUser.body.user.id
958 user17AccessToken = await userLogin(server, user17)
960 const res = await getUserInformation(server.url, server.accessToken, user17Id, true)
961 const user: User = res.body
963 expect(user.videosCount).to.equal(0)
964 expect(user.videoCommentsCount).to.equal(0)
965 expect(user.abusesCount).to.equal(0)
966 expect(user.abusesCreatedCount).to.equal(0)
967 expect(user.abusesAcceptedCount).to.equal(0)
970 it('Should report correct videos count', async function () {
971 const videoAttributes = {
972 name: 'video to test user stats'
974 await uploadVideo(server.url, user17AccessToken, videoAttributes)
975 const res1 = await getVideosList(server.url)
976 videoId = res1.body.data.find(video => video.name === videoAttributes.name).id
978 const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true)
979 const user: User = res2.body
981 expect(user.videosCount).to.equal(1)
984 it('Should report correct video comments for user', async function () {
985 const text = 'super comment'
986 await addVideoCommentThread(server.url, user17AccessToken, videoId, text)
988 const res = await getUserInformation(server.url, server.accessToken, user17Id, true)
989 const user: User = res.body
991 expect(user.videoCommentsCount).to.equal(1)
994 it('Should report correct abuses counts', async function () {
995 const reason = 'my super bad reason'
996 await server.abusesCommand.report({ token: user17AccessToken, videoId, reason })
998 const body1 = await server.abusesCommand.getAdminList()
999 const abuseId = body1.data[0].id
1001 const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true)
1002 const user2: User = res2.body
1004 expect(user2.abusesCount).to.equal(1) // number of incriminations
1005 expect(user2.abusesCreatedCount).to.equal(1) // number of reports created
1007 await server.abusesCommand.update({ abuseId, body: { state: AbuseState.ACCEPTED } })
1009 const res3 = await getUserInformation(server.url, server.accessToken, user17Id, true)
1010 const user3: User = res3.body
1012 expect(user3.abusesAcceptedCount).to.equal(1) // number of reports created accepted
1016 after(async function () {
1017 await closeAllSequelize([ server ])
1018 await cleanupTests([ server ])