1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { HttpStatusCode } from '@shared/models'
12 setAccessTokensToServers,
15 } from '@shared/extra-utils'
16 import { AbuseState, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models'
18 const expect = chai.expect
20 describe('Test users', function () {
21 let server: PeerTubeServer
28 password: 'super password'
31 before(async function () {
34 server = await createSingleServer(1, {
42 await setAccessTokensToServers([ server ])
44 await server.plugins.install({ npmName: 'peertube-theme-background-red' })
47 describe('OAuth client', function () {
48 it('Should create a new client')
50 it('Should return the first client')
52 it('Should remove the last client')
54 it('Should not login with an invalid client id', async function () {
55 const client = { id: 'client', secret: server.store.client.secret }
56 const body = await server.login.login({ client, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
58 expect(body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT)
59 expect(body.error).to.contain('client is invalid')
60 expect(body.type.startsWith('https://')).to.be.true
61 expect(body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT)
64 it('Should not login with an invalid client secret', async function () {
65 const client = { id: server.store.client.id, secret: 'coucou' }
66 const body = await server.login.login({ client, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
68 expect(body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT)
69 expect(body.error).to.contain('client is invalid')
70 expect(body.type.startsWith('https://')).to.be.true
71 expect(body.type).to.contain(OAuth2ErrorCode.INVALID_CLIENT)
75 describe('Login', function () {
77 it('Should not login with an invalid username', async function () {
78 const user = { username: 'captain crochet', password: server.store.user.password }
79 const body = await server.login.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
81 expect(body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT)
82 expect(body.error).to.contain('credentials are invalid')
83 expect(body.type.startsWith('https://')).to.be.true
84 expect(body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT)
87 it('Should not login with an invalid password', async function () {
88 const user = { username: server.store.user.username, password: 'mew_three' }
89 const body = await server.login.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
91 expect(body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT)
92 expect(body.error).to.contain('credentials are invalid')
93 expect(body.type.startsWith('https://')).to.be.true
94 expect(body.type).to.contain(OAuth2ErrorCode.INVALID_GRANT)
97 it('Should not be able to upload a video', async function () {
98 token = 'my_super_token'
100 await server.videos.upload({ token, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
103 it('Should not be able to follow', async function () {
104 token = 'my_super_token'
106 await server.follows.follow({
107 targets: [ 'http://example.com' ],
109 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
113 it('Should not be able to unfollow')
115 it('Should be able to login', async function () {
116 const body = await server.login.login({ expectedStatus: HttpStatusCode.OK_200 })
118 token = body.access_token
121 it('Should be able to login with an insensitive username', async function () {
122 const user = { username: 'RoOt', password: server.store.user.password }
123 await server.login.login({ user, expectedStatus: HttpStatusCode.OK_200 })
125 const user2 = { username: 'rOoT', password: server.store.user.password }
126 await server.login.login({ user: user2, expectedStatus: HttpStatusCode.OK_200 })
128 const user3 = { username: 'ROOt', password: server.store.user.password }
129 await server.login.login({ user: user3, expectedStatus: HttpStatusCode.OK_200 })
133 describe('Upload', function () {
135 it('Should upload the video with the correct token', async function () {
136 await server.videos.upload({ token })
137 const { data } = await server.videos.list()
138 const video = data[0]
140 expect(video.account.name).to.equal('root')
144 it('Should upload the video again with the correct token', async function () {
145 await server.videos.upload({ token })
149 describe('Ratings', function () {
151 it('Should retrieve a video rating', async function () {
152 await server.videos.rate({ id: videoId, rating: 'like' })
153 const rating = await server.users.getMyRating({ token, videoId })
155 expect(rating.videoId).to.equal(videoId)
156 expect(rating.rating).to.equal('like')
159 it('Should retrieve ratings list', async function () {
160 await server.videos.rate({ id: videoId, rating: 'like' })
162 const body = await server.accounts.listRatings({ accountName: server.store.user.username })
164 expect(body.total).to.equal(1)
165 expect(body.data[0].video.id).to.equal(videoId)
166 expect(body.data[0].rating).to.equal('like')
169 it('Should retrieve ratings list by rating type', async function () {
171 const body = await server.accounts.listRatings({ accountName: server.store.user.username, rating: 'like' })
172 expect(body.data.length).to.equal(1)
176 const body = await server.accounts.listRatings({ accountName: server.store.user.username, rating: 'dislike' })
177 expect(body.data.length).to.equal(0)
182 describe('Remove video', function () {
183 it('Should not be able to remove the video with an incorrect token', async function () {
184 await server.videos.remove({ token: 'bad_token', id: videoId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
187 it('Should not be able to remove the video with the token of another account')
189 it('Should be able to remove the video with the correct token', async function () {
190 await server.videos.remove({ token, id: videoId })
194 describe('Logout', function () {
195 it('Should logout (revoke token)', async function () {
196 await server.login.logout({ token: server.accessToken })
199 it('Should not be able to get the user information', async function () {
200 await server.users.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
203 it('Should not be able to upload a video', async function () {
204 await server.videos.upload({ attributes: { name: 'video' }, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
207 it('Should not be able to rate a video', async function () {
208 const path = '/api/v1/videos/'
215 path: path + videoId,
216 token: 'wrong token',
218 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
220 await makePutBodyRequest(options)
223 it('Should be able to login again', async function () {
224 const body = await server.login.login()
225 server.accessToken = body.access_token
226 server.refreshToken = body.refresh_token
229 it('Should be able to get my user information again', async function () {
230 await server.users.getMyInfo()
233 it('Should have an expired access token', async function () {
236 await server.sql.setTokenField(server.accessToken, 'accessTokenExpiresAt', new Date().toISOString())
237 await server.sql.setTokenField(server.accessToken, 'refreshTokenExpiresAt', new Date().toISOString())
239 await killallServers([ server ])
242 await server.users.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
245 it('Should not be able to refresh an access token with an expired refresh token', async function () {
246 await server.login.refreshToken({ refreshToken: server.refreshToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
249 it('Should refresh the token', async function () {
252 const futureDate = new Date(new Date().getTime() + 1000 * 60).toISOString()
253 await server.sql.setTokenField(server.accessToken, 'refreshTokenExpiresAt', futureDate)
255 await killallServers([ server ])
258 const res = await server.login.refreshToken({ refreshToken: server.refreshToken })
259 server.accessToken = res.body.access_token
260 server.refreshToken = res.body.refresh_token
263 it('Should be able to get my user information again', async function () {
264 await server.users.getMyInfo()
268 describe('Creating a user', function () {
270 it('Should be able to create a new user', async function () {
271 await server.users.create({ ...user, videoQuota: 2 * 1024 * 1024, adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST })
274 it('Should be able to login with this user', async function () {
275 userToken = await server.login.getAccessToken(user)
278 it('Should be able to get user information', async function () {
279 const userMe = await server.users.getMyInfo({ token: userToken })
281 const userGet = await server.users.get({ userId: userMe.id, withStats: true })
283 for (const user of [ userMe, userGet ]) {
284 expect(user.username).to.equal('user_1')
285 expect(user.email).to.equal('user_1@example.com')
286 expect(user.nsfwPolicy).to.equal('display')
287 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
288 expect(user.roleLabel).to.equal('User')
289 expect(user.id).to.be.a('number')
290 expect(user.account.displayName).to.equal('user_1')
291 expect(user.account.description).to.be.null
294 expect(userMe.adminFlags).to.be.undefined
295 expect(userGet.adminFlags).to.equal(UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST)
297 expect(userMe.specialPlaylists).to.have.lengthOf(1)
298 expect(userMe.specialPlaylists[0].type).to.equal(VideoPlaylistType.WATCH_LATER)
300 // Check stats are included with withStats
301 expect(userGet.videosCount).to.be.a('number')
302 expect(userGet.videosCount).to.equal(0)
303 expect(userGet.videoCommentsCount).to.be.a('number')
304 expect(userGet.videoCommentsCount).to.equal(0)
305 expect(userGet.abusesCount).to.be.a('number')
306 expect(userGet.abusesCount).to.equal(0)
307 expect(userGet.abusesAcceptedCount).to.be.a('number')
308 expect(userGet.abusesAcceptedCount).to.equal(0)
312 describe('My videos & quotas', function () {
314 it('Should be able to upload a video with this user', async function () {
318 name: 'super user video',
319 fixture: 'video_short.webm'
321 await server.videos.upload({ token: userToken, attributes })
324 it('Should have video quota updated', async function () {
325 const quota = await server.users.getMyQuotaUsed({ token: userToken })
326 expect(quota.videoQuotaUsed).to.equal(218910)
328 const { data } = await server.users.list()
329 const tmpUser = data.find(u => u.username === user.username)
330 expect(tmpUser.videoQuotaUsed).to.equal(218910)
333 it('Should be able to list my videos', async function () {
334 const { total, data } = await server.videos.listMyVideos({ token: userToken })
335 expect(total).to.equal(1)
336 expect(data).to.have.lengthOf(1)
338 const video: Video = data[0]
339 expect(video.name).to.equal('super user video')
340 expect(video.thumbnailPath).to.not.be.null
341 expect(video.previewPath).to.not.be.null
344 it('Should be able to search in my videos', async function () {
346 const { total, data } = await server.videos.listMyVideos({ token: userToken, sort: '-createdAt', search: 'user video' })
347 expect(total).to.equal(1)
348 expect(data).to.have.lengthOf(1)
352 const { total, data } = await server.videos.listMyVideos({ token: userToken, sort: '-createdAt', search: 'toto' })
353 expect(total).to.equal(0)
354 expect(data).to.have.lengthOf(0)
358 it('Should disable webtorrent, enable HLS, and update my quota', async function () {
362 const config = await server.config.getCustomConfig()
363 config.transcoding.webtorrent.enabled = false
364 config.transcoding.hls.enabled = true
365 config.transcoding.enabled = true
366 await server.config.updateCustomSubConfig({ newConfig: config })
371 name: 'super user video 2',
372 fixture: 'video_short.webm'
374 await server.videos.upload({ token: userToken, attributes })
376 await waitJobs([ server ])
380 const data = await server.users.getMyQuotaUsed({ token: userToken })
381 expect(data.videoQuotaUsed).to.be.greaterThan(220000)
386 describe('Users listing', function () {
388 it('Should list all the users', async function () {
389 const { data, total } = await server.users.list()
391 expect(total).to.equal(2)
392 expect(data).to.be.an('array')
393 expect(data.length).to.equal(2)
396 expect(user.username).to.equal('user_1')
397 expect(user.email).to.equal('user_1@example.com')
398 expect(user.nsfwPolicy).to.equal('display')
400 const rootUser = data[1]
401 expect(rootUser.username).to.equal('root')
402 expect(rootUser.email).to.equal('admin' + server.internalServerNumber + '@example.com')
403 expect(user.nsfwPolicy).to.equal('display')
405 expect(rootUser.lastLoginDate).to.exist
406 expect(user.lastLoginDate).to.exist
411 it('Should list only the first user by username asc', async function () {
412 const { total, data } = await server.users.list({ start: 0, count: 1, sort: 'username' })
414 expect(total).to.equal(2)
415 expect(data.length).to.equal(1)
418 expect(user.username).to.equal('root')
419 expect(user.email).to.equal('admin' + server.internalServerNumber + '@example.com')
420 expect(user.roleLabel).to.equal('Administrator')
421 expect(user.nsfwPolicy).to.equal('display')
424 it('Should list only the first user by username desc', async function () {
425 const { total, data } = await server.users.list({ start: 0, count: 1, sort: '-username' })
427 expect(total).to.equal(2)
428 expect(data.length).to.equal(1)
431 expect(user.username).to.equal('user_1')
432 expect(user.email).to.equal('user_1@example.com')
433 expect(user.nsfwPolicy).to.equal('display')
436 it('Should list only the second user by createdAt desc', async function () {
437 const { data, total } = await server.users.list({ start: 0, count: 1, sort: '-createdAt' })
438 expect(total).to.equal(2)
440 expect(data.length).to.equal(1)
443 expect(user.username).to.equal('user_1')
444 expect(user.email).to.equal('user_1@example.com')
445 expect(user.nsfwPolicy).to.equal('display')
448 it('Should list all the users by createdAt asc', async function () {
449 const { data, total } = await server.users.list({ start: 0, count: 2, sort: 'createdAt' })
451 expect(total).to.equal(2)
452 expect(data.length).to.equal(2)
454 expect(data[0].username).to.equal('root')
455 expect(data[0].email).to.equal('admin' + server.internalServerNumber + '@example.com')
456 expect(data[0].nsfwPolicy).to.equal('display')
458 expect(data[1].username).to.equal('user_1')
459 expect(data[1].email).to.equal('user_1@example.com')
460 expect(data[1].nsfwPolicy).to.equal('display')
463 it('Should search user by username', async function () {
464 const { data, total } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', search: 'oot' })
465 expect(total).to.equal(1)
466 expect(data.length).to.equal(1)
467 expect(data[0].username).to.equal('root')
470 it('Should search user by email', async function () {
472 const { total, data } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', search: 'r_1@exam' })
473 expect(total).to.equal(1)
474 expect(data.length).to.equal(1)
475 expect(data[0].username).to.equal('user_1')
476 expect(data[0].email).to.equal('user_1@example.com')
480 const { total, data } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', search: 'example' })
481 expect(total).to.equal(2)
482 expect(data.length).to.equal(2)
483 expect(data[0].username).to.equal('root')
484 expect(data[1].username).to.equal('user_1')
489 describe('Update my account', function () {
491 it('Should update my password', async function () {
492 await server.users.updateMe({
494 currentPassword: 'super password',
495 password: 'new password'
497 user.password = 'new password'
499 await server.login.login({ user })
502 it('Should be able to change the NSFW display attribute', async function () {
503 await server.users.updateMe({
505 nsfwPolicy: 'do_not_list'
508 const user = await server.users.getMyInfo({ token: userToken })
509 expect(user.username).to.equal('user_1')
510 expect(user.email).to.equal('user_1@example.com')
511 expect(user.nsfwPolicy).to.equal('do_not_list')
512 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
513 expect(user.id).to.be.a('number')
514 expect(user.account.displayName).to.equal('user_1')
515 expect(user.account.description).to.be.null
518 it('Should be able to change the autoPlayVideo attribute', async function () {
519 await server.users.updateMe({
524 const user = await server.users.getMyInfo({ token: userToken })
525 expect(user.autoPlayVideo).to.be.false
528 it('Should be able to change the autoPlayNextVideo attribute', async function () {
529 await server.users.updateMe({
531 autoPlayNextVideo: true
534 const user = await server.users.getMyInfo({ token: userToken })
535 expect(user.autoPlayNextVideo).to.be.true
538 it('Should be able to change the email attribute', async function () {
539 await server.users.updateMe({
541 currentPassword: 'new password',
542 email: 'updated@example.com'
545 const user = await server.users.getMyInfo({ token: userToken })
546 expect(user.username).to.equal('user_1')
547 expect(user.email).to.equal('updated@example.com')
548 expect(user.nsfwPolicy).to.equal('do_not_list')
549 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
550 expect(user.id).to.be.a('number')
551 expect(user.account.displayName).to.equal('user_1')
552 expect(user.account.description).to.be.null
555 it('Should be able to update my avatar with a gif', async function () {
556 const fixture = 'avatar.gif'
558 await server.users.updateMyAvatar({ token: userToken, fixture })
560 const user = await server.users.getMyInfo({ token: userToken })
561 await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif')
564 it('Should be able to update my avatar with a gif, and then a png', async function () {
565 for (const extension of [ '.png', '.gif' ]) {
566 const fixture = 'avatar' + extension
568 await server.users.updateMyAvatar({ token: userToken, fixture })
570 const user = await server.users.getMyInfo({ token: userToken })
571 await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension)
575 it('Should be able to update my display name', async function () {
576 await server.users.updateMe({ token: userToken, displayName: 'new display name' })
578 const user = await server.users.getMyInfo({ token: userToken })
579 expect(user.username).to.equal('user_1')
580 expect(user.email).to.equal('updated@example.com')
581 expect(user.nsfwPolicy).to.equal('do_not_list')
582 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
583 expect(user.id).to.be.a('number')
584 expect(user.account.displayName).to.equal('new display name')
585 expect(user.account.description).to.be.null
588 it('Should be able to update my description', async function () {
589 await server.users.updateMe({ token: userToken, description: 'my super description updated' })
591 const user = await server.users.getMyInfo({ token: userToken })
592 expect(user.username).to.equal('user_1')
593 expect(user.email).to.equal('updated@example.com')
594 expect(user.nsfwPolicy).to.equal('do_not_list')
595 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
596 expect(user.id).to.be.a('number')
597 expect(user.account.displayName).to.equal('new display name')
598 expect(user.account.description).to.equal('my super description updated')
599 expect(user.noWelcomeModal).to.be.false
600 expect(user.noInstanceConfigWarningModal).to.be.false
603 it('Should be able to update my theme', async function () {
604 for (const theme of [ 'background-red', 'default', 'instance-default' ]) {
605 await server.users.updateMe({ token: userToken, theme })
607 const user = await server.users.getMyInfo({ token: userToken })
608 expect(user.theme).to.equal(theme)
612 it('Should be able to update my modal preferences', async function () {
613 await server.users.updateMe({
615 noInstanceConfigWarningModal: true,
619 const user = await server.users.getMyInfo({ token: userToken })
620 expect(user.noWelcomeModal).to.be.true
621 expect(user.noInstanceConfigWarningModal).to.be.true
625 describe('Updating another user', function () {
626 it('Should be able to update another user', async function () {
627 await server.users.update({
630 email: 'updated2@example.com',
633 role: UserRole.MODERATOR,
634 adminFlags: UserAdminFlag.NONE,
638 const user = await server.users.get({ token, userId })
640 expect(user.username).to.equal('user_1')
641 expect(user.email).to.equal('updated2@example.com')
642 expect(user.emailVerified).to.be.true
643 expect(user.nsfwPolicy).to.equal('do_not_list')
644 expect(user.videoQuota).to.equal(42)
645 expect(user.roleLabel).to.equal('Moderator')
646 expect(user.id).to.be.a('number')
647 expect(user.adminFlags).to.equal(UserAdminFlag.NONE)
648 expect(user.pluginAuth).to.equal('toto')
651 it('Should reset the auth plugin', async function () {
652 await server.users.update({ userId, token, pluginAuth: null })
654 const user = await server.users.get({ token, userId })
655 expect(user.pluginAuth).to.be.null
658 it('Should have removed the user token', async function () {
659 await server.users.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
661 userToken = await server.login.getAccessToken(user)
664 it('Should be able to update another user password', async function () {
665 await server.users.update({ userId, token, password: 'password updated' })
667 await server.users.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
669 await server.login.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
671 user.password = 'password updated'
672 userToken = await server.login.getAccessToken(user)
676 describe('Video blacklists', function () {
677 it('Should be able to list video blacklist by a moderator', async function () {
678 await server.blacklist.list({ token: userToken })
682 describe('Remove a user', function () {
683 it('Should be able to remove this user', async function () {
684 await server.users.remove({ userId, token })
687 it('Should not be able to login with this user', async function () {
688 await server.login.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
691 it('Should not have videos of this user', async function () {
692 const { data, total } = await server.videos.list()
693 expect(total).to.equal(1)
695 const video = data[0]
696 expect(video.account.name).to.equal('root')
700 describe('Registering a new user', function () {
701 let user15AccessToken
703 it('Should register a new user', async function () {
704 const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' }
705 const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' }
707 await server.users.register({ ...user, channel })
710 it('Should be able to login with this registered user', async function () {
713 password: 'my super password'
716 user15AccessToken = await server.login.getAccessToken(user15)
719 it('Should have the correct display name', async function () {
720 const user = await server.users.getMyInfo({ token: user15AccessToken })
721 expect(user.account.displayName).to.equal('super user 15')
724 it('Should have the correct video quota', async function () {
725 const user = await server.users.getMyInfo({ token: user15AccessToken })
726 expect(user.videoQuota).to.equal(5 * 1024 * 1024)
729 it('Should have created the channel', async function () {
730 const { displayName } = await server.channels.get({ channelName: 'my_user_15_channel' })
732 expect(displayName).to.equal('my channel rocks')
735 it('Should remove me', async function () {
737 const { data } = await server.users.list()
738 expect(data.find(u => u.username === 'user_15')).to.not.be.undefined
741 await server.users.deleteMe({ token: user15AccessToken })
744 const { data } = await server.users.list()
745 expect(data.find(u => u.username === 'user_15')).to.be.undefined
750 describe('User blocking', function () {
752 let user16AccessToken
755 password: 'my super password'
758 it('Should block a user', async function () {
759 const user = await server.users.create({ ...user16 })
762 user16AccessToken = await server.login.getAccessToken(user16)
764 await server.users.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 })
765 await server.users.banUser({ userId: user16Id })
767 await server.users.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
768 await server.login.login({ user: user16, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
771 it('Should search user by banned status', async function () {
773 const { data, total } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', blocked: true })
774 expect(total).to.equal(1)
775 expect(data.length).to.equal(1)
777 expect(data[0].username).to.equal(user16.username)
781 const { data, total } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', blocked: false })
782 expect(total).to.equal(1)
783 expect(data.length).to.equal(1)
785 expect(data[0].username).to.not.equal(user16.username)
789 it('Should unblock a user', async function () {
790 await server.users.unbanUser({ userId: user16Id })
791 user16AccessToken = await server.login.getAccessToken(user16)
792 await server.users.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 })
796 describe('User stats', function () {
798 let user17AccessToken
800 it('Should report correct initial statistics about a user', async function () {
803 password: 'my super password'
805 const created = await server.users.create({ ...user17 })
807 user17Id = created.id
808 user17AccessToken = await server.login.getAccessToken(user17)
810 const user = await server.users.get({ userId: user17Id, withStats: true })
811 expect(user.videosCount).to.equal(0)
812 expect(user.videoCommentsCount).to.equal(0)
813 expect(user.abusesCount).to.equal(0)
814 expect(user.abusesCreatedCount).to.equal(0)
815 expect(user.abusesAcceptedCount).to.equal(0)
818 it('Should report correct videos count', async function () {
819 const attributes = { name: 'video to test user stats' }
820 await server.videos.upload({ token: user17AccessToken, attributes })
822 const { data } = await server.videos.list()
823 videoId = data.find(video => video.name === attributes.name).id
825 const user = await server.users.get({ userId: user17Id, withStats: true })
826 expect(user.videosCount).to.equal(1)
829 it('Should report correct video comments for user', async function () {
830 const text = 'super comment'
831 await server.comments.createThread({ token: user17AccessToken, videoId, text })
833 const user = await server.users.get({ userId: user17Id, withStats: true })
834 expect(user.videoCommentsCount).to.equal(1)
837 it('Should report correct abuses counts', async function () {
838 const reason = 'my super bad reason'
839 await server.abuses.report({ token: user17AccessToken, videoId, reason })
841 const body1 = await server.abuses.getAdminList()
842 const abuseId = body1.data[0].id
844 const user2 = await server.users.get({ userId: user17Id, withStats: true })
845 expect(user2.abusesCount).to.equal(1) // number of incriminations
846 expect(user2.abusesCreatedCount).to.equal(1) // number of reports created
848 await server.abuses.update({ abuseId, body: { state: AbuseState.ACCEPTED } })
850 const user3 = await server.users.get({ userId: user17Id, withStats: true })
851 expect(user3.abusesAcceptedCount).to.equal(1) // number of reports created accepted
855 after(async function () {
856 await cleanupTests([ server ])