diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-11-17 11:35:10 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-11-27 19:40:52 +0100 |
commit | afffe98839db7ccbfa9fb8b7d1413b97900fdc73 (patch) | |
tree | f0b3cbe58f73e81a5ba4bb31dabd9691994cf2ca /server/tests/api/users.ts | |
parent | 1b3989b0961d22a5a45ad16239e3c3f58f66180c (diff) | |
download | PeerTube-afffe98839db7ccbfa9fb8b7d1413b97900fdc73.tar.gz PeerTube-afffe98839db7ccbfa9fb8b7d1413b97900fdc73.tar.zst PeerTube-afffe98839db7ccbfa9fb8b7d1413b97900fdc73.zip |
Speed up activity pub http requests
Diffstat (limited to 'server/tests/api/users.ts')
-rw-r--r-- | server/tests/api/users.ts | 319 |
1 files changed, 217 insertions, 102 deletions
diff --git a/server/tests/api/users.ts b/server/tests/api/users.ts index 6f40ca3c9..055dade04 100644 --- a/server/tests/api/users.ts +++ b/server/tests/api/users.ts | |||
@@ -1,38 +1,36 @@ | |||
1 | /* tslint:disable:no-unused-expression */ | 1 | /* tslint:disable:no-unused-expression */ |
2 | |||
3 | import 'mocha' | ||
4 | import * as chai from 'chai' | 2 | import * as chai from 'chai' |
5 | const expect = chai.expect | 3 | import 'mocha' |
6 | 4 | import { UserRole } from '../../../shared' | |
7 | import { | 5 | import { |
8 | ServerInfo, | ||
9 | flushTests, | ||
10 | runServer, | ||
11 | login, | ||
12 | uploadVideo, | ||
13 | makeFriends, | ||
14 | quitFriends, | ||
15 | getVideosList, | ||
16 | rateVideo, | ||
17 | getUserVideoRating, | ||
18 | removeVideo, | ||
19 | makePutBodyRequest, | ||
20 | createUser, | 6 | createUser, |
21 | loginAndGetAccessToken, | 7 | flushTests, |
8 | getBlacklistedVideosList, | ||
22 | getMyUserInformation, | 9 | getMyUserInformation, |
10 | getUserInformation, | ||
23 | getUsersList, | 11 | getUsersList, |
24 | getUsersListPaginationAndSort, | 12 | getUsersListPaginationAndSort, |
25 | updateUser, | 13 | getUserVideoRating, |
26 | updateMyUser, | 14 | getVideosList, |
15 | killallServers, | ||
16 | login, | ||
17 | loginAndGetAccessToken, | ||
18 | makePutBodyRequest, | ||
19 | rateVideo, | ||
27 | registerUser, | 20 | registerUser, |
28 | removeUser, | 21 | removeUser, |
29 | killallServers, | 22 | removeVideo, |
30 | getUserInformation, | 23 | runServer, |
31 | getBlacklistedVideosList | 24 | ServerInfo, |
25 | updateMyUser, | ||
26 | updateUser, | ||
27 | uploadVideo | ||
32 | } from '../utils' | 28 | } from '../utils' |
33 | import { UserRole } from '../../../shared' | 29 | import { follow } from '../utils/follows' |
34 | import { getMyVideos } from '../utils/videos' | 30 | import { getMyVideos } from '../utils/videos' |
35 | 31 | ||
32 | const expect = chai.expect | ||
33 | |||
36 | describe('Test users', function () { | 34 | describe('Test users', function () { |
37 | let server: ServerInfo | 35 | let server: ServerInfo |
38 | let accessToken: string | 36 | let accessToken: string |
@@ -57,28 +55,36 @@ describe('Test users', function () { | |||
57 | const client = { id: 'client', secret: server.client.secret } | 55 | const client = { id: 'client', secret: server.client.secret } |
58 | const res = await login(server.url, client, server.user, 400) | 56 | const res = await login(server.url, client, server.user, 400) |
59 | 57 | ||
60 | expect(res.body.error).to.equal('invalid_client') | 58 | expect(res.body.error) |
59 | .to | ||
60 | .equal('invalid_client') | ||
61 | }) | 61 | }) |
62 | 62 | ||
63 | it('Should not login with an invalid client secret', async function () { | 63 | it('Should not login with an invalid client secret', async function () { |
64 | const client = { id: server.client.id, secret: 'coucou' } | 64 | const client = { id: server.client.id, secret: 'coucou' } |
65 | const res = await login(server.url, client, server.user, 400) | 65 | const res = await login(server.url, client, server.user, 400) |
66 | 66 | ||
67 | expect(res.body.error).to.equal('invalid_client') | 67 | expect(res.body.error) |
68 | .to | ||
69 | .equal('invalid_client') | ||
68 | }) | 70 | }) |
69 | 71 | ||
70 | it('Should not login with an invalid username', async function () { | 72 | it('Should not login with an invalid username', async function () { |
71 | const user = { username: 'captain crochet', password: server.user.password } | 73 | const user = { username: 'captain crochet', password: server.user.password } |
72 | const res = await login(server.url, server.client, user, 400) | 74 | const res = await login(server.url, server.client, user, 400) |
73 | 75 | ||
74 | expect(res.body.error).to.equal('invalid_grant') | 76 | expect(res.body.error) |
77 | .to | ||
78 | .equal('invalid_grant') | ||
75 | }) | 79 | }) |
76 | 80 | ||
77 | it('Should not login with an invalid password', async function () { | 81 | it('Should not login with an invalid password', async function () { |
78 | const user = { username: server.user.username, password: 'mew_three' } | 82 | const user = { username: server.user.username, password: 'mew_three' } |
79 | const res = await login(server.url, server.client, user, 400) | 83 | const res = await login(server.url, server.client, user, 400) |
80 | 84 | ||
81 | expect(res.body.error).to.equal('invalid_grant') | 85 | expect(res.body.error) |
86 | .to | ||
87 | .equal('invalid_grant') | ||
82 | }) | 88 | }) |
83 | 89 | ||
84 | it('Should not be able to upload a video', async function () { | 90 | it('Should not be able to upload a video', async function () { |
@@ -88,15 +94,12 @@ describe('Test users', function () { | |||
88 | await uploadVideo(server.url, accessToken, videoAttributes, 401) | 94 | await uploadVideo(server.url, accessToken, videoAttributes, 401) |
89 | }) | 95 | }) |
90 | 96 | ||
91 | it('Should not be able to make friends', async function () { | 97 | it('Should not be able to follow', async function () { |
92 | accessToken = 'my_super_token' | 98 | accessToken = 'my_super_token' |
93 | await makeFriends(server.url, accessToken, 401) | 99 | await follow(server.url, [ 'http://example.com' ], accessToken, 401) |
94 | }) | 100 | }) |
95 | 101 | ||
96 | it('Should not be able to quit friends', async function () { | 102 | it('Should not be able to unfollow') |
97 | accessToken = 'my_super_token' | ||
98 | await quitFriends(server.url, accessToken, 401) | ||
99 | }) | ||
100 | 103 | ||
101 | it('Should be able to login', async function () { | 104 | it('Should be able to login', async function () { |
102 | const res = await login(server.url, server.client, server.user, 200) | 105 | const res = await login(server.url, server.client, server.user, 200) |
@@ -108,9 +111,11 @@ describe('Test users', function () { | |||
108 | const videoAttributes = {} | 111 | const videoAttributes = {} |
109 | await uploadVideo(server.url, accessToken, videoAttributes, 204) | 112 | await uploadVideo(server.url, accessToken, videoAttributes, 204) |
110 | const res = await getVideosList(server.url) | 113 | const res = await getVideosList(server.url) |
111 | const video = res.body.data[0] | 114 | const video = res.body.data[ 0 ] |
112 | 115 | ||
113 | expect(video.author).to.equal('root') | 116 | expect(video.account) |
117 | .to | ||
118 | .equal('root') | ||
114 | videoId = video.id | 119 | videoId = video.id |
115 | }) | 120 | }) |
116 | 121 | ||
@@ -124,8 +129,12 @@ describe('Test users', function () { | |||
124 | const res = await getUserVideoRating(server.url, accessToken, videoId) | 129 | const res = await getUserVideoRating(server.url, accessToken, videoId) |
125 | const rating = res.body | 130 | const rating = res.body |
126 | 131 | ||
127 | expect(rating.videoId).to.equal(videoId) | 132 | expect(rating.videoId) |
128 | expect(rating.rating).to.equal('like') | 133 | .to |
134 | .equal(videoId) | ||
135 | expect(rating.rating) | ||
136 | .to | ||
137 | .equal('like') | ||
129 | }) | 138 | }) |
130 | 139 | ||
131 | it('Should not be able to remove the video with an incorrect token', async function () { | 140 | it('Should not be able to remove the video with an incorrect token', async function () { |
@@ -187,12 +196,23 @@ describe('Test users', function () { | |||
187 | const res = await getMyUserInformation(server.url, accessTokenUser) | 196 | const res = await getMyUserInformation(server.url, accessTokenUser) |
188 | const user = res.body | 197 | const user = res.body |
189 | 198 | ||
190 | expect(user.username).to.equal('user_1') | 199 | expect(user.username) |
191 | expect(user.email).to.equal('user_1@example.com') | 200 | .to |
201 | .equal('user_1') | ||
202 | expect(user.email) | ||
203 | .to | ||
204 | .equal('user_1@example.com') | ||
192 | expect(user.displayNSFW).to.be.false | 205 | expect(user.displayNSFW).to.be.false |
193 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | 206 | expect(user.videoQuota) |
194 | expect(user.roleLabel).to.equal('User') | 207 | .to |
195 | expect(user.id).to.be.a('number') | 208 | .equal(2 * 1024 * 1024) |
209 | expect(user.roleLabel) | ||
210 | .to | ||
211 | .equal('User') | ||
212 | expect(user.id) | ||
213 | .to | ||
214 | .be | ||
215 | .a('number') | ||
196 | }) | 216 | }) |
197 | 217 | ||
198 | it('Should be able to upload a video with this user', async function () { | 218 | it('Should be able to upload a video with this user', async function () { |
@@ -206,12 +226,19 @@ describe('Test users', function () { | |||
206 | 226 | ||
207 | it('Should be able to list my videos', async function () { | 227 | it('Should be able to list my videos', async function () { |
208 | const res = await getMyVideos(server.url, accessTokenUser, 0, 5) | 228 | const res = await getMyVideos(server.url, accessTokenUser, 0, 5) |
209 | expect(res.body.total).to.equal(1) | 229 | expect(res.body.total) |
230 | .to | ||
231 | .equal(1) | ||
210 | 232 | ||
211 | const videos = res.body.data | 233 | const videos = res.body.data |
212 | expect(videos).to.have.lengthOf(1) | 234 | expect(videos) |
235 | .to | ||
236 | .have | ||
237 | .lengthOf(1) | ||
213 | 238 | ||
214 | expect(videos[0].name).to.equal('super user video') | 239 | expect(videos[ 0 ].name) |
240 | .to | ||
241 | .equal('super user video') | ||
215 | }) | 242 | }) |
216 | 243 | ||
217 | it('Should list all the users', async function () { | 244 | it('Should list all the users', async function () { |
@@ -220,18 +247,33 @@ describe('Test users', function () { | |||
220 | const total = result.total | 247 | const total = result.total |
221 | const users = result.data | 248 | const users = result.data |
222 | 249 | ||
223 | expect(total).to.equal(2) | 250 | expect(total) |
224 | expect(users).to.be.an('array') | 251 | .to |
225 | expect(users.length).to.equal(2) | 252 | .equal(2) |
226 | 253 | expect(users) | |
227 | const user = users[0] | 254 | .to |
228 | expect(user.username).to.equal('user_1') | 255 | .be |
229 | expect(user.email).to.equal('user_1@example.com') | 256 | .an('array') |
257 | expect(users.length) | ||
258 | .to | ||
259 | .equal(2) | ||
260 | |||
261 | const user = users[ 0 ] | ||
262 | expect(user.username) | ||
263 | .to | ||
264 | .equal('user_1') | ||
265 | expect(user.email) | ||
266 | .to | ||
267 | .equal('user_1@example.com') | ||
230 | expect(user.displayNSFW).to.be.false | 268 | expect(user.displayNSFW).to.be.false |
231 | 269 | ||
232 | const rootUser = users[1] | 270 | const rootUser = users[ 1 ] |
233 | expect(rootUser.username).to.equal('root') | 271 | expect(rootUser.username) |
234 | expect(rootUser.email).to.equal('admin1@example.com') | 272 | .to |
273 | .equal('root') | ||
274 | expect(rootUser.email) | ||
275 | .to | ||
276 | .equal('admin1@example.com') | ||
235 | expect(rootUser.displayNSFW).to.be.false | 277 | expect(rootUser.displayNSFW).to.be.false |
236 | 278 | ||
237 | userId = user.id | 279 | userId = user.id |
@@ -244,13 +286,23 @@ describe('Test users', function () { | |||
244 | const total = result.total | 286 | const total = result.total |
245 | const users = result.data | 287 | const users = result.data |
246 | 288 | ||
247 | expect(total).to.equal(2) | 289 | expect(total) |
248 | expect(users.length).to.equal(1) | 290 | .to |
249 | 291 | .equal(2) | |
250 | const user = users[0] | 292 | expect(users.length) |
251 | expect(user.username).to.equal('root') | 293 | .to |
252 | expect(user.email).to.equal('admin1@example.com') | 294 | .equal(1) |
253 | expect(user.roleLabel).to.equal('Administrator') | 295 | |
296 | const user = users[ 0 ] | ||
297 | expect(user.username) | ||
298 | .to | ||
299 | .equal('root') | ||
300 | expect(user.email) | ||
301 | .to | ||
302 | .equal('admin1@example.com') | ||
303 | expect(user.roleLabel) | ||
304 | .to | ||
305 | .equal('Administrator') | ||
254 | expect(user.displayNSFW).to.be.false | 306 | expect(user.displayNSFW).to.be.false |
255 | }) | 307 | }) |
256 | 308 | ||
@@ -260,12 +312,20 @@ describe('Test users', function () { | |||
260 | const total = result.total | 312 | const total = result.total |
261 | const users = result.data | 313 | const users = result.data |
262 | 314 | ||
263 | expect(total).to.equal(2) | 315 | expect(total) |
264 | expect(users.length).to.equal(1) | 316 | .to |
265 | 317 | .equal(2) | |
266 | const user = users[0] | 318 | expect(users.length) |
267 | expect(user.username).to.equal('user_1') | 319 | .to |
268 | expect(user.email).to.equal('user_1@example.com') | 320 | .equal(1) |
321 | |||
322 | const user = users[ 0 ] | ||
323 | expect(user.username) | ||
324 | .to | ||
325 | .equal('user_1') | ||
326 | expect(user.email) | ||
327 | .to | ||
328 | .equal('user_1@example.com') | ||
269 | expect(user.displayNSFW).to.be.false | 329 | expect(user.displayNSFW).to.be.false |
270 | }) | 330 | }) |
271 | 331 | ||
@@ -275,12 +335,20 @@ describe('Test users', function () { | |||
275 | const total = result.total | 335 | const total = result.total |
276 | const users = result.data | 336 | const users = result.data |
277 | 337 | ||
278 | expect(total).to.equal(2) | 338 | expect(total) |
279 | expect(users.length).to.equal(1) | 339 | .to |
280 | 340 | .equal(2) | |
281 | const user = users[0] | 341 | expect(users.length) |
282 | expect(user.username).to.equal('user_1') | 342 | .to |
283 | expect(user.email).to.equal('user_1@example.com') | 343 | .equal(1) |
344 | |||
345 | const user = users[ 0 ] | ||
346 | expect(user.username) | ||
347 | .to | ||
348 | .equal('user_1') | ||
349 | expect(user.email) | ||
350 | .to | ||
351 | .equal('user_1@example.com') | ||
284 | expect(user.displayNSFW).to.be.false | 352 | expect(user.displayNSFW).to.be.false |
285 | }) | 353 | }) |
286 | 354 | ||
@@ -290,16 +358,28 @@ describe('Test users', function () { | |||
290 | const total = result.total | 358 | const total = result.total |
291 | const users = result.data | 359 | const users = result.data |
292 | 360 | ||
293 | expect(total).to.equal(2) | 361 | expect(total) |
294 | expect(users.length).to.equal(2) | 362 | .to |
295 | 363 | .equal(2) | |
296 | expect(users[0].username).to.equal('root') | 364 | expect(users.length) |
297 | expect(users[0].email).to.equal('admin1@example.com') | 365 | .to |
298 | expect(users[0].displayNSFW).to.be.false | 366 | .equal(2) |
299 | 367 | ||
300 | expect(users[1].username).to.equal('user_1') | 368 | expect(users[ 0 ].username) |
301 | expect(users[1].email).to.equal('user_1@example.com') | 369 | .to |
302 | expect(users[1].displayNSFW).to.be.false | 370 | .equal('root') |
371 | expect(users[ 0 ].email) | ||
372 | .to | ||
373 | .equal('admin1@example.com') | ||
374 | expect(users[ 0 ].displayNSFW).to.be.false | ||
375 | |||
376 | expect(users[ 1 ].username) | ||
377 | .to | ||
378 | .equal('user_1') | ||
379 | expect(users[ 1 ].email) | ||
380 | .to | ||
381 | .equal('user_1@example.com') | ||
382 | expect(users[ 1 ].displayNSFW).to.be.false | ||
303 | }) | 383 | }) |
304 | 384 | ||
305 | it('Should update my password', async function () { | 385 | it('Should update my password', async function () { |
@@ -315,11 +395,20 @@ describe('Test users', function () { | |||
315 | const res = await getMyUserInformation(server.url, accessTokenUser) | 395 | const res = await getMyUserInformation(server.url, accessTokenUser) |
316 | const user = res.body | 396 | const user = res.body |
317 | 397 | ||
318 | expect(user.username).to.equal('user_1') | 398 | expect(user.username) |
319 | expect(user.email).to.equal('user_1@example.com') | 399 | .to |
400 | .equal('user_1') | ||
401 | expect(user.email) | ||
402 | .to | ||
403 | .equal('user_1@example.com') | ||
320 | expect(user.displayNSFW).to.be.ok | 404 | expect(user.displayNSFW).to.be.ok |
321 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | 405 | expect(user.videoQuota) |
322 | expect(user.id).to.be.a('number') | 406 | .to |
407 | .equal(2 * 1024 * 1024) | ||
408 | expect(user.id) | ||
409 | .to | ||
410 | .be | ||
411 | .a('number') | ||
323 | }) | 412 | }) |
324 | 413 | ||
325 | it('Should be able to change the email display attribute', async function () { | 414 | it('Should be able to change the email display attribute', async function () { |
@@ -328,11 +417,20 @@ describe('Test users', function () { | |||
328 | const res = await getMyUserInformation(server.url, accessTokenUser) | 417 | const res = await getMyUserInformation(server.url, accessTokenUser) |
329 | const user = res.body | 418 | const user = res.body |
330 | 419 | ||
331 | expect(user.username).to.equal('user_1') | 420 | expect(user.username) |
332 | expect(user.email).to.equal('updated@example.com') | 421 | .to |
422 | .equal('user_1') | ||
423 | expect(user.email) | ||
424 | .to | ||
425 | .equal('updated@example.com') | ||
333 | expect(user.displayNSFW).to.be.ok | 426 | expect(user.displayNSFW).to.be.ok |
334 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | 427 | expect(user.videoQuota) |
335 | expect(user.id).to.be.a('number') | 428 | .to |
429 | .equal(2 * 1024 * 1024) | ||
430 | expect(user.id) | ||
431 | .to | ||
432 | .be | ||
433 | .a('number') | ||
336 | }) | 434 | }) |
337 | 435 | ||
338 | it('Should be able to update another user', async function () { | 436 | it('Should be able to update another user', async function () { |
@@ -341,12 +439,23 @@ describe('Test users', function () { | |||
341 | const res = await getUserInformation(server.url, accessToken, userId) | 439 | const res = await getUserInformation(server.url, accessToken, userId) |
342 | const user = res.body | 440 | const user = res.body |
343 | 441 | ||
344 | expect(user.username).to.equal('user_1') | 442 | expect(user.username) |
345 | expect(user.email).to.equal('updated2@example.com') | 443 | .to |
444 | .equal('user_1') | ||
445 | expect(user.email) | ||
446 | .to | ||
447 | .equal('updated2@example.com') | ||
346 | expect(user.displayNSFW).to.be.ok | 448 | expect(user.displayNSFW).to.be.ok |
347 | expect(user.videoQuota).to.equal(42) | 449 | expect(user.videoQuota) |
348 | expect(user.roleLabel).to.equal('Moderator') | 450 | .to |
349 | expect(user.id).to.be.a('number') | 451 | .equal(42) |
452 | expect(user.roleLabel) | ||
453 | .to | ||
454 | .equal('Moderator') | ||
455 | expect(user.id) | ||
456 | .to | ||
457 | .be | ||
458 | .a('number') | ||
350 | }) | 459 | }) |
351 | 460 | ||
352 | it('Should not be able to delete a user by a moderator', async function () { | 461 | it('Should not be able to delete a user by a moderator', async function () { |
@@ -369,10 +478,14 @@ describe('Test users', function () { | |||
369 | it('Should not have videos of this user', async function () { | 478 | it('Should not have videos of this user', async function () { |
370 | const res = await getVideosList(server.url) | 479 | const res = await getVideosList(server.url) |
371 | 480 | ||
372 | expect(res.body.total).to.equal(1) | 481 | expect(res.body.total) |
482 | .to | ||
483 | .equal(1) | ||
373 | 484 | ||
374 | const video = res.body.data[0] | 485 | const video = res.body.data[ 0 ] |
375 | expect(video.author).to.equal('root') | 486 | expect(video.account) |
487 | .to | ||
488 | .equal('root') | ||
376 | }) | 489 | }) |
377 | 490 | ||
378 | it('Should register a new user', async function () { | 491 | it('Should register a new user', async function () { |
@@ -392,14 +505,16 @@ describe('Test users', function () { | |||
392 | const res = await getMyUserInformation(server.url, accessToken) | 505 | const res = await getMyUserInformation(server.url, accessToken) |
393 | const user = res.body | 506 | const user = res.body |
394 | 507 | ||
395 | expect(user.videoQuota).to.equal(5 * 1024 * 1024) | 508 | expect(user.videoQuota) |
509 | .to | ||
510 | .equal(5 * 1024 * 1024) | ||
396 | }) | 511 | }) |
397 | 512 | ||
398 | after(async function () { | 513 | after(async function () { |
399 | killallServers([ server ]) | 514 | killallServers([ server ]) |
400 | 515 | ||
401 | // Keep the logs if the test failed | 516 | // Keep the logs if the test failed |
402 | if (this['ok']) { | 517 | if (this[ 'ok' ]) { |
403 | await flushTests() | 518 | await flushTests() |
404 | } | 519 | } |
405 | }) | 520 | }) |