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