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