diff options
author | Chocobozzz <me@florianbigard.com> | 2017-12-29 10:04:15 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2017-12-29 10:04:15 +0100 |
commit | a7ba16b62d18a53c416d248f4be06fb693b318ac (patch) | |
tree | d665a7a5afc69b780f663b314c4d466ba19778f0 /server/tests/api/users | |
parent | efed5d5ef61cd14ee3f9ed1dda8ea8e937370405 (diff) | |
download | PeerTube-a7ba16b62d18a53c416d248f4be06fb693b318ac.tar.gz PeerTube-a7ba16b62d18a53c416d248f4be06fb693b318ac.tar.zst PeerTube-a7ba16b62d18a53c416d248f4be06fb693b318ac.zip |
Fix real world script
Diffstat (limited to 'server/tests/api/users')
-rw-r--r-- | server/tests/api/users/users.ts | 236 |
1 files changed, 58 insertions, 178 deletions
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index a13807b5c..19549acdd 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts | |||
@@ -40,36 +40,28 @@ describe('Test users', function () { | |||
40 | const client = { id: 'client', secret: server.client.secret } | 40 | const client = { id: 'client', secret: server.client.secret } |
41 | const res = await login(server.url, client, server.user, 400) | 41 | const res = await login(server.url, client, server.user, 400) |
42 | 42 | ||
43 | expect(res.body.error) | 43 | expect(res.body.error).to.equal('Authentication failed.') |
44 | .to | ||
45 | .equal('Authentication failed.') | ||
46 | }) | 44 | }) |
47 | 45 | ||
48 | it('Should not login with an invalid client secret', async function () { | 46 | it('Should not login with an invalid client secret', async function () { |
49 | const client = { id: server.client.id, secret: 'coucou' } | 47 | const client = { id: server.client.id, secret: 'coucou' } |
50 | const res = await login(server.url, client, server.user, 400) | 48 | const res = await login(server.url, client, server.user, 400) |
51 | 49 | ||
52 | expect(res.body.error) | 50 | expect(res.body.error).to.equal('Authentication failed.') |
53 | .to | ||
54 | .equal('Authentication failed.') | ||
55 | }) | 51 | }) |
56 | 52 | ||
57 | it('Should not login with an invalid username', async function () { | 53 | it('Should not login with an invalid username', async function () { |
58 | const user = { username: 'captain crochet', password: server.user.password } | 54 | const user = { username: 'captain crochet', password: server.user.password } |
59 | const res = await login(server.url, server.client, user, 400) | 55 | const res = await login(server.url, server.client, user, 400) |
60 | 56 | ||
61 | expect(res.body.error) | 57 | expect(res.body.error).to.equal('Authentication failed.') |
62 | .to | ||
63 | .equal('Authentication failed.') | ||
64 | }) | 58 | }) |
65 | 59 | ||
66 | it('Should not login with an invalid password', async function () { | 60 | it('Should not login with an invalid password', async function () { |
67 | const user = { username: server.user.username, password: 'mew_three' } | 61 | const user = { username: server.user.username, password: 'mew_three' } |
68 | const res = await login(server.url, server.client, user, 400) | 62 | const res = await login(server.url, server.client, user, 400) |
69 | 63 | ||
70 | expect(res.body.error) | 64 | expect(res.body.error).to.equal('Authentication failed.') |
71 | .to | ||
72 | .equal('Authentication failed.') | ||
73 | }) | 65 | }) |
74 | 66 | ||
75 | it('Should not be able to upload a video', async function () { | 67 | it('Should not be able to upload a video', async function () { |
@@ -98,9 +90,7 @@ describe('Test users', function () { | |||
98 | const res = await getVideosList(server.url) | 90 | const res = await getVideosList(server.url) |
99 | const video = res.body.data[ 0 ] | 91 | const video = res.body.data[ 0 ] |
100 | 92 | ||
101 | expect(video.accountName) | 93 | expect(video.accountName).to.equal('root') |
102 | .to | ||
103 | .equal('root') | ||
104 | videoId = video.id | 94 | videoId = video.id |
105 | }) | 95 | }) |
106 | 96 | ||
@@ -114,12 +104,8 @@ describe('Test users', function () { | |||
114 | const res = await getMyUserVideoRating(server.url, accessToken, videoId) | 104 | const res = await getMyUserVideoRating(server.url, accessToken, videoId) |
115 | const rating = res.body | 105 | const rating = res.body |
116 | 106 | ||
117 | expect(rating.videoId) | 107 | expect(rating.videoId).to.equal(videoId) |
118 | .to | 108 | expect(rating.rating).to.equal('like') |
119 | .equal(videoId) | ||
120 | expect(rating.rating) | ||
121 | .to | ||
122 | .equal('like') | ||
123 | }) | 109 | }) |
124 | 110 | ||
125 | it('Should not be able to remove the video with an incorrect token', async function () { | 111 | it('Should not be able to remove the video with an incorrect token', async function () { |
@@ -181,23 +167,12 @@ describe('Test users', function () { | |||
181 | const res = await getMyUserInformation(server.url, accessTokenUser) | 167 | const res = await getMyUserInformation(server.url, accessTokenUser) |
182 | const user = res.body | 168 | const user = res.body |
183 | 169 | ||
184 | expect(user.username) | 170 | expect(user.username).to.equal('user_1') |
185 | .to | 171 | expect(user.email).to.equal('user_1@example.com') |
186 | .equal('user_1') | ||
187 | expect(user.email) | ||
188 | .to | ||
189 | .equal('user_1@example.com') | ||
190 | expect(user.displayNSFW).to.be.false | 172 | expect(user.displayNSFW).to.be.false |
191 | expect(user.videoQuota) | 173 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) |
192 | .to | 174 | expect(user.roleLabel).to.equal('User') |
193 | .equal(2 * 1024 * 1024) | 175 | expect(user.id).to.be.a('number') |
194 | expect(user.roleLabel) | ||
195 | .to | ||
196 | .equal('User') | ||
197 | expect(user.id) | ||
198 | .to | ||
199 | .be | ||
200 | .a('number') | ||
201 | }) | 176 | }) |
202 | 177 | ||
203 | it('Should be able to upload a video with this user', async function () { | 178 | it('Should be able to upload a video with this user', async function () { |
@@ -211,19 +186,12 @@ describe('Test users', function () { | |||
211 | 186 | ||
212 | it('Should be able to list my videos', async function () { | 187 | it('Should be able to list my videos', async function () { |
213 | const res = await getMyVideos(server.url, accessTokenUser, 0, 5) | 188 | const res = await getMyVideos(server.url, accessTokenUser, 0, 5) |
214 | expect(res.body.total) | 189 | expect(res.body.total).to.equal(1) |
215 | .to | ||
216 | .equal(1) | ||
217 | 190 | ||
218 | const videos = res.body.data | 191 | const videos = res.body.data |
219 | expect(videos) | 192 | expect(videos).to.have.lengthOf(1) |
220 | .to | ||
221 | .have | ||
222 | .lengthOf(1) | ||
223 | 193 | ||
224 | expect(videos[ 0 ].name) | 194 | expect(videos[ 0 ].name).to.equal('super user video') |
225 | .to | ||
226 | .equal('super user video') | ||
227 | }) | 195 | }) |
228 | 196 | ||
229 | it('Should list all the users', async function () { | 197 | it('Should list all the users', async function () { |
@@ -232,33 +200,18 @@ describe('Test users', function () { | |||
232 | const total = result.total | 200 | const total = result.total |
233 | const users = result.data | 201 | const users = result.data |
234 | 202 | ||
235 | expect(total) | 203 | expect(total).to.equal(2) |
236 | .to | 204 | expect(users).to.be.an('array') |
237 | .equal(2) | 205 | expect(users.length).to.equal(2) |
238 | expect(users) | ||
239 | .to | ||
240 | .be | ||
241 | .an('array') | ||
242 | expect(users.length) | ||
243 | .to | ||
244 | .equal(2) | ||
245 | 206 | ||
246 | const user = users[ 0 ] | 207 | const user = users[ 0 ] |
247 | expect(user.username) | 208 | expect(user.username).to.equal('user_1') |
248 | .to | 209 | expect(user.email).to.equal('user_1@example.com') |
249 | .equal('user_1') | ||
250 | expect(user.email) | ||
251 | .to | ||
252 | .equal('user_1@example.com') | ||
253 | expect(user.displayNSFW).to.be.false | 210 | expect(user.displayNSFW).to.be.false |
254 | 211 | ||
255 | const rootUser = users[ 1 ] | 212 | const rootUser = users[ 1 ] |
256 | expect(rootUser.username) | 213 | expect(rootUser.username).to.equal('root') |
257 | .to | 214 | expect(rootUser.email).to.equal('admin1@example.com') |
258 | .equal('root') | ||
259 | expect(rootUser.email) | ||
260 | .to | ||
261 | .equal('admin1@example.com') | ||
262 | expect(rootUser.displayNSFW).to.be.false | 215 | expect(rootUser.displayNSFW).to.be.false |
263 | 216 | ||
264 | userId = user.id | 217 | userId = user.id |
@@ -271,23 +224,13 @@ describe('Test users', function () { | |||
271 | const total = result.total | 224 | const total = result.total |
272 | const users = result.data | 225 | const users = result.data |
273 | 226 | ||
274 | expect(total) | 227 | expect(total).to.equal(2) |
275 | .to | 228 | expect(users.length).to.equal(1) |
276 | .equal(2) | ||
277 | expect(users.length) | ||
278 | .to | ||
279 | .equal(1) | ||
280 | 229 | ||
281 | const user = users[ 0 ] | 230 | const user = users[ 0 ] |
282 | expect(user.username) | 231 | expect(user.username).to.equal('root') |
283 | .to | 232 | expect(user.email).to.equal('admin1@example.com') |
284 | .equal('root') | 233 | expect(user.roleLabel).to.equal('Administrator') |
285 | expect(user.email) | ||
286 | .to | ||
287 | .equal('admin1@example.com') | ||
288 | expect(user.roleLabel) | ||
289 | .to | ||
290 | .equal('Administrator') | ||
291 | expect(user.displayNSFW).to.be.false | 234 | expect(user.displayNSFW).to.be.false |
292 | }) | 235 | }) |
293 | 236 | ||
@@ -297,20 +240,12 @@ describe('Test users', function () { | |||
297 | const total = result.total | 240 | const total = result.total |
298 | const users = result.data | 241 | const users = result.data |
299 | 242 | ||
300 | expect(total) | 243 | expect(total).to.equal(2) |
301 | .to | 244 | expect(users.length).to.equal(1) |
302 | .equal(2) | ||
303 | expect(users.length) | ||
304 | .to | ||
305 | .equal(1) | ||
306 | 245 | ||
307 | const user = users[ 0 ] | 246 | const user = users[ 0 ] |
308 | expect(user.username) | 247 | expect(user.username).to.equal('user_1') |
309 | .to | 248 | expect(user.email).to.equal('user_1@example.com') |
310 | .equal('user_1') | ||
311 | expect(user.email) | ||
312 | .to | ||
313 | .equal('user_1@example.com') | ||
314 | expect(user.displayNSFW).to.be.false | 249 | expect(user.displayNSFW).to.be.false |
315 | }) | 250 | }) |
316 | 251 | ||
@@ -320,20 +255,12 @@ describe('Test users', function () { | |||
320 | const total = result.total | 255 | const total = result.total |
321 | const users = result.data | 256 | const users = result.data |
322 | 257 | ||
323 | expect(total) | 258 | expect(total).to.equal(2) |
324 | .to | 259 | expect(users.length).to.equal(1) |
325 | .equal(2) | ||
326 | expect(users.length) | ||
327 | .to | ||
328 | .equal(1) | ||
329 | 260 | ||
330 | const user = users[ 0 ] | 261 | const user = users[ 0 ] |
331 | expect(user.username) | 262 | expect(user.username).to.equal('user_1') |
332 | .to | 263 | expect(user.email).to.equal('user_1@example.com') |
333 | .equal('user_1') | ||
334 | expect(user.email) | ||
335 | .to | ||
336 | .equal('user_1@example.com') | ||
337 | expect(user.displayNSFW).to.be.false | 264 | expect(user.displayNSFW).to.be.false |
338 | }) | 265 | }) |
339 | 266 | ||
@@ -343,27 +270,15 @@ describe('Test users', function () { | |||
343 | const total = result.total | 270 | const total = result.total |
344 | const users = result.data | 271 | const users = result.data |
345 | 272 | ||
346 | expect(total) | 273 | expect(total).to.equal(2) |
347 | .to | 274 | expect(users.length).to.equal(2) |
348 | .equal(2) | 275 | |
349 | expect(users.length) | 276 | expect(users[ 0 ].username).to.equal('root') |
350 | .to | 277 | expect(users[ 0 ].email).to.equal('admin1@example.com') |
351 | .equal(2) | ||
352 | |||
353 | expect(users[ 0 ].username) | ||
354 | .to | ||
355 | .equal('root') | ||
356 | expect(users[ 0 ].email) | ||
357 | .to | ||
358 | .equal('admin1@example.com') | ||
359 | expect(users[ 0 ].displayNSFW).to.be.false | 278 | expect(users[ 0 ].displayNSFW).to.be.false |
360 | 279 | ||
361 | expect(users[ 1 ].username) | 280 | expect(users[ 1 ].username).to.equal('user_1') |
362 | .to | 281 | expect(users[ 1 ].email).to.equal('user_1@example.com') |
363 | .equal('user_1') | ||
364 | expect(users[ 1 ].email) | ||
365 | .to | ||
366 | .equal('user_1@example.com') | ||
367 | expect(users[ 1 ].displayNSFW).to.be.false | 282 | expect(users[ 1 ].displayNSFW).to.be.false |
368 | }) | 283 | }) |
369 | 284 | ||
@@ -388,20 +303,11 @@ describe('Test users', function () { | |||
388 | const res = await getMyUserInformation(server.url, accessTokenUser) | 303 | const res = await getMyUserInformation(server.url, accessTokenUser) |
389 | const user = res.body | 304 | const user = res.body |
390 | 305 | ||
391 | expect(user.username) | 306 | expect(user.username).to.equal('user_1') |
392 | .to | 307 | expect(user.email).to.equal('user_1@example.com') |
393 | .equal('user_1') | ||
394 | expect(user.email) | ||
395 | .to | ||
396 | .equal('user_1@example.com') | ||
397 | expect(user.displayNSFW).to.be.ok | 308 | expect(user.displayNSFW).to.be.ok |
398 | expect(user.videoQuota) | 309 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) |
399 | .to | 310 | expect(user.id).to.be.a('number') |
400 | .equal(2 * 1024 * 1024) | ||
401 | expect(user.id) | ||
402 | .to | ||
403 | .be | ||
404 | .a('number') | ||
405 | }) | 311 | }) |
406 | 312 | ||
407 | it('Should be able to change the autoPlayVideo attribute', async function () { | 313 | it('Should be able to change the autoPlayVideo attribute', async function () { |
@@ -427,20 +333,11 @@ describe('Test users', function () { | |||
427 | const res = await getMyUserInformation(server.url, accessTokenUser) | 333 | const res = await getMyUserInformation(server.url, accessTokenUser) |
428 | const user = res.body | 334 | const user = res.body |
429 | 335 | ||
430 | expect(user.username) | 336 | expect(user.username).to.equal('user_1') |
431 | .to | 337 | expect(user.email).to.equal('updated@example.com') |
432 | .equal('user_1') | ||
433 | expect(user.email) | ||
434 | .to | ||
435 | .equal('updated@example.com') | ||
436 | expect(user.displayNSFW).to.be.ok | 338 | expect(user.displayNSFW).to.be.ok |
437 | expect(user.videoQuota) | 339 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) |
438 | .to | 340 | expect(user.id).to.be.a('number') |
439 | .equal(2 * 1024 * 1024) | ||
440 | expect(user.id) | ||
441 | .to | ||
442 | .be | ||
443 | .a('number') | ||
444 | }) | 341 | }) |
445 | 342 | ||
446 | it('Should be able to update another user', async function () { | 343 | it('Should be able to update another user', async function () { |
@@ -456,23 +353,12 @@ describe('Test users', function () { | |||
456 | const res = await getUserInformation(server.url, accessToken, userId) | 353 | const res = await getUserInformation(server.url, accessToken, userId) |
457 | const user = res.body | 354 | const user = res.body |
458 | 355 | ||
459 | expect(user.username) | 356 | expect(user.username).to.equal('user_1') |
460 | .to | 357 | expect(user.email).to.equal('updated2@example.com') |
461 | .equal('user_1') | ||
462 | expect(user.email) | ||
463 | .to | ||
464 | .equal('updated2@example.com') | ||
465 | expect(user.displayNSFW).to.be.ok | 358 | expect(user.displayNSFW).to.be.ok |
466 | expect(user.videoQuota) | 359 | expect(user.videoQuota).to.equal(42) |
467 | .to | 360 | expect(user.roleLabel).to.equal('Moderator') |
468 | .equal(42) | 361 | expect(user.id).to.be.a('number') |
469 | expect(user.roleLabel) | ||
470 | .to | ||
471 | .equal('Moderator') | ||
472 | expect(user.id) | ||
473 | .to | ||
474 | .be | ||
475 | .a('number') | ||
476 | }) | 362 | }) |
477 | 363 | ||
478 | it('Should not be able to delete a user by a moderator', async function () { | 364 | it('Should not be able to delete a user by a moderator', async function () { |
@@ -495,14 +381,10 @@ describe('Test users', function () { | |||
495 | it('Should not have videos of this user', async function () { | 381 | it('Should not have videos of this user', async function () { |
496 | const res = await getVideosList(server.url) | 382 | const res = await getVideosList(server.url) |
497 | 383 | ||
498 | expect(res.body.total) | 384 | expect(res.body.total).to.equal(1) |
499 | .to | ||
500 | .equal(1) | ||
501 | 385 | ||
502 | const video = res.body.data[ 0 ] | 386 | const video = res.body.data[ 0 ] |
503 | expect(video.accountName) | 387 | expect(video.accountName).to.equal('root') |
504 | .to | ||
505 | .equal('root') | ||
506 | }) | 388 | }) |
507 | 389 | ||
508 | it('Should register a new user', async function () { | 390 | it('Should register a new user', async function () { |
@@ -522,9 +404,7 @@ describe('Test users', function () { | |||
522 | const res = await getMyUserInformation(server.url, accessToken) | 404 | const res = await getMyUserInformation(server.url, accessToken) |
523 | const user = res.body | 405 | const user = res.body |
524 | 406 | ||
525 | expect(user.videoQuota) | 407 | expect(user.videoQuota).to.equal(5 * 1024 * 1024) |
526 | .to | ||
527 | .equal(5 * 1024 * 1024) | ||
528 | }) | 408 | }) |
529 | 409 | ||
530 | after(async function () { | 410 | after(async function () { |