aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/users/users.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-13 14:23:01 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:18 +0200
commit7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0 (patch)
tree7a166515e4d57a06eb3c08be569f106ed049988b /server/tests/api/users/users.ts
parentd0a0fa429d4651710ed951a3c11af0219e408964 (diff)
downloadPeerTube-7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0.tar.gz
PeerTube-7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0.tar.zst
PeerTube-7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0.zip
Introduce user command
Diffstat (limited to 'server/tests/api/users/users.ts')
-rw-r--r--server/tests/api/users/users.ts374
1 files changed, 118 insertions, 256 deletions
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts
index 608bedb8b..30d7e850d 100644
--- a/server/tests/api/users/users.ts
+++ b/server/tests/api/users/users.ts
@@ -4,37 +4,22 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { HttpStatusCode } from '@shared/core-utils' 5import { HttpStatusCode } from '@shared/core-utils'
6import { 6import {
7 blockUser,
8 cleanupTests, 7 cleanupTests,
9 createUser,
10 deleteMe,
11 flushAndRunServer, 8 flushAndRunServer,
12 getMyUserInformation,
13 getMyUserVideoQuotaUsed,
14 getMyUserVideoRating,
15 getMyVideos, 9 getMyVideos,
16 getUserInformation,
17 getUsersList,
18 getUsersListPaginationAndSort,
19 getVideosList, 10 getVideosList,
20 killallServers, 11 killallServers,
21 makePutBodyRequest, 12 makePutBodyRequest,
22 rateVideo, 13 rateVideo,
23 registerUserWithChannel,
24 removeUser,
25 removeVideo, 14 removeVideo,
26 reRunServer, 15 reRunServer,
27 ServerInfo, 16 ServerInfo,
28 setAccessTokensToServers, 17 setAccessTokensToServers,
29 testImage, 18 testImage,
30 unblockUser,
31 updateMyAvatar,
32 updateMyUser,
33 updateUser,
34 uploadVideo, 19 uploadVideo,
35 waitJobs 20 waitJobs
36} from '@shared/extra-utils' 21} from '@shared/extra-utils'
37import { AbuseState, MyUser, OAuth2ErrorCode, User, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' 22import { AbuseState, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models'
38 23
39const expect = chai.expect 24const expect = chai.expect
40 25
@@ -174,8 +159,7 @@ describe('Test users', function () {
174 159
175 it('Should retrieve a video rating', async function () { 160 it('Should retrieve a video rating', async function () {
176 await rateVideo(server.url, accessToken, videoId, 'like') 161 await rateVideo(server.url, accessToken, videoId, 'like')
177 const res = await getMyUserVideoRating(server.url, accessToken, videoId) 162 const rating = await server.usersCommand.getMyRating({ token: accessToken, videoId })
178 const rating = res.body
179 163
180 expect(rating.videoId).to.equal(videoId) 164 expect(rating.videoId).to.equal(videoId)
181 expect(rating.rating).to.equal('like') 165 expect(rating.rating).to.equal('like')
@@ -222,7 +206,7 @@ describe('Test users', function () {
222 }) 206 })
223 207
224 it('Should not be able to get the user information', async function () { 208 it('Should not be able to get the user information', async function () {
225 await getMyUserInformation(server.url, server.accessToken, HttpStatusCode.UNAUTHORIZED_401) 209 await server.usersCommand.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
226 }) 210 })
227 211
228 it('Should not be able to upload a video', async function () { 212 it('Should not be able to upload a video', async function () {
@@ -252,7 +236,7 @@ describe('Test users', function () {
252 }) 236 })
253 237
254 it('Should be able to get my user information again', async function () { 238 it('Should be able to get my user information again', async function () {
255 await getMyUserInformation(server.url, server.accessToken) 239 await server.usersCommand.getMyInfo()
256 }) 240 })
257 241
258 it('Should have an expired access token', async function () { 242 it('Should have an expired access token', async function () {
@@ -264,7 +248,7 @@ describe('Test users', function () {
264 await killallServers([ server ]) 248 await killallServers([ server ])
265 await reRunServer(server) 249 await reRunServer(server)
266 250
267 await getMyUserInformation(server.url, server.accessToken, HttpStatusCode.UNAUTHORIZED_401) 251 await server.usersCommand.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
268 }) 252 })
269 253
270 it('Should not be able to refresh an access token with an expired refresh token', async function () { 254 it('Should not be able to refresh an access token with an expired refresh token', async function () {
@@ -286,21 +270,14 @@ describe('Test users', function () {
286 }) 270 })
287 271
288 it('Should be able to get my user information again', async function () { 272 it('Should be able to get my user information again', async function () {
289 await getMyUserInformation(server.url, server.accessToken) 273 await server.usersCommand.getMyInfo()
290 }) 274 })
291 }) 275 })
292 276
293 describe('Creating a user', function () { 277 describe('Creating a user', function () {
294 278
295 it('Should be able to create a new user', async function () { 279 it('Should be able to create a new user', async function () {
296 await createUser({ 280 await server.usersCommand.create({ ...user, videoQuota: 2 * 1024 * 1024, adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST })
297 url: server.url,
298 accessToken: accessToken,
299 username: user.username,
300 password: user.password,
301 videoQuota: 2 * 1024 * 1024,
302 adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST
303 })
304 }) 281 })
305 282
306 it('Should be able to login with this user', async function () { 283 it('Should be able to login with this user', async function () {
@@ -308,11 +285,9 @@ describe('Test users', function () {
308 }) 285 })
309 286
310 it('Should be able to get user information', async function () { 287 it('Should be able to get user information', async function () {
311 const res1 = await getMyUserInformation(server.url, accessTokenUser) 288 const userMe = await server.usersCommand.getMyInfo({ token: accessTokenUser })
312 const userMe: MyUser = res1.body
313 289
314 const res2 = await getUserInformation(server.url, server.accessToken, userMe.id, true) 290 const userGet = await server.usersCommand.get({ userId: userMe.id, withStats: true })
315 const userGet: User = res2.body
316 291
317 for (const user of [ userMe, userGet ]) { 292 for (const user of [ userMe, userGet ]) {
318 expect(user.username).to.equal('user_1') 293 expect(user.username).to.equal('user_1')
@@ -356,15 +331,11 @@ describe('Test users', function () {
356 }) 331 })
357 332
358 it('Should have video quota updated', async function () { 333 it('Should have video quota updated', async function () {
359 const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser) 334 const quota = await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser })
360 const data = res.body 335 expect(quota.videoQuotaUsed).to.equal(218910)
361
362 expect(data.videoQuotaUsed).to.equal(218910)
363
364 const resUsers = await getUsersList(server.url, server.accessToken)
365 336
366 const users: User[] = resUsers.body.data 337 const { data } = await server.usersCommand.list()
367 const tmpUser = users.find(u => u.username === user.username) 338 const tmpUser = data.find(u => u.username === user.username)
368 expect(tmpUser.videoQuotaUsed).to.equal(218910) 339 expect(tmpUser.videoQuotaUsed).to.equal(218910)
369 }) 340 })
370 341
@@ -421,9 +392,7 @@ describe('Test users', function () {
421 } 392 }
422 393
423 { 394 {
424 const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser) 395 const data = await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser })
425 const data = res.body
426
427 expect(data.videoQuotaUsed).to.be.greaterThan(220000) 396 expect(data.videoQuotaUsed).to.be.greaterThan(220000)
428 } 397 }
429 }) 398 })
@@ -432,21 +401,18 @@ describe('Test users', function () {
432 describe('Users listing', function () { 401 describe('Users listing', function () {
433 402
434 it('Should list all the users', async function () { 403 it('Should list all the users', async function () {
435 const res = await getUsersList(server.url, server.accessToken) 404 const { data, total } = await server.usersCommand.list()
436 const result = res.body
437 const total = result.total
438 const users = result.data
439 405
440 expect(total).to.equal(2) 406 expect(total).to.equal(2)
441 expect(users).to.be.an('array') 407 expect(data).to.be.an('array')
442 expect(users.length).to.equal(2) 408 expect(data.length).to.equal(2)
443 409
444 const user = users[0] 410 const user = data[0]
445 expect(user.username).to.equal('user_1') 411 expect(user.username).to.equal('user_1')
446 expect(user.email).to.equal('user_1@example.com') 412 expect(user.email).to.equal('user_1@example.com')
447 expect(user.nsfwPolicy).to.equal('display') 413 expect(user.nsfwPolicy).to.equal('display')
448 414
449 const rootUser = users[1] 415 const rootUser = data[1]
450 expect(rootUser.username).to.equal('root') 416 expect(rootUser.username).to.equal('root')
451 expect(rootUser.email).to.equal('admin' + server.internalServerNumber + '@example.com') 417 expect(rootUser.email).to.equal('admin' + server.internalServerNumber + '@example.com')
452 expect(user.nsfwPolicy).to.equal('display') 418 expect(user.nsfwPolicy).to.equal('display')
@@ -458,16 +424,12 @@ describe('Test users', function () {
458 }) 424 })
459 425
460 it('Should list only the first user by username asc', async function () { 426 it('Should list only the first user by username asc', async function () {
461 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, 'username') 427 const { total, data } = await server.usersCommand.list({ start: 0, count: 1, sort: 'username' })
462
463 const result = res.body
464 const total = result.total
465 const users = result.data
466 428
467 expect(total).to.equal(2) 429 expect(total).to.equal(2)
468 expect(users.length).to.equal(1) 430 expect(data.length).to.equal(1)
469 431
470 const user = users[0] 432 const user = data[0]
471 expect(user.username).to.equal('root') 433 expect(user.username).to.equal('root')
472 expect(user.email).to.equal('admin' + server.internalServerNumber + '@example.com') 434 expect(user.email).to.equal('admin' + server.internalServerNumber + '@example.com')
473 expect(user.roleLabel).to.equal('Administrator') 435 expect(user.roleLabel).to.equal('Administrator')
@@ -475,84 +437,66 @@ describe('Test users', function () {
475 }) 437 })
476 438
477 it('Should list only the first user by username desc', async function () { 439 it('Should list only the first user by username desc', async function () {
478 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-username') 440 const { total, data } = await server.usersCommand.list({ start: 0, count: 1, sort: '-username' })
479 const result = res.body
480 const total = result.total
481 const users = result.data
482 441
483 expect(total).to.equal(2) 442 expect(total).to.equal(2)
484 expect(users.length).to.equal(1) 443 expect(data.length).to.equal(1)
485 444
486 const user = users[0] 445 const user = data[0]
487 expect(user.username).to.equal('user_1') 446 expect(user.username).to.equal('user_1')
488 expect(user.email).to.equal('user_1@example.com') 447 expect(user.email).to.equal('user_1@example.com')
489 expect(user.nsfwPolicy).to.equal('display') 448 expect(user.nsfwPolicy).to.equal('display')
490 }) 449 })
491 450
492 it('Should list only the second user by createdAt desc', async function () { 451 it('Should list only the second user by createdAt desc', async function () {
493 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-createdAt') 452 const { data, total } = await server.usersCommand.list({ start: 0, count: 1, sort: '-createdAt' })
494 const result = res.body
495 const total = result.total
496 const users = result.data
497
498 expect(total).to.equal(2) 453 expect(total).to.equal(2)
499 expect(users.length).to.equal(1)
500 454
501 const user = users[0] 455 expect(data.length).to.equal(1)
456
457 const user = data[0]
502 expect(user.username).to.equal('user_1') 458 expect(user.username).to.equal('user_1')
503 expect(user.email).to.equal('user_1@example.com') 459 expect(user.email).to.equal('user_1@example.com')
504 expect(user.nsfwPolicy).to.equal('display') 460 expect(user.nsfwPolicy).to.equal('display')
505 }) 461 })
506 462
507 it('Should list all the users by createdAt asc', async function () { 463 it('Should list all the users by createdAt asc', async function () {
508 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt') 464 const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt' })
509 const result = res.body
510 const total = result.total
511 const users = result.data
512 465
513 expect(total).to.equal(2) 466 expect(total).to.equal(2)
514 expect(users.length).to.equal(2) 467 expect(data.length).to.equal(2)
515 468
516 expect(users[0].username).to.equal('root') 469 expect(data[0].username).to.equal('root')
517 expect(users[0].email).to.equal('admin' + server.internalServerNumber + '@example.com') 470 expect(data[0].email).to.equal('admin' + server.internalServerNumber + '@example.com')
518 expect(users[0].nsfwPolicy).to.equal('display') 471 expect(data[0].nsfwPolicy).to.equal('display')
519 472
520 expect(users[1].username).to.equal('user_1') 473 expect(data[1].username).to.equal('user_1')
521 expect(users[1].email).to.equal('user_1@example.com') 474 expect(data[1].email).to.equal('user_1@example.com')
522 expect(users[1].nsfwPolicy).to.equal('display') 475 expect(data[1].nsfwPolicy).to.equal('display')
523 }) 476 })
524 477
525 it('Should search user by username', async function () { 478 it('Should search user by username', async function () {
526 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'oot') 479 const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', search: 'oot' })
527 const users = res.body.data as User[] 480 expect(total).to.equal(1)
528 481 expect(data.length).to.equal(1)
529 expect(res.body.total).to.equal(1) 482 expect(data[0].username).to.equal('root')
530 expect(users.length).to.equal(1)
531
532 expect(users[0].username).to.equal('root')
533 }) 483 })
534 484
535 it('Should search user by email', async function () { 485 it('Should search user by email', async function () {
536 { 486 {
537 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'r_1@exam') 487 const { total, data } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', search: 'r_1@exam' })
538 const users = res.body.data as User[] 488 expect(total).to.equal(1)
539 489 expect(data.length).to.equal(1)
540 expect(res.body.total).to.equal(1) 490 expect(data[0].username).to.equal('user_1')
541 expect(users.length).to.equal(1) 491 expect(data[0].email).to.equal('user_1@example.com')
542
543 expect(users[0].username).to.equal('user_1')
544 expect(users[0].email).to.equal('user_1@example.com')
545 } 492 }
546 493
547 { 494 {
548 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'example') 495 const { total, data } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', search: 'example' })
549 const users = res.body.data as User[] 496 expect(total).to.equal(2)
550 497 expect(data.length).to.equal(2)
551 expect(res.body.total).to.equal(2) 498 expect(data[0].username).to.equal('root')
552 expect(users.length).to.equal(2) 499 expect(data[1].username).to.equal('user_1')
553
554 expect(users[0].username).to.equal('root')
555 expect(users[1].username).to.equal('user_1')
556 } 500 }
557 }) 501 })
558 }) 502 })
@@ -560,9 +504,8 @@ describe('Test users', function () {
560 describe('Update my account', function () { 504 describe('Update my account', function () {
561 505
562 it('Should update my password', async function () { 506 it('Should update my password', async function () {
563 await updateMyUser({ 507 await server.usersCommand.updateMe({
564 url: server.url, 508 token: accessTokenUser,
565 accessToken: accessTokenUser,
566 currentPassword: 'super password', 509 currentPassword: 'super password',
567 password: 'new password' 510 password: 'new password'
568 }) 511 })
@@ -572,15 +515,12 @@ describe('Test users', function () {
572 }) 515 })
573 516
574 it('Should be able to change the NSFW display attribute', async function () { 517 it('Should be able to change the NSFW display attribute', async function () {
575 await updateMyUser({ 518 await server.usersCommand.updateMe({
576 url: server.url, 519 token: accessTokenUser,
577 accessToken: accessTokenUser,
578 nsfwPolicy: 'do_not_list' 520 nsfwPolicy: 'do_not_list'
579 }) 521 })
580 522
581 const res = await getMyUserInformation(server.url, accessTokenUser) 523 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
582 const user = res.body
583
584 expect(user.username).to.equal('user_1') 524 expect(user.username).to.equal('user_1')
585 expect(user.email).to.equal('user_1@example.com') 525 expect(user.email).to.equal('user_1@example.com')
586 expect(user.nsfwPolicy).to.equal('do_not_list') 526 expect(user.nsfwPolicy).to.equal('do_not_list')
@@ -591,42 +531,33 @@ describe('Test users', function () {
591 }) 531 })
592 532
593 it('Should be able to change the autoPlayVideo attribute', async function () { 533 it('Should be able to change the autoPlayVideo attribute', async function () {
594 await updateMyUser({ 534 await server.usersCommand.updateMe({
595 url: server.url, 535 token: accessTokenUser,
596 accessToken: accessTokenUser,
597 autoPlayVideo: false 536 autoPlayVideo: false
598 }) 537 })
599 538
600 const res = await getMyUserInformation(server.url, accessTokenUser) 539 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
601 const user = res.body
602
603 expect(user.autoPlayVideo).to.be.false 540 expect(user.autoPlayVideo).to.be.false
604 }) 541 })
605 542
606 it('Should be able to change the autoPlayNextVideo attribute', async function () { 543 it('Should be able to change the autoPlayNextVideo attribute', async function () {
607 await updateMyUser({ 544 await server.usersCommand.updateMe({
608 url: server.url, 545 token: accessTokenUser,
609 accessToken: accessTokenUser,
610 autoPlayNextVideo: true 546 autoPlayNextVideo: true
611 }) 547 })
612 548
613 const res = await getMyUserInformation(server.url, accessTokenUser) 549 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
614 const user = res.body
615
616 expect(user.autoPlayNextVideo).to.be.true 550 expect(user.autoPlayNextVideo).to.be.true
617 }) 551 })
618 552
619 it('Should be able to change the email attribute', async function () { 553 it('Should be able to change the email attribute', async function () {
620 await updateMyUser({ 554 await server.usersCommand.updateMe({
621 url: server.url, 555 token: accessTokenUser,
622 accessToken: accessTokenUser,
623 currentPassword: 'new password', 556 currentPassword: 'new password',
624 email: 'updated@example.com' 557 email: 'updated@example.com'
625 }) 558 })
626 559
627 const res = await getMyUserInformation(server.url, accessTokenUser) 560 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
628 const user = res.body
629
630 expect(user.username).to.equal('user_1') 561 expect(user.username).to.equal('user_1')
631 expect(user.email).to.equal('updated@example.com') 562 expect(user.email).to.equal('updated@example.com')
632 expect(user.nsfwPolicy).to.equal('do_not_list') 563 expect(user.nsfwPolicy).to.equal('do_not_list')
@@ -639,15 +570,9 @@ describe('Test users', function () {
639 it('Should be able to update my avatar with a gif', async function () { 570 it('Should be able to update my avatar with a gif', async function () {
640 const fixture = 'avatar.gif' 571 const fixture = 'avatar.gif'
641 572
642 await updateMyAvatar({ 573 await server.usersCommand.updateMyAvatar({ token: accessTokenUser, fixture })
643 url: server.url,
644 accessToken: accessTokenUser,
645 fixture
646 })
647
648 const res = await getMyUserInformation(server.url, accessTokenUser)
649 const user = res.body
650 574
575 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
651 await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif') 576 await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif')
652 }) 577 })
653 578
@@ -655,29 +580,17 @@ describe('Test users', function () {
655 for (const extension of [ '.png', '.gif' ]) { 580 for (const extension of [ '.png', '.gif' ]) {
656 const fixture = 'avatar' + extension 581 const fixture = 'avatar' + extension
657 582
658 await updateMyAvatar({ 583 await server.usersCommand.updateMyAvatar({ token: accessTokenUser, fixture })
659 url: server.url,
660 accessToken: accessTokenUser,
661 fixture
662 })
663
664 const res = await getMyUserInformation(server.url, accessTokenUser)
665 const user = res.body
666 584
585 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
667 await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension) 586 await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension)
668 } 587 }
669 }) 588 })
670 589
671 it('Should be able to update my display name', async function () { 590 it('Should be able to update my display name', async function () {
672 await updateMyUser({ 591 await server.usersCommand.updateMe({ token: accessTokenUser, displayName: 'new display name' })
673 url: server.url,
674 accessToken: accessTokenUser,
675 displayName: 'new display name'
676 })
677
678 const res = await getMyUserInformation(server.url, accessTokenUser)
679 const user = res.body
680 592
593 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
681 expect(user.username).to.equal('user_1') 594 expect(user.username).to.equal('user_1')
682 expect(user.email).to.equal('updated@example.com') 595 expect(user.email).to.equal('updated@example.com')
683 expect(user.nsfwPolicy).to.equal('do_not_list') 596 expect(user.nsfwPolicy).to.equal('do_not_list')
@@ -688,15 +601,9 @@ describe('Test users', function () {
688 }) 601 })
689 602
690 it('Should be able to update my description', async function () { 603 it('Should be able to update my description', async function () {
691 await updateMyUser({ 604 await server.usersCommand.updateMe({ token: accessTokenUser, description: 'my super description updated' })
692 url: server.url,
693 accessToken: accessTokenUser,
694 description: 'my super description updated'
695 })
696
697 const res = await getMyUserInformation(server.url, accessTokenUser)
698 const user: User = res.body
699 605
606 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
700 expect(user.username).to.equal('user_1') 607 expect(user.username).to.equal('user_1')
701 expect(user.email).to.equal('updated@example.com') 608 expect(user.email).to.equal('updated@example.com')
702 expect(user.nsfwPolicy).to.equal('do_not_list') 609 expect(user.nsfwPolicy).to.equal('do_not_list')
@@ -710,30 +617,21 @@ describe('Test users', function () {
710 617
711 it('Should be able to update my theme', async function () { 618 it('Should be able to update my theme', async function () {
712 for (const theme of [ 'background-red', 'default', 'instance-default' ]) { 619 for (const theme of [ 'background-red', 'default', 'instance-default' ]) {
713 await updateMyUser({ 620 await server.usersCommand.updateMe({ token: accessTokenUser, theme })
714 url: server.url,
715 accessToken: accessTokenUser,
716 theme
717 })
718 621
719 const res = await getMyUserInformation(server.url, accessTokenUser) 622 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
720 const body: User = res.body 623 expect(user.theme).to.equal(theme)
721
722 expect(body.theme).to.equal(theme)
723 } 624 }
724 }) 625 })
725 626
726 it('Should be able to update my modal preferences', async function () { 627 it('Should be able to update my modal preferences', async function () {
727 await updateMyUser({ 628 await server.usersCommand.updateMe({
728 url: server.url, 629 token: accessTokenUser,
729 accessToken: accessTokenUser,
730 noInstanceConfigWarningModal: true, 630 noInstanceConfigWarningModal: true,
731 noWelcomeModal: true 631 noWelcomeModal: true
732 }) 632 })
733 633
734 const res = await getMyUserInformation(server.url, accessTokenUser) 634 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser })
735 const user: User = res.body
736
737 expect(user.noWelcomeModal).to.be.true 635 expect(user.noWelcomeModal).to.be.true
738 expect(user.noInstanceConfigWarningModal).to.be.true 636 expect(user.noInstanceConfigWarningModal).to.be.true
739 }) 637 })
@@ -741,10 +639,9 @@ describe('Test users', function () {
741 639
742 describe('Updating another user', function () { 640 describe('Updating another user', function () {
743 it('Should be able to update another user', async function () { 641 it('Should be able to update another user', async function () {
744 await updateUser({ 642 await server.usersCommand.update({
745 url: server.url,
746 userId, 643 userId,
747 accessToken, 644 token: accessToken,
748 email: 'updated2@example.com', 645 email: 'updated2@example.com',
749 emailVerified: true, 646 emailVerified: true,
750 videoQuota: 42, 647 videoQuota: 42,
@@ -753,8 +650,7 @@ describe('Test users', function () {
753 pluginAuth: 'toto' 650 pluginAuth: 'toto'
754 }) 651 })
755 652
756 const res = await getUserInformation(server.url, accessToken, userId) 653 const user = await server.usersCommand.get({ token: accessToken, userId })
757 const user = res.body as User
758 654
759 expect(user.username).to.equal('user_1') 655 expect(user.username).to.equal('user_1')
760 expect(user.email).to.equal('updated2@example.com') 656 expect(user.email).to.equal('updated2@example.com')
@@ -768,28 +664,22 @@ describe('Test users', function () {
768 }) 664 })
769 665
770 it('Should reset the auth plugin', async function () { 666 it('Should reset the auth plugin', async function () {
771 await updateUser({ url: server.url, userId, accessToken, pluginAuth: null }) 667 await server.usersCommand.update({ userId, token: accessToken, pluginAuth: null })
772 668
773 const res = await getUserInformation(server.url, accessToken, userId) 669 const user = await server.usersCommand.get({ token: accessToken, userId })
774 const user = res.body as User
775 expect(user.pluginAuth).to.be.null 670 expect(user.pluginAuth).to.be.null
776 }) 671 })
777 672
778 it('Should have removed the user token', async function () { 673 it('Should have removed the user token', async function () {
779 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401) 674 await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
780 675
781 accessTokenUser = await server.loginCommand.getAccessToken(user) 676 accessTokenUser = await server.loginCommand.getAccessToken(user)
782 }) 677 })
783 678
784 it('Should be able to update another user password', async function () { 679 it('Should be able to update another user password', async function () {
785 await updateUser({ 680 await server.usersCommand.update({ userId, token: accessToken, password: 'password updated' })
786 url: server.url,
787 userId,
788 accessToken,
789 password: 'password updated'
790 })
791 681
792 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401) 682 await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
793 683
794 await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 684 await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
795 685
@@ -806,7 +696,7 @@ describe('Test users', function () {
806 696
807 describe('Remove a user', function () { 697 describe('Remove a user', function () {
808 it('Should be able to remove this user', async function () { 698 it('Should be able to remove this user', async function () {
809 await removeUser(server.url, userId, accessToken) 699 await server.usersCommand.remove({ userId, token: accessToken })
810 }) 700 })
811 701
812 it('Should not be able to login with this user', async function () { 702 it('Should not be able to login with this user', async function () {
@@ -830,7 +720,7 @@ describe('Test users', function () {
830 const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' } 720 const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' }
831 const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' } 721 const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' }
832 722
833 await registerUserWithChannel({ url: server.url, user, channel }) 723 await server.usersCommand.register({ ...user, channel })
834 }) 724 })
835 725
836 it('Should be able to login with this registered user', async function () { 726 it('Should be able to login with this registered user', async function () {
@@ -843,16 +733,12 @@ describe('Test users', function () {
843 }) 733 })
844 734
845 it('Should have the correct display name', async function () { 735 it('Should have the correct display name', async function () {
846 const res = await getMyUserInformation(server.url, user15AccessToken) 736 const user = await server.usersCommand.getMyInfo({ token: user15AccessToken })
847 const user: User = res.body
848
849 expect(user.account.displayName).to.equal('super user 15') 737 expect(user.account.displayName).to.equal('super user 15')
850 }) 738 })
851 739
852 it('Should have the correct video quota', async function () { 740 it('Should have the correct video quota', async function () {
853 const res = await getMyUserInformation(server.url, user15AccessToken) 741 const user = await server.usersCommand.getMyInfo({ token: user15AccessToken })
854 const user = res.body
855
856 expect(user.videoQuota).to.equal(5 * 1024 * 1024) 742 expect(user.videoQuota).to.equal(5 * 1024 * 1024)
857 }) 743 })
858 744
@@ -864,15 +750,15 @@ describe('Test users', function () {
864 750
865 it('Should remove me', async function () { 751 it('Should remove me', async function () {
866 { 752 {
867 const res = await getUsersList(server.url, server.accessToken) 753 const { data } = await server.usersCommand.list()
868 expect(res.body.data.find(u => u.username === 'user_15')).to.not.be.undefined 754 expect(data.find(u => u.username === 'user_15')).to.not.be.undefined
869 } 755 }
870 756
871 await deleteMe(server.url, user15AccessToken) 757 await server.usersCommand.deleteMe({ token: user15AccessToken })
872 758
873 { 759 {
874 const res = await getUsersList(server.url, server.accessToken) 760 const { data } = await server.usersCommand.list()
875 expect(res.body.data.find(u => u.username === 'user_15')).to.be.undefined 761 expect(data.find(u => u.username === 'user_15')).to.be.undefined
876 } 762 }
877 }) 763 })
878 }) 764 })
@@ -886,49 +772,40 @@ describe('Test users', function () {
886 } 772 }
887 773
888 it('Should block a user', async function () { 774 it('Should block a user', async function () {
889 const resUser = await createUser({ 775 const user = await server.usersCommand.create({ ...user16 })
890 url: server.url, 776 user16Id = user.id
891 accessToken: server.accessToken,
892 username: user16.username,
893 password: user16.password
894 })
895 user16Id = resUser.body.user.id
896 777
897 user16AccessToken = await server.loginCommand.getAccessToken(user16) 778 user16AccessToken = await server.loginCommand.getAccessToken(user16)
898 779
899 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200) 780 await server.usersCommand.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 })
900 await blockUser(server.url, user16Id, server.accessToken) 781 await server.usersCommand.banUser({ userId: user16Id })
901 782
902 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.UNAUTHORIZED_401) 783 await server.usersCommand.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
903 await server.loginCommand.login({ user: user16, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 784 await server.loginCommand.login({ user: user16, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
904 }) 785 })
905 786
906 it('Should search user by banned status', async function () { 787 it('Should search user by banned status', async function () {
907 { 788 {
908 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', undefined, true) 789 const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', blocked: true })
909 const users = res.body.data as User[] 790 expect(total).to.equal(1)
791 expect(data.length).to.equal(1)
910 792
911 expect(res.body.total).to.equal(1) 793 expect(data[0].username).to.equal(user16.username)
912 expect(users.length).to.equal(1)
913
914 expect(users[0].username).to.equal(user16.username)
915 } 794 }
916 795
917 { 796 {
918 const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', undefined, false) 797 const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', blocked: false })
919 const users = res.body.data as User[] 798 expect(total).to.equal(1)
920 799 expect(data.length).to.equal(1)
921 expect(res.body.total).to.equal(1)
922 expect(users.length).to.equal(1)
923 800
924 expect(users[0].username).to.not.equal(user16.username) 801 expect(data[0].username).to.not.equal(user16.username)
925 } 802 }
926 }) 803 })
927 804
928 it('Should unblock a user', async function () { 805 it('Should unblock a user', async function () {
929 await unblockUser(server.url, user16Id, server.accessToken) 806 await server.usersCommand.unbanUser({ userId: user16Id })
930 user16AccessToken = await server.loginCommand.getAccessToken(user16) 807 user16AccessToken = await server.loginCommand.getAccessToken(user16)
931 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200) 808 await server.usersCommand.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 })
932 }) 809 })
933 }) 810 })
934 811
@@ -941,19 +818,12 @@ describe('Test users', function () {
941 username: 'user_17', 818 username: 'user_17',
942 password: 'my super password' 819 password: 'my super password'
943 } 820 }
944 const resUser = await createUser({ 821 const created = await server.usersCommand.create({ ...user17 })
945 url: server.url,
946 accessToken: server.accessToken,
947 username: user17.username,
948 password: user17.password
949 })
950 822
951 user17Id = resUser.body.user.id 823 user17Id = created.id
952 user17AccessToken = await server.loginCommand.getAccessToken(user17) 824 user17AccessToken = await server.loginCommand.getAccessToken(user17)
953 825
954 const res = await getUserInformation(server.url, server.accessToken, user17Id, true) 826 const user = await server.usersCommand.get({ userId: user17Id, withStats: true })
955 const user: User = res.body
956
957 expect(user.videosCount).to.equal(0) 827 expect(user.videosCount).to.equal(0)
958 expect(user.videoCommentsCount).to.equal(0) 828 expect(user.videoCommentsCount).to.equal(0)
959 expect(user.abusesCount).to.equal(0) 829 expect(user.abusesCount).to.equal(0)
@@ -969,9 +839,7 @@ describe('Test users', function () {
969 const res1 = await getVideosList(server.url) 839 const res1 = await getVideosList(server.url)
970 videoId = res1.body.data.find(video => video.name === videoAttributes.name).id 840 videoId = res1.body.data.find(video => video.name === videoAttributes.name).id
971 841
972 const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true) 842 const user = await server.usersCommand.get({ userId: user17Id, withStats: true })
973 const user: User = res2.body
974
975 expect(user.videosCount).to.equal(1) 843 expect(user.videosCount).to.equal(1)
976 }) 844 })
977 845
@@ -979,9 +847,7 @@ describe('Test users', function () {
979 const text = 'super comment' 847 const text = 'super comment'
980 await server.commentsCommand.createThread({ token: user17AccessToken, videoId, text }) 848 await server.commentsCommand.createThread({ token: user17AccessToken, videoId, text })
981 849
982 const res = await getUserInformation(server.url, server.accessToken, user17Id, true) 850 const user = await server.usersCommand.get({ userId: user17Id, withStats: true })
983 const user: User = res.body
984
985 expect(user.videoCommentsCount).to.equal(1) 851 expect(user.videoCommentsCount).to.equal(1)
986 }) 852 })
987 853
@@ -992,17 +858,13 @@ describe('Test users', function () {
992 const body1 = await server.abusesCommand.getAdminList() 858 const body1 = await server.abusesCommand.getAdminList()
993 const abuseId = body1.data[0].id 859 const abuseId = body1.data[0].id
994 860
995 const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true) 861 const user2 = await server.usersCommand.get({ userId: user17Id, withStats: true })
996 const user2: User = res2.body
997
998 expect(user2.abusesCount).to.equal(1) // number of incriminations 862 expect(user2.abusesCount).to.equal(1) // number of incriminations
999 expect(user2.abusesCreatedCount).to.equal(1) // number of reports created 863 expect(user2.abusesCreatedCount).to.equal(1) // number of reports created
1000 864
1001 await server.abusesCommand.update({ abuseId, body: { state: AbuseState.ACCEPTED } }) 865 await server.abusesCommand.update({ abuseId, body: { state: AbuseState.ACCEPTED } })
1002 866
1003 const res3 = await getUserInformation(server.url, server.accessToken, user17Id, true) 867 const user3 = await server.usersCommand.get({ userId: user17Id, withStats: true })
1004 const user3: User = res3.body
1005
1006 expect(user3.abusesAcceptedCount).to.equal(1) // number of reports created accepted 868 expect(user3.abusesAcceptedCount).to.equal(1) // number of reports created accepted
1007 }) 869 })
1008 }) 870 })