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