diff options
Diffstat (limited to 'server/tests/api/users/users.ts')
-rw-r--r-- | server/tests/api/users/users.ts | 247 |
1 files changed, 197 insertions, 50 deletions
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 24203a731..c0cbce360 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts | |||
@@ -1,9 +1,10 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
2 | 2 | ||
3 | import * as chai from 'chai' | 3 | import * as chai from 'chai' |
4 | import 'mocha' | 4 | import 'mocha' |
5 | import { User, UserRole, Video, MyUser, VideoPlaylistType } from '../../../../shared/index' | 5 | import { MyUser, User, UserRole, Video, VideoAbuseState, VideoAbuseUpdate, VideoPlaylistType } from '../../../../shared/index' |
6 | import { | 6 | import { |
7 | addVideoCommentThread, | ||
7 | blockUser, | 8 | blockUser, |
8 | cleanupTests, | 9 | cleanupTests, |
9 | createUser, | 10 | createUser, |
@@ -11,33 +12,41 @@ import { | |||
11 | flushAndRunServer, | 12 | flushAndRunServer, |
12 | getAccountRatings, | 13 | getAccountRatings, |
13 | getBlacklistedVideosList, | 14 | getBlacklistedVideosList, |
15 | getCustomConfig, | ||
14 | getMyUserInformation, | 16 | getMyUserInformation, |
15 | getMyUserVideoQuotaUsed, | 17 | getMyUserVideoQuotaUsed, |
16 | getMyUserVideoRating, | 18 | getMyUserVideoRating, |
17 | getUserInformation, | 19 | getUserInformation, |
18 | getUsersList, | 20 | getUsersList, |
19 | getUsersListPaginationAndSort, | 21 | getUsersListPaginationAndSort, |
22 | getVideoAbusesList, | ||
20 | getVideoChannel, | 23 | getVideoChannel, |
21 | getVideosList, installPlugin, | 24 | getVideosList, |
25 | installPlugin, | ||
22 | login, | 26 | login, |
23 | makePutBodyRequest, | 27 | makePutBodyRequest, |
24 | rateVideo, | 28 | rateVideo, |
25 | registerUserWithChannel, | 29 | registerUserWithChannel, |
26 | removeUser, | 30 | removeUser, |
27 | removeVideo, | 31 | removeVideo, |
32 | reportVideoAbuse, | ||
28 | ServerInfo, | 33 | ServerInfo, |
29 | testImage, | 34 | testImage, |
30 | unblockUser, | 35 | unblockUser, |
36 | updateCustomSubConfig, | ||
31 | updateMyAvatar, | 37 | updateMyAvatar, |
32 | updateMyUser, | 38 | updateMyUser, |
33 | updateUser, | 39 | updateUser, |
40 | updateVideoAbuse, | ||
34 | uploadVideo, | 41 | uploadVideo, |
35 | userLogin | 42 | userLogin, |
43 | waitJobs | ||
36 | } from '../../../../shared/extra-utils' | 44 | } from '../../../../shared/extra-utils' |
37 | import { follow } from '../../../../shared/extra-utils/server/follows' | 45 | import { follow } from '../../../../shared/extra-utils/server/follows' |
38 | import { setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' | 46 | import { logout, serverLogin, setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' |
39 | import { getMyVideos } from '../../../../shared/extra-utils/videos/videos' | 47 | import { getMyVideos } from '../../../../shared/extra-utils/videos/videos' |
40 | import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' | 48 | import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' |
49 | import { CustomConfig } from '@shared/models/server' | ||
41 | 50 | ||
42 | const expect = chai.expect | 51 | const expect = chai.expect |
43 | 52 | ||
@@ -54,7 +63,14 @@ describe('Test users', function () { | |||
54 | 63 | ||
55 | before(async function () { | 64 | before(async function () { |
56 | this.timeout(30000) | 65 | this.timeout(30000) |
57 | server = await flushAndRunServer(1) | 66 | |
67 | server = await flushAndRunServer(1, { | ||
68 | rates_limit: { | ||
69 | login: { | ||
70 | max: 30 | ||
71 | } | ||
72 | } | ||
73 | }) | ||
58 | 74 | ||
59 | await setAccessTokensToServers([ server ]) | 75 | await setAccessTokensToServers([ server ]) |
60 | 76 | ||
@@ -121,13 +137,13 @@ describe('Test users', function () { | |||
121 | 137 | ||
122 | it('Should be able to login with an insensitive username', async function () { | 138 | it('Should be able to login with an insensitive username', async function () { |
123 | const user = { username: 'RoOt', password: server.user.password } | 139 | const user = { username: 'RoOt', password: server.user.password } |
124 | const res = await login(server.url, server.client, user, 200) | 140 | await login(server.url, server.client, user, 200) |
125 | 141 | ||
126 | const user2 = { username: 'rOoT', password: server.user.password } | 142 | const user2 = { username: 'rOoT', password: server.user.password } |
127 | const res2 = await login(server.url, server.client, user2, 200) | 143 | await login(server.url, server.client, user2, 200) |
128 | 144 | ||
129 | const user3 = { username: 'ROOt', password: server.user.password } | 145 | const user3 = { username: 'ROOt', password: server.user.password } |
130 | const res3 = await login(server.url, server.client, user3, 200) | 146 | await login(server.url, server.client, user3, 200) |
131 | }) | 147 | }) |
132 | }) | 148 | }) |
133 | 149 | ||
@@ -137,7 +153,7 @@ describe('Test users', function () { | |||
137 | const videoAttributes = {} | 153 | const videoAttributes = {} |
138 | await uploadVideo(server.url, accessToken, videoAttributes) | 154 | await uploadVideo(server.url, accessToken, videoAttributes) |
139 | const res = await getVideosList(server.url) | 155 | const res = await getVideosList(server.url) |
140 | const video = res.body.data[ 0 ] | 156 | const video = res.body.data[0] |
141 | 157 | ||
142 | expect(video.account.name).to.equal('root') | 158 | expect(video.account.name).to.equal('root') |
143 | videoId = video.id | 159 | videoId = video.id |
@@ -167,8 +183,8 @@ describe('Test users', function () { | |||
167 | const ratings = res.body | 183 | const ratings = res.body |
168 | 184 | ||
169 | expect(ratings.total).to.equal(1) | 185 | expect(ratings.total).to.equal(1) |
170 | expect(ratings.data[ 0 ].video.id).to.equal(videoId) | 186 | expect(ratings.data[0].video.id).to.equal(videoId) |
171 | expect(ratings.data[ 0 ].rating).to.equal('like') | 187 | expect(ratings.data[0].rating).to.equal('like') |
172 | }) | 188 | }) |
173 | 189 | ||
174 | it('Should retrieve ratings list by rating type', async function () { | 190 | it('Should retrieve ratings list by rating type', async function () { |
@@ -199,13 +215,17 @@ describe('Test users', function () { | |||
199 | }) | 215 | }) |
200 | 216 | ||
201 | describe('Logout', function () { | 217 | describe('Logout', function () { |
202 | it('Should logout (revoke token)') | 218 | it('Should logout (revoke token)', async function () { |
203 | 219 | await logout(server.url, server.accessToken) | |
204 | it('Should not be able to get the user information') | 220 | }) |
205 | 221 | ||
206 | it('Should not be able to upload a video') | 222 | it('Should not be able to get the user information', async function () { |
223 | await getMyUserInformation(server.url, server.accessToken, 401) | ||
224 | }) | ||
207 | 225 | ||
208 | it('Should not be able to remove a video') | 226 | it('Should not be able to upload a video', async function () { |
227 | await uploadVideo(server.url, server.accessToken, { name: 'video' }, 401) | ||
228 | }) | ||
209 | 229 | ||
210 | it('Should not be able to rate a video', async function () { | 230 | it('Should not be able to rate a video', async function () { |
211 | const path = '/api/v1/videos/' | 231 | const path = '/api/v1/videos/' |
@@ -223,13 +243,17 @@ describe('Test users', function () { | |||
223 | await makePutBodyRequest(options) | 243 | await makePutBodyRequest(options) |
224 | }) | 244 | }) |
225 | 245 | ||
226 | it('Should be able to login again') | 246 | it('Should be able to login again', async function () { |
247 | server.accessToken = await serverLogin(server) | ||
248 | }) | ||
227 | 249 | ||
228 | it('Should have an expired access token') | 250 | it('Should have an expired access token') |
229 | 251 | ||
230 | it('Should refresh the token') | 252 | it('Should refresh the token') |
231 | 253 | ||
232 | it('Should be able to upload a video again') | 254 | it('Should be able to get my user information again', async function () { |
255 | await getMyUserInformation(server.url, server.accessToken) | ||
256 | }) | ||
233 | }) | 257 | }) |
234 | 258 | ||
235 | describe('Creating a user', function () { | 259 | describe('Creating a user', function () { |
@@ -253,7 +277,7 @@ describe('Test users', function () { | |||
253 | const res1 = await getMyUserInformation(server.url, accessTokenUser) | 277 | const res1 = await getMyUserInformation(server.url, accessTokenUser) |
254 | const userMe: MyUser = res1.body | 278 | const userMe: MyUser = res1.body |
255 | 279 | ||
256 | const res2 = await getUserInformation(server.url, server.accessToken, userMe.id) | 280 | const res2 = await getUserInformation(server.url, server.accessToken, userMe.id, true) |
257 | const userGet: User = res2.body | 281 | const userGet: User = res2.body |
258 | 282 | ||
259 | for (const user of [ userMe, userGet ]) { | 283 | for (const user of [ userMe, userGet ]) { |
@@ -272,13 +296,23 @@ describe('Test users', function () { | |||
272 | 296 | ||
273 | expect(userMe.specialPlaylists).to.have.lengthOf(1) | 297 | expect(userMe.specialPlaylists).to.have.lengthOf(1) |
274 | expect(userMe.specialPlaylists[0].type).to.equal(VideoPlaylistType.WATCH_LATER) | 298 | expect(userMe.specialPlaylists[0].type).to.equal(VideoPlaylistType.WATCH_LATER) |
299 | |||
300 | // Check stats are included with withStats | ||
301 | expect(userGet.videosCount).to.be.a('number') | ||
302 | expect(userGet.videosCount).to.equal(0) | ||
303 | expect(userGet.videoCommentsCount).to.be.a('number') | ||
304 | expect(userGet.videoCommentsCount).to.equal(0) | ||
305 | expect(userGet.videoAbusesCount).to.be.a('number') | ||
306 | expect(userGet.videoAbusesCount).to.equal(0) | ||
307 | expect(userGet.videoAbusesAcceptedCount).to.be.a('number') | ||
308 | expect(userGet.videoAbusesAcceptedCount).to.equal(0) | ||
275 | }) | 309 | }) |
276 | }) | 310 | }) |
277 | 311 | ||
278 | describe('My videos & quotas', function () { | 312 | describe('My videos & quotas', function () { |
279 | 313 | ||
280 | it('Should be able to upload a video with this user', async function () { | 314 | it('Should be able to upload a video with this user', async function () { |
281 | this.timeout(5000) | 315 | this.timeout(10000) |
282 | 316 | ||
283 | const videoAttributes = { | 317 | const videoAttributes = { |
284 | name: 'super user video', | 318 | name: 'super user video', |
@@ -307,7 +341,7 @@ describe('Test users', function () { | |||
307 | const videos = res.body.data | 341 | const videos = res.body.data |
308 | expect(videos).to.have.lengthOf(1) | 342 | expect(videos).to.have.lengthOf(1) |
309 | 343 | ||
310 | const video: Video = videos[ 0 ] | 344 | const video: Video = videos[0] |
311 | expect(video.name).to.equal('super user video') | 345 | expect(video.name).to.equal('super user video') |
312 | expect(video.thumbnailPath).to.not.be.null | 346 | expect(video.thumbnailPath).to.not.be.null |
313 | expect(video.previewPath).to.not.be.null | 347 | expect(video.previewPath).to.not.be.null |
@@ -330,6 +364,36 @@ describe('Test users', function () { | |||
330 | expect(videos).to.have.lengthOf(0) | 364 | expect(videos).to.have.lengthOf(0) |
331 | } | 365 | } |
332 | }) | 366 | }) |
367 | |||
368 | it('Should disable webtorrent, enable HLS, and update my quota', async function () { | ||
369 | this.timeout(60000) | ||
370 | |||
371 | { | ||
372 | const res = await getCustomConfig(server.url, server.accessToken) | ||
373 | const config = res.body as CustomConfig | ||
374 | config.transcoding.webtorrent.enabled = false | ||
375 | config.transcoding.hls.enabled = true | ||
376 | config.transcoding.enabled = true | ||
377 | await updateCustomSubConfig(server.url, server.accessToken, config) | ||
378 | } | ||
379 | |||
380 | { | ||
381 | const videoAttributes = { | ||
382 | name: 'super user video 2', | ||
383 | fixture: 'video_short.webm' | ||
384 | } | ||
385 | await uploadVideo(server.url, accessTokenUser, videoAttributes) | ||
386 | |||
387 | await waitJobs([ server ]) | ||
388 | } | ||
389 | |||
390 | { | ||
391 | const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser) | ||
392 | const data = res.body | ||
393 | |||
394 | expect(data.videoQuotaUsed).to.be.greaterThan(220000) | ||
395 | } | ||
396 | }) | ||
333 | }) | 397 | }) |
334 | 398 | ||
335 | describe('Users listing', function () { | 399 | describe('Users listing', function () { |
@@ -344,16 +408,19 @@ describe('Test users', function () { | |||
344 | expect(users).to.be.an('array') | 408 | expect(users).to.be.an('array') |
345 | expect(users.length).to.equal(2) | 409 | expect(users.length).to.equal(2) |
346 | 410 | ||
347 | const user = users[ 0 ] | 411 | const user = users[0] |
348 | expect(user.username).to.equal('user_1') | 412 | expect(user.username).to.equal('user_1') |
349 | expect(user.email).to.equal('user_1@example.com') | 413 | expect(user.email).to.equal('user_1@example.com') |
350 | expect(user.nsfwPolicy).to.equal('display') | 414 | expect(user.nsfwPolicy).to.equal('display') |
351 | 415 | ||
352 | const rootUser = users[ 1 ] | 416 | const rootUser = users[1] |
353 | expect(rootUser.username).to.equal('root') | 417 | expect(rootUser.username).to.equal('root') |
354 | expect(rootUser.email).to.equal('admin' + server.internalServerNumber + '@example.com') | 418 | expect(rootUser.email).to.equal('admin' + server.internalServerNumber + '@example.com') |
355 | expect(user.nsfwPolicy).to.equal('display') | 419 | expect(user.nsfwPolicy).to.equal('display') |
356 | 420 | ||
421 | expect(rootUser.lastLoginDate).to.exist | ||
422 | expect(user.lastLoginDate).to.exist | ||
423 | |||
357 | userId = user.id | 424 | userId = user.id |
358 | }) | 425 | }) |
359 | 426 | ||
@@ -367,7 +434,7 @@ describe('Test users', function () { | |||
367 | expect(total).to.equal(2) | 434 | expect(total).to.equal(2) |
368 | expect(users.length).to.equal(1) | 435 | expect(users.length).to.equal(1) |
369 | 436 | ||
370 | const user = users[ 0 ] | 437 | const user = users[0] |
371 | expect(user.username).to.equal('root') | 438 | expect(user.username).to.equal('root') |
372 | expect(user.email).to.equal('admin' + server.internalServerNumber + '@example.com') | 439 | expect(user.email).to.equal('admin' + server.internalServerNumber + '@example.com') |
373 | expect(user.roleLabel).to.equal('Administrator') | 440 | expect(user.roleLabel).to.equal('Administrator') |
@@ -383,7 +450,7 @@ describe('Test users', function () { | |||
383 | expect(total).to.equal(2) | 450 | expect(total).to.equal(2) |
384 | expect(users.length).to.equal(1) | 451 | expect(users.length).to.equal(1) |
385 | 452 | ||
386 | const user = users[ 0 ] | 453 | const user = users[0] |
387 | expect(user.username).to.equal('user_1') | 454 | expect(user.username).to.equal('user_1') |
388 | expect(user.email).to.equal('user_1@example.com') | 455 | expect(user.email).to.equal('user_1@example.com') |
389 | expect(user.nsfwPolicy).to.equal('display') | 456 | expect(user.nsfwPolicy).to.equal('display') |
@@ -398,7 +465,7 @@ describe('Test users', function () { | |||
398 | expect(total).to.equal(2) | 465 | expect(total).to.equal(2) |
399 | expect(users.length).to.equal(1) | 466 | expect(users.length).to.equal(1) |
400 | 467 | ||
401 | const user = users[ 0 ] | 468 | const user = users[0] |
402 | expect(user.username).to.equal('user_1') | 469 | expect(user.username).to.equal('user_1') |
403 | expect(user.email).to.equal('user_1@example.com') | 470 | expect(user.email).to.equal('user_1@example.com') |
404 | expect(user.nsfwPolicy).to.equal('display') | 471 | expect(user.nsfwPolicy).to.equal('display') |
@@ -413,13 +480,13 @@ describe('Test users', function () { | |||
413 | expect(total).to.equal(2) | 480 | expect(total).to.equal(2) |
414 | expect(users.length).to.equal(2) | 481 | expect(users.length).to.equal(2) |
415 | 482 | ||
416 | expect(users[ 0 ].username).to.equal('root') | 483 | expect(users[0].username).to.equal('root') |
417 | expect(users[ 0 ].email).to.equal('admin' + server.internalServerNumber + '@example.com') | 484 | expect(users[0].email).to.equal('admin' + server.internalServerNumber + '@example.com') |
418 | expect(users[ 0 ].nsfwPolicy).to.equal('display') | 485 | expect(users[0].nsfwPolicy).to.equal('display') |
419 | 486 | ||
420 | expect(users[ 1 ].username).to.equal('user_1') | 487 | expect(users[1].username).to.equal('user_1') |
421 | expect(users[ 1 ].email).to.equal('user_1@example.com') | 488 | expect(users[1].email).to.equal('user_1@example.com') |
422 | expect(users[ 1 ].nsfwPolicy).to.equal('display') | 489 | expect(users[1].nsfwPolicy).to.equal('display') |
423 | }) | 490 | }) |
424 | 491 | ||
425 | it('Should search user by username', async function () { | 492 | it('Should search user by username', async function () { |
@@ -429,7 +496,7 @@ describe('Test users', function () { | |||
429 | expect(res.body.total).to.equal(1) | 496 | expect(res.body.total).to.equal(1) |
430 | expect(users.length).to.equal(1) | 497 | expect(users.length).to.equal(1) |
431 | 498 | ||
432 | expect(users[ 0 ].username).to.equal('root') | 499 | expect(users[0].username).to.equal('root') |
433 | }) | 500 | }) |
434 | 501 | ||
435 | it('Should search user by email', async function () { | 502 | it('Should search user by email', async function () { |
@@ -440,8 +507,8 @@ describe('Test users', function () { | |||
440 | expect(res.body.total).to.equal(1) | 507 | expect(res.body.total).to.equal(1) |
441 | expect(users.length).to.equal(1) | 508 | expect(users.length).to.equal(1) |
442 | 509 | ||
443 | expect(users[ 0 ].username).to.equal('user_1') | 510 | expect(users[0].username).to.equal('user_1') |
444 | expect(users[ 0 ].email).to.equal('user_1@example.com') | 511 | expect(users[0].email).to.equal('user_1@example.com') |
445 | } | 512 | } |
446 | 513 | ||
447 | { | 514 | { |
@@ -451,8 +518,8 @@ describe('Test users', function () { | |||
451 | expect(res.body.total).to.equal(2) | 518 | expect(res.body.total).to.equal(2) |
452 | expect(users.length).to.equal(2) | 519 | expect(users.length).to.equal(2) |
453 | 520 | ||
454 | expect(users[ 0 ].username).to.equal('root') | 521 | expect(users[0].username).to.equal('root') |
455 | expect(users[ 1 ].username).to.equal('user_1') | 522 | expect(users[1].username).to.equal('user_1') |
456 | } | 523 | } |
457 | }) | 524 | }) |
458 | }) | 525 | }) |
@@ -622,7 +689,6 @@ describe('Test users', function () { | |||
622 | }) | 689 | }) |
623 | 690 | ||
624 | describe('Updating another user', function () { | 691 | describe('Updating another user', function () { |
625 | |||
626 | it('Should be able to update another user', async function () { | 692 | it('Should be able to update another user', async function () { |
627 | await updateUser({ | 693 | await updateUser({ |
628 | url: server.url, | 694 | url: server.url, |
@@ -691,12 +757,14 @@ describe('Test users', function () { | |||
691 | 757 | ||
692 | expect(res.body.total).to.equal(1) | 758 | expect(res.body.total).to.equal(1) |
693 | 759 | ||
694 | const video = res.body.data[ 0 ] | 760 | const video = res.body.data[0] |
695 | expect(video.account.name).to.equal('root') | 761 | expect(video.account.name).to.equal('root') |
696 | }) | 762 | }) |
697 | }) | 763 | }) |
698 | 764 | ||
699 | describe('Registering a new user', function () { | 765 | describe('Registering a new user', function () { |
766 | let user15AccessToken | ||
767 | |||
700 | it('Should register a new user', async function () { | 768 | it('Should register a new user', async function () { |
701 | const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' } | 769 | const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' } |
702 | const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' } | 770 | const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' } |
@@ -710,18 +778,18 @@ describe('Test users', function () { | |||
710 | password: 'my super password' | 778 | password: 'my super password' |
711 | } | 779 | } |
712 | 780 | ||
713 | accessToken = await userLogin(server, user15) | 781 | user15AccessToken = await userLogin(server, user15) |
714 | }) | 782 | }) |
715 | 783 | ||
716 | it('Should have the correct display name', async function () { | 784 | it('Should have the correct display name', async function () { |
717 | const res = await getMyUserInformation(server.url, accessToken) | 785 | const res = await getMyUserInformation(server.url, user15AccessToken) |
718 | const user: User = res.body | 786 | const user: User = res.body |
719 | 787 | ||
720 | expect(user.account.displayName).to.equal('super user 15') | 788 | expect(user.account.displayName).to.equal('super user 15') |
721 | }) | 789 | }) |
722 | 790 | ||
723 | it('Should have the correct video quota', async function () { | 791 | it('Should have the correct video quota', async function () { |
724 | const res = await getMyUserInformation(server.url, accessToken) | 792 | const res = await getMyUserInformation(server.url, user15AccessToken) |
725 | const user = res.body | 793 | const user = res.body |
726 | 794 | ||
727 | expect(user.videoQuota).to.equal(5 * 1024 * 1024) | 795 | expect(user.videoQuota).to.equal(5 * 1024 * 1024) |
@@ -739,7 +807,7 @@ describe('Test users', function () { | |||
739 | expect(res.body.data.find(u => u.username === 'user_15')).to.not.be.undefined | 807 | expect(res.body.data.find(u => u.username === 'user_15')).to.not.be.undefined |
740 | } | 808 | } |
741 | 809 | ||
742 | await deleteMe(server.url, accessToken) | 810 | await deleteMe(server.url, user15AccessToken) |
743 | 811 | ||
744 | { | 812 | { |
745 | const res = await getUsersList(server.url, server.accessToken) | 813 | const res = await getUsersList(server.url, server.accessToken) |
@@ -749,6 +817,9 @@ describe('Test users', function () { | |||
749 | }) | 817 | }) |
750 | 818 | ||
751 | describe('User blocking', function () { | 819 | describe('User blocking', function () { |
820 | let user16Id | ||
821 | let user16AccessToken | ||
822 | |||
752 | it('Should block and unblock a user', async function () { | 823 | it('Should block and unblock a user', async function () { |
753 | const user16 = { | 824 | const user16 = { |
754 | username: 'user_16', | 825 | username: 'user_16', |
@@ -760,19 +831,95 @@ describe('Test users', function () { | |||
760 | username: user16.username, | 831 | username: user16.username, |
761 | password: user16.password | 832 | password: user16.password |
762 | }) | 833 | }) |
763 | const user16Id = resUser.body.user.id | 834 | user16Id = resUser.body.user.id |
764 | 835 | ||
765 | accessToken = await userLogin(server, user16) | 836 | user16AccessToken = await userLogin(server, user16) |
766 | 837 | ||
767 | await getMyUserInformation(server.url, accessToken, 200) | 838 | await getMyUserInformation(server.url, user16AccessToken, 200) |
768 | await blockUser(server.url, user16Id, server.accessToken) | 839 | await blockUser(server.url, user16Id, server.accessToken) |
769 | 840 | ||
770 | await getMyUserInformation(server.url, accessToken, 401) | 841 | await getMyUserInformation(server.url, user16AccessToken, 401) |
771 | await userLogin(server, user16, 400) | 842 | await userLogin(server, user16, 400) |
772 | 843 | ||
773 | await unblockUser(server.url, user16Id, server.accessToken) | 844 | await unblockUser(server.url, user16Id, server.accessToken) |
774 | accessToken = await userLogin(server, user16) | 845 | user16AccessToken = await userLogin(server, user16) |
775 | await getMyUserInformation(server.url, accessToken, 200) | 846 | await getMyUserInformation(server.url, user16AccessToken, 200) |
847 | }) | ||
848 | }) | ||
849 | |||
850 | describe('User stats', function () { | ||
851 | let user17Id | ||
852 | let user17AccessToken | ||
853 | |||
854 | it('Should report correct initial statistics about a user', async function () { | ||
855 | const user17 = { | ||
856 | username: 'user_17', | ||
857 | password: 'my super password' | ||
858 | } | ||
859 | const resUser = await createUser({ | ||
860 | url: server.url, | ||
861 | accessToken: server.accessToken, | ||
862 | username: user17.username, | ||
863 | password: user17.password | ||
864 | }) | ||
865 | |||
866 | user17Id = resUser.body.user.id | ||
867 | user17AccessToken = await userLogin(server, user17) | ||
868 | |||
869 | const res = await getUserInformation(server.url, server.accessToken, user17Id, true) | ||
870 | const user: User = res.body | ||
871 | |||
872 | expect(user.videosCount).to.equal(0) | ||
873 | expect(user.videoCommentsCount).to.equal(0) | ||
874 | expect(user.videoAbusesCount).to.equal(0) | ||
875 | expect(user.videoAbusesCreatedCount).to.equal(0) | ||
876 | expect(user.videoAbusesAcceptedCount).to.equal(0) | ||
877 | }) | ||
878 | |||
879 | it('Should report correct videos count', async function () { | ||
880 | const videoAttributes = { | ||
881 | name: 'video to test user stats' | ||
882 | } | ||
883 | await uploadVideo(server.url, user17AccessToken, videoAttributes) | ||
884 | const res1 = await getVideosList(server.url) | ||
885 | videoId = res1.body.data.find(video => video.name === videoAttributes.name).id | ||
886 | |||
887 | const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true) | ||
888 | const user: User = res2.body | ||
889 | |||
890 | expect(user.videosCount).to.equal(1) | ||
891 | }) | ||
892 | |||
893 | it('Should report correct video comments for user', async function () { | ||
894 | const text = 'super comment' | ||
895 | await addVideoCommentThread(server.url, user17AccessToken, videoId, text) | ||
896 | |||
897 | const res = await getUserInformation(server.url, server.accessToken, user17Id, true) | ||
898 | const user: User = res.body | ||
899 | |||
900 | expect(user.videoCommentsCount).to.equal(1) | ||
901 | }) | ||
902 | |||
903 | it('Should report correct video abuses counts', async function () { | ||
904 | const reason = 'my super bad reason' | ||
905 | await reportVideoAbuse(server.url, user17AccessToken, videoId, reason) | ||
906 | |||
907 | const res1 = await getVideoAbusesList({ url: server.url, token: server.accessToken }) | ||
908 | const abuseId = res1.body.data[0].id | ||
909 | |||
910 | const res2 = await getUserInformation(server.url, server.accessToken, user17Id, true) | ||
911 | const user2: User = res2.body | ||
912 | |||
913 | expect(user2.videoAbusesCount).to.equal(1) // number of incriminations | ||
914 | expect(user2.videoAbusesCreatedCount).to.equal(1) // number of reports created | ||
915 | |||
916 | const body: VideoAbuseUpdate = { state: VideoAbuseState.ACCEPTED } | ||
917 | await updateVideoAbuse(server.url, server.accessToken, videoId, abuseId, body) | ||
918 | |||
919 | const res3 = await getUserInformation(server.url, server.accessToken, user17Id, true) | ||
920 | const user3: User = res3.body | ||
921 | |||
922 | expect(user3.videoAbusesAcceptedCount).to.equal(1) // number of reports created accepted | ||
776 | }) | 923 | }) |
777 | }) | 924 | }) |
778 | 925 | ||