aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/users/users.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/users/users.ts')
-rw-r--r--server/tests/api/users/users.ts166
1 files changed, 75 insertions, 91 deletions
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts
index 30d7e850d..6f3873939 100644
--- a/server/tests/api/users/users.ts
+++ b/server/tests/api/users/users.ts
@@ -6,17 +6,12 @@ import { HttpStatusCode } from '@shared/core-utils'
6import { 6import {
7 cleanupTests, 7 cleanupTests,
8 flushAndRunServer, 8 flushAndRunServer,
9 getMyVideos,
10 getVideosList,
11 killallServers, 9 killallServers,
12 makePutBodyRequest, 10 makePutBodyRequest,
13 rateVideo,
14 removeVideo,
15 reRunServer, 11 reRunServer,
16 ServerInfo, 12 ServerInfo,
17 setAccessTokensToServers, 13 setAccessTokensToServers,
18 testImage, 14 testImage,
19 uploadVideo,
20 waitJobs 15 waitJobs
21} from '@shared/extra-utils' 16} from '@shared/extra-utils'
22import { AbuseState, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models' 17import { AbuseState, OAuth2ErrorCode, UserAdminFlag, UserRole, Video, VideoPlaylistType } from '@shared/models'
@@ -25,8 +20,8 @@ const expect = chai.expect
25 20
26describe('Test users', function () { 21describe('Test users', function () {
27 let server: ServerInfo 22 let server: ServerInfo
28 let accessToken: string 23 let token: string
29 let accessTokenUser: string 24 let userToken: string
30 let videoId: number 25 let videoId: number
31 let userId: number 26 let userId: number
32 const user = { 27 const user = {
@@ -101,18 +96,17 @@ describe('Test users', function () {
101 }) 96 })
102 97
103 it('Should not be able to upload a video', async function () { 98 it('Should not be able to upload a video', async function () {
104 accessToken = 'my_super_token' 99 token = 'my_super_token'
105 100
106 const videoAttributes = {} 101 await server.videosCommand.upload({ token, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
107 await uploadVideo(server.url, accessToken, videoAttributes, HttpStatusCode.UNAUTHORIZED_401)
108 }) 102 })
109 103
110 it('Should not be able to follow', async function () { 104 it('Should not be able to follow', async function () {
111 accessToken = 'my_super_token' 105 token = 'my_super_token'
112 106
113 await server.followsCommand.follow({ 107 await server.followsCommand.follow({
114 targets: [ 'http://example.com' ], 108 targets: [ 'http://example.com' ],
115 token: accessToken, 109 token,
116 expectedStatus: HttpStatusCode.UNAUTHORIZED_401 110 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
117 }) 111 })
118 }) 112 })
@@ -122,7 +116,7 @@ describe('Test users', function () {
122 it('Should be able to login', async function () { 116 it('Should be able to login', async function () {
123 const body = await server.loginCommand.login({ expectedStatus: HttpStatusCode.OK_200 }) 117 const body = await server.loginCommand.login({ expectedStatus: HttpStatusCode.OK_200 })
124 118
125 accessToken = body.access_token 119 token = body.access_token
126 }) 120 })
127 121
128 it('Should be able to login with an insensitive username', async function () { 122 it('Should be able to login with an insensitive username', async function () {
@@ -140,33 +134,31 @@ describe('Test users', function () {
140 describe('Upload', function () { 134 describe('Upload', function () {
141 135
142 it('Should upload the video with the correct token', async function () { 136 it('Should upload the video with the correct token', async function () {
143 const videoAttributes = {} 137 await server.videosCommand.upload({ token })
144 await uploadVideo(server.url, accessToken, videoAttributes) 138 const { data } = await server.videosCommand.list()
145 const res = await getVideosList(server.url) 139 const video = data[0]
146 const video = res.body.data[0]
147 140
148 expect(video.account.name).to.equal('root') 141 expect(video.account.name).to.equal('root')
149 videoId = video.id 142 videoId = video.id
150 }) 143 })
151 144
152 it('Should upload the video again with the correct token', async function () { 145 it('Should upload the video again with the correct token', async function () {
153 const videoAttributes = {} 146 await server.videosCommand.upload({ token })
154 await uploadVideo(server.url, accessToken, videoAttributes)
155 }) 147 })
156 }) 148 })
157 149
158 describe('Ratings', function () { 150 describe('Ratings', function () {
159 151
160 it('Should retrieve a video rating', async function () { 152 it('Should retrieve a video rating', async function () {
161 await rateVideo(server.url, accessToken, videoId, 'like') 153 await server.videosCommand.rate({ id: videoId, rating: 'like' })
162 const rating = await server.usersCommand.getMyRating({ token: accessToken, videoId }) 154 const rating = await server.usersCommand.getMyRating({ token, videoId })
163 155
164 expect(rating.videoId).to.equal(videoId) 156 expect(rating.videoId).to.equal(videoId)
165 expect(rating.rating).to.equal('like') 157 expect(rating.rating).to.equal('like')
166 }) 158 })
167 159
168 it('Should retrieve ratings list', async function () { 160 it('Should retrieve ratings list', async function () {
169 await rateVideo(server.url, accessToken, videoId, 'like') 161 await server.videosCommand.rate({ id: videoId, rating: 'like' })
170 162
171 const body = await server.accountsCommand.listRatings({ accountName: server.user.username }) 163 const body = await server.accountsCommand.listRatings({ accountName: server.user.username })
172 164
@@ -190,13 +182,13 @@ describe('Test users', function () {
190 182
191 describe('Remove video', function () { 183 describe('Remove video', function () {
192 it('Should not be able to remove the video with an incorrect token', async function () { 184 it('Should not be able to remove the video with an incorrect token', async function () {
193 await removeVideo(server.url, 'bad_token', videoId, HttpStatusCode.UNAUTHORIZED_401) 185 await server.videosCommand.remove({ token: 'bad_token', id: videoId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
194 }) 186 })
195 187
196 it('Should not be able to remove the video with the token of another account') 188 it('Should not be able to remove the video with the token of another account')
197 189
198 it('Should be able to remove the video with the correct token', async function () { 190 it('Should be able to remove the video with the correct token', async function () {
199 await removeVideo(server.url, accessToken, videoId) 191 await server.videosCommand.remove({ token, id: videoId })
200 }) 192 })
201 }) 193 })
202 194
@@ -210,7 +202,7 @@ describe('Test users', function () {
210 }) 202 })
211 203
212 it('Should not be able to upload a video', async function () { 204 it('Should not be able to upload a video', async function () {
213 await uploadVideo(server.url, server.accessToken, { name: 'video' }, HttpStatusCode.UNAUTHORIZED_401) 205 await server.videosCommand.upload({ attributes: { name: 'video' }, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
214 }) 206 })
215 207
216 it('Should not be able to rate a video', async function () { 208 it('Should not be able to rate a video', async function () {
@@ -281,11 +273,11 @@ describe('Test users', function () {
281 }) 273 })
282 274
283 it('Should be able to login with this user', async function () { 275 it('Should be able to login with this user', async function () {
284 accessTokenUser = await server.loginCommand.getAccessToken(user) 276 userToken = await server.loginCommand.getAccessToken(user)
285 }) 277 })
286 278
287 it('Should be able to get user information', async function () { 279 it('Should be able to get user information', async function () {
288 const userMe = await server.usersCommand.getMyInfo({ token: accessTokenUser }) 280 const userMe = await server.usersCommand.getMyInfo({ token: userToken })
289 281
290 const userGet = await server.usersCommand.get({ userId: userMe.id, withStats: true }) 282 const userGet = await server.usersCommand.get({ userId: userMe.id, withStats: true })
291 283
@@ -323,15 +315,15 @@ describe('Test users', function () {
323 it('Should be able to upload a video with this user', async function () { 315 it('Should be able to upload a video with this user', async function () {
324 this.timeout(10000) 316 this.timeout(10000)
325 317
326 const videoAttributes = { 318 const attributes = {
327 name: 'super user video', 319 name: 'super user video',
328 fixture: 'video_short.webm' 320 fixture: 'video_short.webm'
329 } 321 }
330 await uploadVideo(server.url, accessTokenUser, videoAttributes) 322 await server.videosCommand.upload({ token: userToken, attributes })
331 }) 323 })
332 324
333 it('Should have video quota updated', async function () { 325 it('Should have video quota updated', async function () {
334 const quota = await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser }) 326 const quota = await server.usersCommand.getMyQuotaUsed({ token: userToken })
335 expect(quota.videoQuotaUsed).to.equal(218910) 327 expect(quota.videoQuotaUsed).to.equal(218910)
336 328
337 const { data } = await server.usersCommand.list() 329 const { data } = await server.usersCommand.list()
@@ -340,13 +332,11 @@ describe('Test users', function () {
340 }) 332 })
341 333
342 it('Should be able to list my videos', async function () { 334 it('Should be able to list my videos', async function () {
343 const res = await getMyVideos(server.url, accessTokenUser, 0, 5) 335 const { total, data } = await server.videosCommand.listMyVideos({ token: userToken })
344 expect(res.body.total).to.equal(1) 336 expect(total).to.equal(1)
345 337 expect(data).to.have.lengthOf(1)
346 const videos = res.body.data
347 expect(videos).to.have.lengthOf(1)
348 338
349 const video: Video = videos[0] 339 const video: Video = data[0]
350 expect(video.name).to.equal('super user video') 340 expect(video.name).to.equal('super user video')
351 expect(video.thumbnailPath).to.not.be.null 341 expect(video.thumbnailPath).to.not.be.null
352 expect(video.previewPath).to.not.be.null 342 expect(video.previewPath).to.not.be.null
@@ -354,19 +344,15 @@ describe('Test users', function () {
354 344
355 it('Should be able to search in my videos', async function () { 345 it('Should be able to search in my videos', async function () {
356 { 346 {
357 const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'user video') 347 const { total, data } = await server.videosCommand.listMyVideos({ token: userToken, sort: '-createdAt', search: 'user video' })
358 expect(res.body.total).to.equal(1) 348 expect(total).to.equal(1)
359 349 expect(data).to.have.lengthOf(1)
360 const videos = res.body.data
361 expect(videos).to.have.lengthOf(1)
362 } 350 }
363 351
364 { 352 {
365 const res = await getMyVideos(server.url, accessTokenUser, 0, 5, '-createdAt', 'toto') 353 const { total, data } = await server.videosCommand.listMyVideos({ token: userToken, sort: '-createdAt', search: 'toto' })
366 expect(res.body.total).to.equal(0) 354 expect(total).to.equal(0)
367 355 expect(data).to.have.lengthOf(0)
368 const videos = res.body.data
369 expect(videos).to.have.lengthOf(0)
370 } 356 }
371 }) 357 })
372 358
@@ -382,17 +368,17 @@ describe('Test users', function () {
382 } 368 }
383 369
384 { 370 {
385 const videoAttributes = { 371 const attributes = {
386 name: 'super user video 2', 372 name: 'super user video 2',
387 fixture: 'video_short.webm' 373 fixture: 'video_short.webm'
388 } 374 }
389 await uploadVideo(server.url, accessTokenUser, videoAttributes) 375 await server.videosCommand.upload({ token: userToken, attributes })
390 376
391 await waitJobs([ server ]) 377 await waitJobs([ server ])
392 } 378 }
393 379
394 { 380 {
395 const data = await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser }) 381 const data = await server.usersCommand.getMyQuotaUsed({ token: userToken })
396 expect(data.videoQuotaUsed).to.be.greaterThan(220000) 382 expect(data.videoQuotaUsed).to.be.greaterThan(220000)
397 } 383 }
398 }) 384 })
@@ -505,7 +491,7 @@ describe('Test users', function () {
505 491
506 it('Should update my password', async function () { 492 it('Should update my password', async function () {
507 await server.usersCommand.updateMe({ 493 await server.usersCommand.updateMe({
508 token: accessTokenUser, 494 token: userToken,
509 currentPassword: 'super password', 495 currentPassword: 'super password',
510 password: 'new password' 496 password: 'new password'
511 }) 497 })
@@ -516,11 +502,11 @@ describe('Test users', function () {
516 502
517 it('Should be able to change the NSFW display attribute', async function () { 503 it('Should be able to change the NSFW display attribute', async function () {
518 await server.usersCommand.updateMe({ 504 await server.usersCommand.updateMe({
519 token: accessTokenUser, 505 token: userToken,
520 nsfwPolicy: 'do_not_list' 506 nsfwPolicy: 'do_not_list'
521 }) 507 })
522 508
523 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) 509 const user = await server.usersCommand.getMyInfo({ token: userToken })
524 expect(user.username).to.equal('user_1') 510 expect(user.username).to.equal('user_1')
525 expect(user.email).to.equal('user_1@example.com') 511 expect(user.email).to.equal('user_1@example.com')
526 expect(user.nsfwPolicy).to.equal('do_not_list') 512 expect(user.nsfwPolicy).to.equal('do_not_list')
@@ -532,32 +518,32 @@ describe('Test users', function () {
532 518
533 it('Should be able to change the autoPlayVideo attribute', async function () { 519 it('Should be able to change the autoPlayVideo attribute', async function () {
534 await server.usersCommand.updateMe({ 520 await server.usersCommand.updateMe({
535 token: accessTokenUser, 521 token: userToken,
536 autoPlayVideo: false 522 autoPlayVideo: false
537 }) 523 })
538 524
539 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) 525 const user = await server.usersCommand.getMyInfo({ token: userToken })
540 expect(user.autoPlayVideo).to.be.false 526 expect(user.autoPlayVideo).to.be.false
541 }) 527 })
542 528
543 it('Should be able to change the autoPlayNextVideo attribute', async function () { 529 it('Should be able to change the autoPlayNextVideo attribute', async function () {
544 await server.usersCommand.updateMe({ 530 await server.usersCommand.updateMe({
545 token: accessTokenUser, 531 token: userToken,
546 autoPlayNextVideo: true 532 autoPlayNextVideo: true
547 }) 533 })
548 534
549 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) 535 const user = await server.usersCommand.getMyInfo({ token: userToken })
550 expect(user.autoPlayNextVideo).to.be.true 536 expect(user.autoPlayNextVideo).to.be.true
551 }) 537 })
552 538
553 it('Should be able to change the email attribute', async function () { 539 it('Should be able to change the email attribute', async function () {
554 await server.usersCommand.updateMe({ 540 await server.usersCommand.updateMe({
555 token: accessTokenUser, 541 token: userToken,
556 currentPassword: 'new password', 542 currentPassword: 'new password',
557 email: 'updated@example.com' 543 email: 'updated@example.com'
558 }) 544 })
559 545
560 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) 546 const user = await server.usersCommand.getMyInfo({ token: userToken })
561 expect(user.username).to.equal('user_1') 547 expect(user.username).to.equal('user_1')
562 expect(user.email).to.equal('updated@example.com') 548 expect(user.email).to.equal('updated@example.com')
563 expect(user.nsfwPolicy).to.equal('do_not_list') 549 expect(user.nsfwPolicy).to.equal('do_not_list')
@@ -570,9 +556,9 @@ describe('Test users', function () {
570 it('Should be able to update my avatar with a gif', async function () { 556 it('Should be able to update my avatar with a gif', async function () {
571 const fixture = 'avatar.gif' 557 const fixture = 'avatar.gif'
572 558
573 await server.usersCommand.updateMyAvatar({ token: accessTokenUser, fixture }) 559 await server.usersCommand.updateMyAvatar({ token: userToken, fixture })
574 560
575 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) 561 const user = await server.usersCommand.getMyInfo({ token: userToken })
576 await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif') 562 await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif')
577 }) 563 })
578 564
@@ -580,17 +566,17 @@ describe('Test users', function () {
580 for (const extension of [ '.png', '.gif' ]) { 566 for (const extension of [ '.png', '.gif' ]) {
581 const fixture = 'avatar' + extension 567 const fixture = 'avatar' + extension
582 568
583 await server.usersCommand.updateMyAvatar({ token: accessTokenUser, fixture }) 569 await server.usersCommand.updateMyAvatar({ token: userToken, fixture })
584 570
585 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) 571 const user = await server.usersCommand.getMyInfo({ token: userToken })
586 await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension) 572 await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension)
587 } 573 }
588 }) 574 })
589 575
590 it('Should be able to update my display name', async function () { 576 it('Should be able to update my display name', async function () {
591 await server.usersCommand.updateMe({ token: accessTokenUser, displayName: 'new display name' }) 577 await server.usersCommand.updateMe({ token: userToken, displayName: 'new display name' })
592 578
593 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) 579 const user = await server.usersCommand.getMyInfo({ token: userToken })
594 expect(user.username).to.equal('user_1') 580 expect(user.username).to.equal('user_1')
595 expect(user.email).to.equal('updated@example.com') 581 expect(user.email).to.equal('updated@example.com')
596 expect(user.nsfwPolicy).to.equal('do_not_list') 582 expect(user.nsfwPolicy).to.equal('do_not_list')
@@ -601,9 +587,9 @@ describe('Test users', function () {
601 }) 587 })
602 588
603 it('Should be able to update my description', async function () { 589 it('Should be able to update my description', async function () {
604 await server.usersCommand.updateMe({ token: accessTokenUser, description: 'my super description updated' }) 590 await server.usersCommand.updateMe({ token: userToken, description: 'my super description updated' })
605 591
606 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) 592 const user = await server.usersCommand.getMyInfo({ token: userToken })
607 expect(user.username).to.equal('user_1') 593 expect(user.username).to.equal('user_1')
608 expect(user.email).to.equal('updated@example.com') 594 expect(user.email).to.equal('updated@example.com')
609 expect(user.nsfwPolicy).to.equal('do_not_list') 595 expect(user.nsfwPolicy).to.equal('do_not_list')
@@ -617,21 +603,21 @@ describe('Test users', function () {
617 603
618 it('Should be able to update my theme', async function () { 604 it('Should be able to update my theme', async function () {
619 for (const theme of [ 'background-red', 'default', 'instance-default' ]) { 605 for (const theme of [ 'background-red', 'default', 'instance-default' ]) {
620 await server.usersCommand.updateMe({ token: accessTokenUser, theme }) 606 await server.usersCommand.updateMe({ token: userToken, theme })
621 607
622 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) 608 const user = await server.usersCommand.getMyInfo({ token: userToken })
623 expect(user.theme).to.equal(theme) 609 expect(user.theme).to.equal(theme)
624 } 610 }
625 }) 611 })
626 612
627 it('Should be able to update my modal preferences', async function () { 613 it('Should be able to update my modal preferences', async function () {
628 await server.usersCommand.updateMe({ 614 await server.usersCommand.updateMe({
629 token: accessTokenUser, 615 token: userToken,
630 noInstanceConfigWarningModal: true, 616 noInstanceConfigWarningModal: true,
631 noWelcomeModal: true 617 noWelcomeModal: true
632 }) 618 })
633 619
634 const user = await server.usersCommand.getMyInfo({ token: accessTokenUser }) 620 const user = await server.usersCommand.getMyInfo({ token: userToken })
635 expect(user.noWelcomeModal).to.be.true 621 expect(user.noWelcomeModal).to.be.true
636 expect(user.noInstanceConfigWarningModal).to.be.true 622 expect(user.noInstanceConfigWarningModal).to.be.true
637 }) 623 })
@@ -641,7 +627,7 @@ describe('Test users', function () {
641 it('Should be able to update another user', async function () { 627 it('Should be able to update another user', async function () {
642 await server.usersCommand.update({ 628 await server.usersCommand.update({
643 userId, 629 userId,
644 token: accessToken, 630 token,
645 email: 'updated2@example.com', 631 email: 'updated2@example.com',
646 emailVerified: true, 632 emailVerified: true,
647 videoQuota: 42, 633 videoQuota: 42,
@@ -650,7 +636,7 @@ describe('Test users', function () {
650 pluginAuth: 'toto' 636 pluginAuth: 'toto'
651 }) 637 })
652 638
653 const user = await server.usersCommand.get({ token: accessToken, userId }) 639 const user = await server.usersCommand.get({ token, userId })
654 640
655 expect(user.username).to.equal('user_1') 641 expect(user.username).to.equal('user_1')
656 expect(user.email).to.equal('updated2@example.com') 642 expect(user.email).to.equal('updated2@example.com')
@@ -664,39 +650,39 @@ describe('Test users', function () {
664 }) 650 })
665 651
666 it('Should reset the auth plugin', async function () { 652 it('Should reset the auth plugin', async function () {
667 await server.usersCommand.update({ userId, token: accessToken, pluginAuth: null }) 653 await server.usersCommand.update({ userId, token, pluginAuth: null })
668 654
669 const user = await server.usersCommand.get({ token: accessToken, userId }) 655 const user = await server.usersCommand.get({ token, userId })
670 expect(user.pluginAuth).to.be.null 656 expect(user.pluginAuth).to.be.null
671 }) 657 })
672 658
673 it('Should have removed the user token', async function () { 659 it('Should have removed the user token', async function () {
674 await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) 660 await server.usersCommand.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
675 661
676 accessTokenUser = await server.loginCommand.getAccessToken(user) 662 userToken = await server.loginCommand.getAccessToken(user)
677 }) 663 })
678 664
679 it('Should be able to update another user password', async function () { 665 it('Should be able to update another user password', async function () {
680 await server.usersCommand.update({ userId, token: accessToken, password: 'password updated' }) 666 await server.usersCommand.update({ userId, token, password: 'password updated' })
681 667
682 await server.usersCommand.getMyQuotaUsed({ token: accessTokenUser, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) 668 await server.usersCommand.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
683 669
684 await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 670 await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
685 671
686 user.password = 'password updated' 672 user.password = 'password updated'
687 accessTokenUser = await server.loginCommand.getAccessToken(user) 673 userToken = await server.loginCommand.getAccessToken(user)
688 }) 674 })
689 }) 675 })
690 676
691 describe('Video blacklists', function () { 677 describe('Video blacklists', function () {
692 it('Should be able to list video blacklist by a moderator', async function () { 678 it('Should be able to list video blacklist by a moderator', async function () {
693 await server.blacklistCommand.list({ token: accessTokenUser }) 679 await server.blacklistCommand.list({ token: userToken })
694 }) 680 })
695 }) 681 })
696 682
697 describe('Remove a user', function () { 683 describe('Remove a user', function () {
698 it('Should be able to remove this user', async function () { 684 it('Should be able to remove this user', async function () {
699 await server.usersCommand.remove({ userId, token: accessToken }) 685 await server.usersCommand.remove({ userId, token })
700 }) 686 })
701 687
702 it('Should not be able to login with this user', async function () { 688 it('Should not be able to login with this user', async function () {
@@ -704,11 +690,10 @@ describe('Test users', function () {
704 }) 690 })
705 691
706 it('Should not have videos of this user', async function () { 692 it('Should not have videos of this user', async function () {
707 const res = await getVideosList(server.url) 693 const { data, total } = await server.videosCommand.list()
708 694 expect(total).to.equal(1)
709 expect(res.body.total).to.equal(1)
710 695
711 const video = res.body.data[0] 696 const video = data[0]
712 expect(video.account.name).to.equal('root') 697 expect(video.account.name).to.equal('root')
713 }) 698 })
714 }) 699 })
@@ -832,12 +817,11 @@ describe('Test users', function () {
832 }) 817 })
833 818
834 it('Should report correct videos count', async function () { 819 it('Should report correct videos count', async function () {
835 const videoAttributes = { 820 const attributes = { name: 'video to test user stats' }
836 name: 'video to test user stats' 821 await server.videosCommand.upload({ token: user17AccessToken, attributes })
837 } 822
838 await uploadVideo(server.url, user17AccessToken, videoAttributes) 823 const { data } = await server.videosCommand.list()
839 const res1 = await getVideosList(server.url) 824 videoId = data.find(video => video.name === attributes.name).id
840 videoId = res1.body.data.find(video => video.name === videoAttributes.name).id
841 825
842 const user = await server.usersCommand.get({ userId: user17Id, withStats: true }) 826 const user = await server.usersCommand.get({ userId: user17Id, withStats: true })
843 expect(user.videosCount).to.equal(1) 827 expect(user.videosCount).to.equal(1)