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