]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/users/users.ts
Put channel stats behind withStats flag
[github/Chocobozzz/PeerTube.git] / server / tests / api / users / users.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
86d13ec2 2
0e1dc3e7 3import * as chai from 'chai'
afffe988 4import 'mocha'
76314386 5import { MyUser, User, UserRole, Video, VideoPlaylistType, VideoAbuseState, VideoAbuseUpdate } from '../../../../shared/index'
0e1dc3e7 6import {
a890d1e0 7 blockUser,
7c3b7976 8 cleanupTests,
a890d1e0
C
9 createUser,
10 deleteMe,
7c3b7976 11 flushAndRunServer,
c100a614 12 getAccountRatings,
a890d1e0
C
13 getBlacklistedVideosList,
14 getMyUserInformation,
15 getMyUserVideoQuotaUsed,
16 getMyUserVideoRating,
17 getUserInformation,
18 getUsersList,
19 getUsersListPaginationAndSort,
1f20622f 20 getVideoChannel,
a1587156
C
21 getVideosList,
22 installPlugin,
a890d1e0
C
23 login,
24 makePutBodyRequest,
25 rateVideo,
1f20622f 26 registerUserWithChannel,
a890d1e0
C
27 removeUser,
28 removeVideo,
a890d1e0
C
29 ServerInfo,
30 testImage,
31 unblockUser,
32 updateMyAvatar,
33 updateMyUser,
34 updateUser,
35 uploadVideo,
76314386
RK
36 userLogin,
37 reportVideoAbuse,
38 addVideoCommentThread,
39 updateVideoAbuse,
40 getVideoAbusesList
94565d52
C
41} from '../../../../shared/extra-utils'
42import { follow } from '../../../../shared/extra-utils/server/follows'
43import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
44import { getMyVideos } from '../../../../shared/extra-utils/videos/videos'
1eddc9a7 45import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
0e1dc3e7 46
afffe988
C
47const expect = chai.expect
48
0e1dc3e7
C
49describe('Test users', function () {
50 let server: ServerInfo
51 let accessToken: string
52 let accessTokenUser: string
53 let videoId: number
54 let userId: number
f8b8c36b
C
55 const user = {
56 username: 'user_1',
57 password: 'super password'
58 }
0e1dc3e7
C
59
60 before(async function () {
e212f887 61 this.timeout(30000)
210feb6c 62 server = await flushAndRunServer(1)
86d13ec2
C
63
64 await setAccessTokensToServers([ server ])
9b474844
C
65
66 await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-theme-background-red' })
0e1dc3e7
C
67 })
68
1eddc9a7
C
69 describe('OAuth client', function () {
70 it('Should create a new client')
0e1dc3e7 71
1eddc9a7 72 it('Should return the first client')
0e1dc3e7 73
1eddc9a7 74 it('Should remove the last client')
0e1dc3e7 75
1eddc9a7
C
76 it('Should not login with an invalid client id', async function () {
77 const client = { id: 'client', secret: server.client.secret }
78 const res = await login(server.url, client, server.user, 400)
0e1dc3e7 79
1eddc9a7
C
80 expect(res.body.error).to.contain('client is invalid')
81 })
0e1dc3e7 82
1eddc9a7
C
83 it('Should not login with an invalid client secret', async function () {
84 const client = { id: server.client.id, secret: 'coucou' }
85 const res = await login(server.url, client, server.user, 400)
0e1dc3e7 86
1eddc9a7
C
87 expect(res.body.error).to.contain('client is invalid')
88 })
0e1dc3e7
C
89 })
90
1eddc9a7 91 describe('Login', function () {
0e1dc3e7 92
1eddc9a7
C
93 it('Should not login with an invalid username', async function () {
94 const user = { username: 'captain crochet', password: server.user.password }
95 const res = await login(server.url, server.client, user, 400)
0e1dc3e7 96
1eddc9a7
C
97 expect(res.body.error).to.contain('credentials are invalid')
98 })
0e1dc3e7 99
1eddc9a7
C
100 it('Should not login with an invalid password', async function () {
101 const user = { username: server.user.username, password: 'mew_three' }
102 const res = await login(server.url, server.client, user, 400)
0e1dc3e7 103
1eddc9a7
C
104 expect(res.body.error).to.contain('credentials are invalid')
105 })
0e1dc3e7 106
1eddc9a7
C
107 it('Should not be able to upload a video', async function () {
108 accessToken = 'my_super_token'
0e1dc3e7 109
1eddc9a7
C
110 const videoAttributes = {}
111 await uploadVideo(server.url, accessToken, videoAttributes, 401)
112 })
0e1dc3e7 113
1eddc9a7
C
114 it('Should not be able to follow', async function () {
115 accessToken = 'my_super_token'
116 await follow(server.url, [ 'http://example.com' ], accessToken, 401)
117 })
0e1dc3e7 118
1eddc9a7 119 it('Should not be able to unfollow')
0e1dc3e7 120
1eddc9a7
C
121 it('Should be able to login', async function () {
122 const res = await login(server.url, server.client, server.user, 200)
0e1dc3e7 123
1eddc9a7
C
124 accessToken = res.body.access_token
125 })
50b4dcce
NB
126
127 it('Should be able to login with an insensitive username', async function () {
128 const user = { username: 'RoOt', password: server.user.password }
a1587156 129 await login(server.url, server.client, user, 200)
50b4dcce
NB
130
131 const user2 = { username: 'rOoT', password: server.user.password }
a1587156 132 await login(server.url, server.client, user2, 200)
50b4dcce
NB
133
134 const user3 = { username: 'ROOt', password: server.user.password }
a1587156 135 await login(server.url, server.client, user3, 200)
50b4dcce 136 })
0e1dc3e7
C
137 })
138
1eddc9a7 139 describe('Upload', function () {
0e1dc3e7 140
1eddc9a7
C
141 it('Should upload the video with the correct token', async function () {
142 const videoAttributes = {}
143 await uploadVideo(server.url, accessToken, videoAttributes)
144 const res = await getVideosList(server.url)
a1587156 145 const video = res.body.data[0]
0e1dc3e7 146
1eddc9a7
C
147 expect(video.account.name).to.equal('root')
148 videoId = video.id
149 })
150
151 it('Should upload the video again with the correct token', async function () {
152 const videoAttributes = {}
153 await uploadVideo(server.url, accessToken, videoAttributes)
154 })
0e1dc3e7
C
155 })
156
1eddc9a7 157 describe('Ratings', function () {
22834691 158
1eddc9a7
C
159 it('Should retrieve a video rating', async function () {
160 await rateVideo(server.url, accessToken, videoId, 'like')
161 const res = await getMyUserVideoRating(server.url, accessToken, videoId)
162 const rating = res.body
c100a614 163
1eddc9a7
C
164 expect(rating.videoId).to.equal(videoId)
165 expect(rating.rating).to.equal('like')
166 })
c100a614 167
1eddc9a7
C
168 it('Should retrieve ratings list', async function () {
169 await rateVideo(server.url, accessToken, videoId, 'like')
22834691 170
1eddc9a7 171 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, 200)
22834691 172 const ratings = res.body
0e1dc3e7 173
1eddc9a7 174 expect(ratings.total).to.equal(1)
a1587156
C
175 expect(ratings.data[0].video.id).to.equal(videoId)
176 expect(ratings.data[0].rating).to.equal('like')
1eddc9a7 177 })
0e1dc3e7 178
1eddc9a7
C
179 it('Should retrieve ratings list by rating type', async function () {
180 {
181 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'like')
182 const ratings = res.body
183 expect(ratings.data.length).to.equal(1)
184 }
185
186 {
187 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'dislike')
188 const ratings = res.body
189 expect(ratings.data.length).to.equal(0)
190 }
191 })
0e1dc3e7
C
192 })
193
1eddc9a7
C
194 describe('Remove video', function () {
195 it('Should not be able to remove the video with an incorrect token', async function () {
196 await removeVideo(server.url, 'bad_token', videoId, 401)
197 })
0e1dc3e7 198
1eddc9a7 199 it('Should not be able to remove the video with the token of another account')
0e1dc3e7 200
1eddc9a7
C
201 it('Should be able to remove the video with the correct token', async function () {
202 await removeVideo(server.url, accessToken, videoId)
203 })
0e1dc3e7
C
204 })
205
1eddc9a7
C
206 describe('Logout', function () {
207 it('Should logout (revoke token)')
0e1dc3e7 208
1eddc9a7 209 it('Should not be able to get the user information')
0e1dc3e7 210
1eddc9a7 211 it('Should not be able to upload a video')
0e1dc3e7 212
1eddc9a7 213 it('Should not be able to remove a video')
0e1dc3e7 214
1eddc9a7
C
215 it('Should not be able to rate a video', async function () {
216 const path = '/api/v1/videos/'
217 const data = {
218 rating: 'likes'
219 }
0e1dc3e7 220
1eddc9a7
C
221 const options = {
222 url: server.url,
223 path: path + videoId,
224 token: 'wrong token',
225 fields: data,
226 statusCodeExpected: 401
227 }
228 await makePutBodyRequest(options)
229 })
0e1dc3e7 230
1eddc9a7 231 it('Should be able to login again')
0e1dc3e7 232
1eddc9a7 233 it('Should have an expired access token')
0e1dc3e7 234
1eddc9a7
C
235 it('Should refresh the token')
236
237 it('Should be able to upload a video again')
0e1dc3e7
C
238 })
239
1eddc9a7 240 describe('Creating a user', function () {
ce5496d6 241
1eddc9a7
C
242 it('Should be able to create a new user', async function () {
243 await createUser({
244 url: server.url,
245 accessToken: accessToken,
246 username: user.username,
247 password: user.password,
248 videoQuota: 2 * 1024 * 1024,
249 adminFlags: UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST
250 })
251 })
a76138ff 252
1eddc9a7
C
253 it('Should be able to login with this user', async function () {
254 accessTokenUser = await userLogin(server, user)
255 })
a76138ff 256
1eddc9a7
C
257 it('Should be able to get user information', async function () {
258 const res1 = await getMyUserInformation(server.url, accessTokenUser)
ac0868bc 259 const userMe: MyUser = res1.body
1eddc9a7 260
76314386 261 const res2 = await getUserInformation(server.url, server.accessToken, userMe.id, true)
1eddc9a7
C
262 const userGet: User = res2.body
263
264 for (const user of [ userMe, userGet ]) {
265 expect(user.username).to.equal('user_1')
266 expect(user.email).to.equal('user_1@example.com')
267 expect(user.nsfwPolicy).to.equal('display')
268 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
269 expect(user.roleLabel).to.equal('User')
270 expect(user.id).to.be.a('number')
271 expect(user.account.displayName).to.equal('user_1')
272 expect(user.account.description).to.be.null
273 }
274
275 expect(userMe.adminFlags).to.be.undefined
276 expect(userGet.adminFlags).to.equal(UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST)
29128b2f
RK
277
278 expect(userMe.specialPlaylists).to.have.lengthOf(1)
ac0868bc 279 expect(userMe.specialPlaylists[0].type).to.equal(VideoPlaylistType.WATCH_LATER)
76314386
RK
280
281 // Check stats are included with withStats
282 expect(userGet.videosCount).to.be.a('number')
283 expect(userGet.videosCount).to.equal(0)
284 expect(userGet.videoCommentsCount).to.be.a('number')
285 expect(userGet.videoCommentsCount).to.equal(0)
286 expect(userGet.videoAbusesCount).to.be.a('number')
287 expect(userGet.videoAbusesCount).to.equal(0)
288 expect(userGet.videoAbusesAcceptedCount).to.be.a('number')
289 expect(userGet.videoAbusesAcceptedCount).to.equal(0)
1eddc9a7 290 })
ce5496d6
C
291 })
292
1eddc9a7 293 describe('My videos & quotas', function () {
11474c3c 294
1eddc9a7
C
295 it('Should be able to upload a video with this user', async function () {
296 this.timeout(5000)
0e1dc3e7 297
1eddc9a7
C
298 const videoAttributes = {
299 name: 'super user video',
300 fixture: 'video_short.webm'
301 }
302 await uploadVideo(server.url, accessTokenUser, videoAttributes)
303 })
afffe988 304
1eddc9a7
C
305 it('Should have video quota updated', async function () {
306 const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser)
307 const data = res.body
0e1dc3e7 308
1eddc9a7 309 expect(data.videoQuotaUsed).to.equal(218910)
0e1dc3e7 310
1eddc9a7 311 const resUsers = await getUsersList(server.url, server.accessToken)
0e1dc3e7 312
1eddc9a7
C
313 const users: User[] = resUsers.body.data
314 const tmpUser = users.find(u => u.username === user.username)
315 expect(tmpUser.videoQuotaUsed).to.equal(218910)
316 })
0e1dc3e7 317
1eddc9a7
C
318 it('Should be able to list my videos', async function () {
319 const res = await getMyVideos(server.url, accessTokenUser, 0, 5)
320 expect(res.body.total).to.equal(1)
0e1dc3e7 321
1eddc9a7
C
322 const videos = res.body.data
323 expect(videos).to.have.lengthOf(1)
afffe988 324
a1587156 325 const video: Video = videos[0]
a18f275d
C
326 expect(video.name).to.equal('super user video')
327 expect(video.thumbnailPath).to.not.be.null
328 expect(video.previewPath).to.not.be.null
1eddc9a7 329 })
cca1e13b
C
330
331 it('Should be able to search in my videos', async function () {
332 {
333 const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'user video')
334 expect(res.body.total).to.equal(1)
335
336 const videos = res.body.data
337 expect(videos).to.have.lengthOf(1)
338 }
339
340 {
341 const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'toto')
342 expect(res.body.total).to.equal(0)
343
344 const videos = res.body.data
345 expect(videos).to.have.lengthOf(0)
346 }
347 })
0e1dc3e7
C
348 })
349
1eddc9a7 350 describe('Users listing', function () {
0e1dc3e7 351
1eddc9a7
C
352 it('Should list all the users', async function () {
353 const res = await getUsersList(server.url, server.accessToken)
354 const result = res.body
355 const total = result.total
356 const users = result.data
afffe988 357
1eddc9a7
C
358 expect(total).to.equal(2)
359 expect(users).to.be.an('array')
360 expect(users.length).to.equal(2)
0e1dc3e7 361
a1587156 362 const user = users[0]
1eddc9a7
C
363 expect(user.username).to.equal('user_1')
364 expect(user.email).to.equal('user_1@example.com')
365 expect(user.nsfwPolicy).to.equal('display')
0e1dc3e7 366
a1587156 367 const rootUser = users[1]
1eddc9a7 368 expect(rootUser.username).to.equal('root')
48f07b4a 369 expect(rootUser.email).to.equal('admin' + server.internalServerNumber + '@example.com')
1eddc9a7 370 expect(user.nsfwPolicy).to.equal('display')
afffe988 371
1eddc9a7
C
372 userId = user.id
373 })
0e1dc3e7 374
1eddc9a7
C
375 it('Should list only the first user by username asc', async function () {
376 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, 'username')
0e1dc3e7 377
1eddc9a7
C
378 const result = res.body
379 const total = result.total
380 const users = result.data
a7ba16b6 381
1eddc9a7
C
382 expect(total).to.equal(2)
383 expect(users.length).to.equal(1)
afffe988 384
a1587156 385 const user = users[0]
1eddc9a7 386 expect(user.username).to.equal('root')
48f07b4a 387 expect(user.email).to.equal('admin' + server.internalServerNumber + '@example.com')
1eddc9a7
C
388 expect(user.roleLabel).to.equal('Administrator')
389 expect(user.nsfwPolicy).to.equal('display')
390 })
0e1dc3e7 391
1eddc9a7
C
392 it('Should list only the first user by username desc', async function () {
393 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-username')
394 const result = res.body
395 const total = result.total
396 const users = result.data
24b9417c 397
1eddc9a7
C
398 expect(total).to.equal(2)
399 expect(users.length).to.equal(1)
24b9417c 400
a1587156 401 const user = users[0]
1eddc9a7
C
402 expect(user.username).to.equal('user_1')
403 expect(user.email).to.equal('user_1@example.com')
404 expect(user.nsfwPolicy).to.equal('display')
405 })
24b9417c 406
1eddc9a7
C
407 it('Should list only the second user by createdAt desc', async function () {
408 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-createdAt')
409 const result = res.body
410 const total = result.total
411 const users = result.data
24b9417c 412
1eddc9a7 413 expect(total).to.equal(2)
24b9417c
C
414 expect(users.length).to.equal(1)
415
a1587156 416 const user = users[0]
1eddc9a7
C
417 expect(user.username).to.equal('user_1')
418 expect(user.email).to.equal('user_1@example.com')
419 expect(user.nsfwPolicy).to.equal('display')
420 })
24b9417c 421
1eddc9a7
C
422 it('Should list all the users by createdAt asc', async function () {
423 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt')
424 const result = res.body
425 const total = result.total
426 const users = result.data
24b9417c 427
1eddc9a7 428 expect(total).to.equal(2)
24b9417c
C
429 expect(users.length).to.equal(2)
430
a1587156
C
431 expect(users[0].username).to.equal('root')
432 expect(users[0].email).to.equal('admin' + server.internalServerNumber + '@example.com')
433 expect(users[0].nsfwPolicy).to.equal('display')
24b9417c 434
a1587156
C
435 expect(users[1].username).to.equal('user_1')
436 expect(users[1].email).to.equal('user_1@example.com')
437 expect(users[1].nsfwPolicy).to.equal('display')
11ba2ab3 438 })
0e1dc3e7 439
1eddc9a7
C
440 it('Should search user by username', async function () {
441 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'oot')
442 const users = res.body.data as User[]
443
444 expect(res.body.total).to.equal(1)
445 expect(users.length).to.equal(1)
0e1dc3e7 446
a1587156 447 expect(users[0].username).to.equal('root')
11ba2ab3 448 })
0e1dc3e7 449
1eddc9a7
C
450 it('Should search user by email', async function () {
451 {
452 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'r_1@exam')
453 const users = res.body.data as User[]
0e1dc3e7 454
1eddc9a7
C
455 expect(res.body.total).to.equal(1)
456 expect(users.length).to.equal(1)
5c98d3bf 457
a1587156
C
458 expect(users[0].username).to.equal('user_1')
459 expect(users[0].email).to.equal('user_1@example.com')
1eddc9a7 460 }
7efe153b 461
1eddc9a7
C
462 {
463 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'example')
464 const users = res.body.data as User[]
7efe153b 465
1eddc9a7
C
466 expect(res.body.total).to.equal(2)
467 expect(users.length).to.equal(2)
7efe153b 468
a1587156
C
469 expect(users[0].username).to.equal('root')
470 expect(users[1].username).to.equal('user_1')
1eddc9a7 471 }
11ba2ab3 472 })
5c98d3bf
C
473 })
474
1eddc9a7
C
475 describe('Update my account', function () {
476 it('Should update my password', async function () {
477 await updateMyUser({
478 url: server.url,
479 accessToken: accessTokenUser,
480 currentPassword: 'super password',
43d0ea7f 481 password: 'new password'
1eddc9a7
C
482 })
483 user.password = 'new password'
c5911fd3 484
1eddc9a7 485 await userLogin(server, user, 200)
c5911fd3
C
486 })
487
1eddc9a7
C
488 it('Should be able to change the NSFW display attribute', async function () {
489 await updateMyUser({
490 url: server.url,
491 accessToken: accessTokenUser,
492 nsfwPolicy: 'do_not_list'
493 })
494
495 const res = await getMyUserInformation(server.url, accessTokenUser)
496 const user = res.body
497
498 expect(user.username).to.equal('user_1')
499 expect(user.email).to.equal('user_1@example.com')
500 expect(user.nsfwPolicy).to.equal('do_not_list')
501 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
502 expect(user.id).to.be.a('number')
503 expect(user.account.displayName).to.equal('user_1')
504 expect(user.account.description).to.be.null
505 })
c5911fd3 506
1eddc9a7
C
507 it('Should be able to change the autoPlayVideo attribute', async function () {
508 await updateMyUser({
509 url: server.url,
510 accessToken: accessTokenUser,
511 autoPlayVideo: false
512 })
c5911fd3 513
1eddc9a7
C
514 const res = await getMyUserInformation(server.url, accessTokenUser)
515 const user = res.body
516
517 expect(user.autoPlayVideo).to.be.false
ed56ad11
C
518 })
519
6aa54148
L
520 it('Should be able to change the autoPlayNextVideo attribute', async function () {
521 await updateMyUser({
522 url: server.url,
523 accessToken: accessTokenUser,
524 autoPlayNextVideo: true
525 })
526
527 const res = await getMyUserInformation(server.url, accessTokenUser)
528 const user = res.body
529
530 expect(user.autoPlayNextVideo).to.be.true
531 })
532
675a8fc7 533 it('Should be able to change the email attribute', async function () {
1eddc9a7
C
534 await updateMyUser({
535 url: server.url,
536 accessToken: accessTokenUser,
675a8fc7 537 currentPassword: 'new password',
1eddc9a7
C
538 email: 'updated@example.com'
539 })
540
541 const res = await getMyUserInformation(server.url, accessTokenUser)
542 const user = res.body
543
544 expect(user.username).to.equal('user_1')
545 expect(user.email).to.equal('updated@example.com')
546 expect(user.nsfwPolicy).to.equal('do_not_list')
547 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
548 expect(user.id).to.be.a('number')
549 expect(user.account.displayName).to.equal('user_1')
550 expect(user.account.description).to.be.null
551 })
ed56ad11 552
1eddc9a7
C
553 it('Should be able to update my avatar', async function () {
554 const fixture = 'avatar.png'
ed56ad11 555
1eddc9a7
C
556 await updateMyAvatar({
557 url: server.url,
558 accessToken: accessTokenUser,
559 fixture
560 })
2422c46b 561
1eddc9a7
C
562 const res = await getMyUserInformation(server.url, accessTokenUser)
563 const user = res.body
2422c46b 564
1eddc9a7
C
565 await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.png')
566 })
567
568 it('Should be able to update my display name', async function () {
569 await updateMyUser({
570 url: server.url,
571 accessToken: accessTokenUser,
572 displayName: 'new display name'
573 })
574
575 const res = await getMyUserInformation(server.url, accessTokenUser)
576 const user = res.body
577
578 expect(user.username).to.equal('user_1')
579 expect(user.email).to.equal('updated@example.com')
580 expect(user.nsfwPolicy).to.equal('do_not_list')
581 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
582 expect(user.id).to.be.a('number')
583 expect(user.account.displayName).to.equal('new display name')
584 expect(user.account.description).to.be.null
585 })
2422c46b 586
1eddc9a7
C
587 it('Should be able to update my description', async function () {
588 await updateMyUser({
589 url: server.url,
590 accessToken: accessTokenUser,
591 description: 'my super description updated'
592 })
593
594 const res = await getMyUserInformation(server.url, accessTokenUser)
43d0ea7f 595 const user: User = res.body
1eddc9a7
C
596
597 expect(user.username).to.equal('user_1')
598 expect(user.email).to.equal('updated@example.com')
599 expect(user.nsfwPolicy).to.equal('do_not_list')
600 expect(user.videoQuota).to.equal(2 * 1024 * 1024)
601 expect(user.id).to.be.a('number')
602 expect(user.account.displayName).to.equal('new display name')
603 expect(user.account.description).to.equal('my super description updated')
43d0ea7f
C
604 expect(user.noWelcomeModal).to.be.false
605 expect(user.noInstanceConfigWarningModal).to.be.false
1eddc9a7 606 })
9b474844
C
607
608 it('Should be able to update my theme', async function () {
609 for (const theme of [ 'background-red', 'default', 'instance-default' ]) {
610 await updateMyUser({
611 url: server.url,
612 accessToken: accessTokenUser,
613 theme
614 })
615
616 const res = await getMyUserInformation(server.url, accessTokenUser)
617 const body: User = res.body
618
619 expect(body.theme).to.equal(theme)
620 }
621 })
43d0ea7f
C
622
623 it('Should be able to update my modal preferences', async function () {
624 await updateMyUser({
625 url: server.url,
626 accessToken: accessTokenUser,
627 noInstanceConfigWarningModal: true,
628 noWelcomeModal: true
629 })
630
631 const res = await getMyUserInformation(server.url, accessTokenUser)
632 const user: User = res.body
633
634 expect(user.noWelcomeModal).to.be.true
635 expect(user.noInstanceConfigWarningModal).to.be.true
636 })
0e1dc3e7
C
637 })
638
1eddc9a7 639 describe('Updating another user', function () {
1eddc9a7
C
640 it('Should be able to update another user', async function () {
641 await updateUser({
642 url: server.url,
643 userId,
644 accessToken,
645 email: 'updated2@example.com',
646 emailVerified: true,
647 videoQuota: 42,
648 role: UserRole.MODERATOR,
649 adminFlags: UserAdminFlag.NONE
650 })
651
652 const res = await getUserInformation(server.url, accessToken, userId)
653 const user = res.body
654
655 expect(user.username).to.equal('user_1')
656 expect(user.email).to.equal('updated2@example.com')
657 expect(user.emailVerified).to.be.true
658 expect(user.nsfwPolicy).to.equal('do_not_list')
659 expect(user.videoQuota).to.equal(42)
660 expect(user.roleLabel).to.equal('Moderator')
661 expect(user.id).to.be.a('number')
662 expect(user.adminFlags).to.equal(UserAdminFlag.NONE)
663 })
f8b8c36b 664
1eddc9a7
C
665 it('Should have removed the user token', async function () {
666 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401)
f8b8c36b 667
1eddc9a7 668 accessTokenUser = await userLogin(server, user)
b426edd4
C
669 })
670
1eddc9a7
C
671 it('Should be able to update another user password', async function () {
672 await updateUser({
673 url: server.url,
674 userId,
675 accessToken,
676 password: 'password updated'
677 })
b426edd4 678
1eddc9a7 679 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401)
b426edd4 680
1eddc9a7 681 await userLogin(server, user, 400)
b426edd4 682
1eddc9a7
C
683 user.password = 'password updated'
684 accessTokenUser = await userLogin(server, user)
685 })
757f0da3
C
686 })
687
1eddc9a7
C
688 describe('Video blacklists', function () {
689 it('Should be able to list video blacklist by a moderator', async function () {
690 await getBlacklistedVideosList({ url: server.url, token: accessTokenUser })
691 })
0e1dc3e7
C
692 })
693
1eddc9a7
C
694 describe('Remove a user', function () {
695 it('Should be able to remove this user', async function () {
696 await removeUser(server.url, userId, accessToken)
697 })
0e1dc3e7 698
1eddc9a7
C
699 it('Should not be able to login with this user', async function () {
700 await userLogin(server, user, 400)
701 })
0e1dc3e7 702
1eddc9a7
C
703 it('Should not have videos of this user', async function () {
704 const res = await getVideosList(server.url)
0e1dc3e7 705
1eddc9a7 706 expect(res.body.total).to.equal(1)
0e1dc3e7 707
a1587156 708 const video = res.body.data[0]
1eddc9a7
C
709 expect(video.account.name).to.equal('root')
710 })
0e1dc3e7
C
711 })
712
1eddc9a7 713 describe('Registering a new user', function () {
76314386
RK
714 let user15AccessToken
715
1eddc9a7 716 it('Should register a new user', async function () {
1f20622f 717 const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' }
e590b4a5
C
718 const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' }
719
720 await registerUserWithChannel({ url: server.url, user, channel })
1eddc9a7 721 })
0e1dc3e7 722
1eddc9a7
C
723 it('Should be able to login with this registered user', async function () {
724 const user15 = {
725 username: 'user_15',
726 password: 'my super password'
727 }
5c98d3bf 728
76314386 729 user15AccessToken = await userLogin(server, user15)
1eddc9a7 730 })
5c98d3bf 731
1f20622f 732 it('Should have the correct display name', async function () {
76314386 733 const res = await getMyUserInformation(server.url, user15AccessToken)
1f20622f
C
734 const user: User = res.body
735
736 expect(user.account.displayName).to.equal('super user 15')
737 })
738
1eddc9a7 739 it('Should have the correct video quota', async function () {
76314386 740 const res = await getMyUserInformation(server.url, user15AccessToken)
1eddc9a7 741 const user = res.body
0e1dc3e7 742
1eddc9a7
C
743 expect(user.videoQuota).to.equal(5 * 1024 * 1024)
744 })
92b9d60c 745
e590b4a5
C
746 it('Should have created the channel', async function () {
747 const res = await getVideoChannel(server.url, 'my_user_15_channel')
748
749 expect(res.body.displayName).to.equal('my channel rocks')
750 })
751
1eddc9a7
C
752 it('Should remove me', async function () {
753 {
754 const res = await getUsersList(server.url, server.accessToken)
755 expect(res.body.data.find(u => u.username === 'user_15')).to.not.be.undefined
756 }
92b9d60c 757
76314386 758 await deleteMe(server.url, user15AccessToken)
1eddc9a7
C
759
760 {
761 const res = await getUsersList(server.url, server.accessToken)
762 expect(res.body.data.find(u => u.username === 'user_15')).to.be.undefined
763 }
764 })
92b9d60c
C
765 })
766
1eddc9a7 767 describe('User blocking', function () {
76314386
RK
768 let user16Id
769 let user16AccessToken
770
1eddc9a7
C
771 it('Should block and unblock a user', async function () {
772 const user16 = {
773 username: 'user_16',
774 password: 'my super password'
775 }
776 const resUser = await createUser({
777 url: server.url,
778 accessToken: server.accessToken,
779 username: user16.username,
780 password: user16.password
781 })
76314386 782 user16Id = resUser.body.user.id
e6921918 783
76314386 784 user16AccessToken = await userLogin(server, user16)
e6921918 785
76314386 786 await getMyUserInformation(server.url, user16AccessToken, 200)
1eddc9a7 787 await blockUser(server.url, user16Id, server.accessToken)
e6921918 788
76314386 789 await getMyUserInformation(server.url, user16AccessToken, 401)
1eddc9a7 790 await userLogin(server, user16, 400)
e6921918 791
1eddc9a7 792 await unblockUser(server.url, user16Id, server.accessToken)
76314386
RK
793 user16AccessToken = await userLogin(server, user16)
794 await getMyUserInformation(server.url, user16AccessToken, 200)
795 })
796 })
797
798 describe('User stats', function () {
799 let user17Id
800 let user17AccessToken
801
802 it('Should report correct initial statistics about a user', async function () {
803 const user17 = {
804 username: 'user_17',
805 password: 'my super password'
806 }
807 const resUser = await createUser({
808 url: server.url,
809 accessToken: server.accessToken,
810 username: user17.username,
811 password: user17.password
812 })
813
814 user17Id = resUser.body.user.id
815 user17AccessToken = await userLogin(server, user17)
816
817 const res = await getUserInformation(server.url, server.accessToken, user17Id, true)
818 const user: User = res.body
819
820 expect(user.videosCount).to.equal(0)
821 expect(user.videoCommentsCount).to.equal(0)
822 expect(user.videoAbusesCount).to.equal(0)
823 expect(user.videoAbusesCreatedCount).to.equal(0)
824 expect(user.videoAbusesAcceptedCount).to.equal(0)
825 })
826
827 it('Should report correct videos count', async function () {
828 const videoAttributes = {
829 name: 'video to test user stats'
830 }
831 await uploadVideo(server.url, user17AccessToken, videoAttributes)
832 const res1 = await getVideosList(server.url)
833 videoId = res1.body.data.find(video => video.name === videoAttributes.name).id
834
835 const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true)
836 const user: User = res2.body
837
838 expect(user.videosCount).to.equal(1)
839 })
840
841 it('Should report correct video comments for user', async function () {
842 const text = 'super comment'
843 await addVideoCommentThread(server.url, user17AccessToken, videoId, text)
844
845 const res = await getUserInformation(server.url, server.accessToken, user17Id, true)
846 const user: User = res.body
847
848 expect(user.videoCommentsCount).to.equal(1)
849 })
850
851 it('Should report correct video abuses counts', async function () {
852 const reason = 'my super bad reason'
853 await reportVideoAbuse(server.url, user17AccessToken, videoId, reason)
854
855 const res1 = await getVideoAbusesList(server.url, server.accessToken)
856 const abuseId = res1.body.data[0].id
857
858 const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true)
859 const user2: User = res2.body
860
861 expect(user2.videoAbusesCount).to.equal(1) // number of incriminations
862 expect(user2.videoAbusesCreatedCount).to.equal(1) // number of reports created
863
864 const body: VideoAbuseUpdate = { state: VideoAbuseState.ACCEPTED }
865 await updateVideoAbuse(server.url, server.accessToken, videoId, abuseId, body)
866
867 const res3 = await getUserInformation(server.url, server.accessToken, user17Id, true)
868 const user3: User = res3.body
869
870 expect(user3.videoAbusesAcceptedCount).to.equal(1) // number of reports created accepted
1eddc9a7 871 })
e6921918
C
872 })
873
7c3b7976
C
874 after(async function () {
875 await cleanupTests([ server ])
0e1dc3e7
C
876 })
877})