aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-01-12 15:20:03 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-01-12 15:20:03 +0100
commit99fe265a5fc077cb66c322e7f3d191ff7110aea0 (patch)
treec9e04ccfcc5496d2300d7c26db5833e494b4cdad /server/tests
parentfcc5f77b95d330bfcb439c172b7fcc58f3162e4d (diff)
parent91cc839af88730ba55f84997c56b85ea100070a7 (diff)
downloadPeerTube-99fe265a5fc077cb66c322e7f3d191ff7110aea0.tar.gz
PeerTube-99fe265a5fc077cb66c322e7f3d191ff7110aea0.tar.zst
PeerTube-99fe265a5fc077cb66c322e7f3d191ff7110aea0.zip
Merge branch 'postgresql'
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/check-params.js764
-rw-r--r--server/tests/api/check-params/index.js9
-rw-r--r--server/tests/api/check-params/pods.js204
-rw-r--r--server/tests/api/check-params/remotes.js64
-rw-r--r--server/tests/api/check-params/requests.js87
-rw-r--r--server/tests/api/check-params/users.js284
-rw-r--r--server/tests/api/check-params/video-abuses.js180
-rw-r--r--server/tests/api/check-params/videos.js460
-rw-r--r--server/tests/api/friends-advanced.js10
-rw-r--r--server/tests/api/friends-basic.js16
-rw-r--r--server/tests/api/multiple-pods.js87
-rw-r--r--server/tests/api/requests.js42
-rw-r--r--server/tests/api/single-pod.js243
-rw-r--r--server/tests/api/users.js8
-rw-r--r--server/tests/api/video-abuse.js191
-rw-r--r--server/tests/real-world/real-world.js68
-rw-r--r--server/tests/utils/login.js11
-rw-r--r--server/tests/utils/miscs.js6
-rw-r--r--server/tests/utils/servers.js8
-rw-r--r--server/tests/utils/video-abuses.js73
-rw-r--r--server/tests/utils/videos.js84
21 files changed, 1956 insertions, 943 deletions
diff --git a/server/tests/api/check-params.js b/server/tests/api/check-params.js
deleted file mode 100644
index 444c2fc55..000000000
--- a/server/tests/api/check-params.js
+++ /dev/null
@@ -1,764 +0,0 @@
1'use strict'
2
3const chai = require('chai')
4const expect = chai.expect
5const pathUtils = require('path')
6const request = require('supertest')
7const series = require('async/series')
8
9const loginUtils = require('../utils/login')
10const requestsUtils = require('../utils/requests')
11const serversUtils = require('../utils/servers')
12const usersUtils = require('../utils/users')
13
14describe('Test parameters validator', function () {
15 let server = null
16 let userAccessToken = null
17
18 // ---------------------------------------------------------------
19
20 before(function (done) {
21 this.timeout(20000)
22
23 series([
24 function (next) {
25 serversUtils.flushTests(next)
26 },
27 function (next) {
28 serversUtils.runServer(1, function (server1) {
29 server = server1
30
31 next()
32 })
33 },
34 function (next) {
35 loginUtils.loginAndGetAccessToken(server, function (err, token) {
36 if (err) throw err
37 server.accessToken = token
38
39 next()
40 })
41 }
42 ], done)
43 })
44
45 describe('Of the pods API', function () {
46 const path = '/api/v1/pods/'
47
48 describe('When making friends', function () {
49 let userAccessToken = null
50
51 before(function (done) {
52 usersUtils.createUser(server.url, server.accessToken, 'user1', 'password', function () {
53 server.user = {
54 username: 'user1',
55 password: 'password'
56 }
57
58 loginUtils.loginAndGetAccessToken(server, function (err, accessToken) {
59 if (err) throw err
60
61 userAccessToken = accessToken
62
63 done()
64 })
65 })
66 })
67
68 describe('When making friends', function () {
69 const body = {
70 hosts: [ 'localhost:9002' ]
71 }
72
73 it('Should fail without hosts', function (done) {
74 request(server.url)
75 .post(path + '/makefriends')
76 .set('Authorization', 'Bearer ' + server.accessToken)
77 .set('Accept', 'application/json')
78 .expect(400, done)
79 })
80
81 it('Should fail if hosts is not an array', function (done) {
82 request(server.url)
83 .post(path + '/makefriends')
84 .send({ hosts: 'localhost:9002' })
85 .set('Authorization', 'Bearer ' + server.accessToken)
86 .set('Accept', 'application/json')
87 .expect(400, done)
88 })
89
90 it('Should fail if the array is not composed by hosts', function (done) {
91 request(server.url)
92 .post(path + '/makefriends')
93 .send({ hosts: [ 'localhost:9002', 'localhost:coucou' ] })
94 .set('Authorization', 'Bearer ' + server.accessToken)
95 .set('Accept', 'application/json')
96 .expect(400, done)
97 })
98
99 it('Should fail if the array is composed with http schemes', function (done) {
100 request(server.url)
101 .post(path + '/makefriends')
102 .send({ hosts: [ 'localhost:9002', 'http://localhost:9003' ] })
103 .set('Authorization', 'Bearer ' + server.accessToken)
104 .set('Accept', 'application/json')
105 .expect(400, done)
106 })
107
108 it('Should fail if hosts are not unique', function (done) {
109 request(server.url)
110 .post(path + '/makefriends')
111 .send({ urls: [ 'localhost:9002', 'localhost:9002' ] })
112 .set('Authorization', 'Bearer ' + server.accessToken)
113 .set('Accept', 'application/json')
114 .expect(400, done)
115 })
116
117 it('Should fail with a invalid token', function (done) {
118 request(server.url)
119 .post(path + '/makefriends')
120 .send(body)
121 .set('Authorization', 'Bearer faketoken')
122 .set('Accept', 'application/json')
123 .expect(401, done)
124 })
125
126 it('Should fail if the user is not an administrator', function (done) {
127 request(server.url)
128 .post(path + '/makefriends')
129 .send(body)
130 .set('Authorization', 'Bearer ' + userAccessToken)
131 .set('Accept', 'application/json')
132 .expect(403, done)
133 })
134 })
135
136 describe('When quitting friends', function () {
137 it('Should fail with a invalid token', function (done) {
138 request(server.url)
139 .get(path + '/quitfriends')
140 .query({ start: 'hello' })
141 .set('Authorization', 'Bearer faketoken')
142 .set('Accept', 'application/json')
143 .expect(401, done)
144 })
145
146 it('Should fail if the user is not an administrator', function (done) {
147 request(server.url)
148 .get(path + '/quitfriends')
149 .query({ start: 'hello' })
150 .set('Authorization', 'Bearer ' + userAccessToken)
151 .set('Accept', 'application/json')
152 .expect(403, done)
153 })
154 })
155 })
156
157 describe('When adding a pod', function () {
158 it('Should fail with nothing', function (done) {
159 const data = {}
160 requestsUtils.makePostBodyRequest(server.url, path, null, data, done)
161 })
162
163 it('Should fail without public key', function (done) {
164 const data = {
165 host: 'coucou.com'
166 }
167 requestsUtils.makePostBodyRequest(server.url, path, null, data, done)
168 })
169
170 it('Should fail without an host', function (done) {
171 const data = {
172 publicKey: 'mysuperpublickey'
173 }
174 requestsUtils.makePostBodyRequest(server.url, path, null, data, done)
175 })
176
177 it('Should fail with an incorrect host', function (done) {
178 const data = {
179 host: 'http://coucou.com',
180 publicKey: 'mysuperpublickey'
181 }
182 requestsUtils.makePostBodyRequest(server.url, path, null, data, function () {
183 data.host = 'http://coucou'
184 requestsUtils.makePostBodyRequest(server.url, path, null, data, function () {
185 data.host = 'coucou'
186 requestsUtils.makePostBodyRequest(server.url, path, null, data, done)
187 })
188 })
189 })
190
191 it('Should succeed with the correct parameters', function (done) {
192 const data = {
193 host: 'coucou.com',
194 publicKey: 'mysuperpublickey'
195 }
196 requestsUtils.makePostBodyRequest(server.url, path, null, data, done, 200)
197 })
198 })
199 })
200
201 describe('Of the videos API', function () {
202 const path = '/api/v1/videos/'
203
204 describe('When listing a video', function () {
205 it('Should fail with a bad start pagination', function (done) {
206 request(server.url)
207 .get(path)
208 .query({ start: 'hello' })
209 .set('Accept', 'application/json')
210 .expect(400, done)
211 })
212
213 it('Should fail with a bad count pagination', function (done) {
214 request(server.url)
215 .get(path)
216 .query({ count: 'hello' })
217 .set('Accept', 'application/json')
218 .expect(400, done)
219 })
220
221 it('Should fail with an incorrect sort', function (done) {
222 request(server.url)
223 .get(path)
224 .query({ sort: 'hello' })
225 .set('Accept', 'application/json')
226 .expect(400, done)
227 })
228 })
229
230 describe('When searching a video', function () {
231 it('Should fail with nothing', function (done) {
232 request(server.url)
233 .get(pathUtils.join(path, 'search'))
234 .set('Accept', 'application/json')
235 .expect(400, done)
236 })
237
238 it('Should fail with a bad start pagination', function (done) {
239 request(server.url)
240 .get(pathUtils.join(path, 'search', 'test'))
241 .query({ start: 'hello' })
242 .set('Accept', 'application/json')
243 .expect(400, done)
244 })
245
246 it('Should fail with a bad count pagination', function (done) {
247 request(server.url)
248 .get(pathUtils.join(path, 'search', 'test'))
249 .query({ count: 'hello' })
250 .set('Accept', 'application/json')
251 .expect(400, done)
252 })
253
254 it('Should fail with an incorrect sort', function (done) {
255 request(server.url)
256 .get(pathUtils.join(path, 'search', 'test'))
257 .query({ sort: 'hello' })
258 .set('Accept', 'application/json')
259 .expect(400, done)
260 })
261 })
262
263 describe('When adding a video', function () {
264 it('Should fail with nothing', function (done) {
265 const data = {}
266 const attach = {}
267 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
268 })
269
270 it('Should fail without name', function (done) {
271 const data = {
272 description: 'my super description',
273 tags: [ 'tag1', 'tag2' ]
274 }
275 const attach = {
276 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
277 }
278 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
279 })
280
281 it('Should fail with a long name', function (done) {
282 const data = {
283 name: 'My very very very very very very very very very very very very very very very very long name',
284 description: 'my super description',
285 tags: [ 'tag1', 'tag2' ]
286 }
287 const attach = {
288 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
289 }
290 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
291 })
292
293 it('Should fail without description', function (done) {
294 const data = {
295 name: 'my super name',
296 tags: [ 'tag1', 'tag2' ]
297 }
298 const attach = {
299 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
300 }
301 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
302 })
303
304 it('Should fail with a long description', function (done) {
305 const data = {
306 name: 'my super name',
307 description: 'my super description which is very very very very very very very very very very very very very very' +
308 'very very very very very very very very very very very very very very very very very very very very very' +
309 'very very very very very very very very very very very very very very very long',
310 tags: [ 'tag1', 'tag2' ]
311 }
312 const attach = {
313 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
314 }
315 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
316 })
317
318 it('Should fail without tags', function (done) {
319 const data = {
320 name: 'my super name',
321 description: 'my super description'
322 }
323 const attach = {
324 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
325 }
326 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
327 })
328
329 it('Should fail with too many tags', function (done) {
330 const data = {
331 name: 'my super name',
332 description: 'my super description',
333 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
334 }
335 const attach = {
336 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
337 }
338 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
339 })
340
341 it('Should fail with not enough tags', function (done) {
342 const data = {
343 name: 'my super name',
344 description: 'my super description',
345 tags: [ ]
346 }
347 const attach = {
348 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
349 }
350 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
351 })
352
353 it('Should fail with a tag length too low', function (done) {
354 const data = {
355 name: 'my super name',
356 description: 'my super description',
357 tags: [ 'tag1', 't' ]
358 }
359 const attach = {
360 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
361 }
362 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
363 })
364
365 it('Should fail with a tag length too big', function (done) {
366 const data = {
367 name: 'my super name',
368 description: 'my super description',
369 tags: [ 'mysupertagtoolong', 'tag1' ]
370 }
371 const attach = {
372 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
373 }
374 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
375 })
376
377 it('Should fail with malformed tags', function (done) {
378 const data = {
379 name: 'my super name',
380 description: 'my super description',
381 tags: [ 'my tag' ]
382 }
383 const attach = {
384 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
385 }
386 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
387 })
388
389 it('Should fail without an input file', function (done) {
390 const data = {
391 name: 'my super name',
392 description: 'my super description',
393 tags: [ 'tag1', 'tag2' ]
394 }
395 const attach = {}
396 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
397 })
398
399 it('Should fail without an incorrect input file', function (done) {
400 const data = {
401 name: 'my super name',
402 description: 'my super description',
403 tags: [ 'tag1', 'tag2' ]
404 }
405 const attach = {
406 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short_fake.webm')
407 }
408 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
409 })
410
411 it('Should fail with a too big duration', function (done) {
412 const data = {
413 name: 'my super name',
414 description: 'my super description',
415 tags: [ 'tag1', 'tag2' ]
416 }
417 const attach = {
418 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_too_long.webm')
419 }
420 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
421 })
422
423 it('Should succeed with the correct parameters', function (done) {
424 const data = {
425 name: 'my super name',
426 description: 'my super description',
427 tags: [ 'tag1', 'tag2' ]
428 }
429 const attach = {
430 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
431 }
432 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () {
433 attach.videofile = pathUtils.join(__dirname, 'fixtures', 'video_short.mp4')
434 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () {
435 attach.videofile = pathUtils.join(__dirname, 'fixtures', 'video_short.ogv')
436 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done, 204)
437 }, false)
438 }, false)
439 })
440 })
441
442 describe('When getting a video', function () {
443 it('Should return the list of the videos with nothing', function (done) {
444 request(server.url)
445 .get(path)
446 .set('Accept', 'application/json')
447 .expect(200)
448 .expect('Content-Type', /json/)
449 .end(function (err, res) {
450 if (err) throw err
451
452 expect(res.body.data).to.be.an('array')
453 expect(res.body.data.length).to.equal(3)
454
455 done()
456 })
457 })
458
459 it('Should fail without a mongodb id', function (done) {
460 request(server.url)
461 .get(path + 'coucou')
462 .set('Accept', 'application/json')
463 .expect(400, done)
464 })
465
466 it('Should return 404 with an incorrect video', function (done) {
467 request(server.url)
468 .get(path + '123456789012345678901234')
469 .set('Accept', 'application/json')
470 .expect(404, done)
471 })
472
473 it('Should succeed with the correct parameters')
474 })
475
476 describe('When removing a video', function () {
477 it('Should have 404 with nothing', function (done) {
478 request(server.url)
479 .delete(path)
480 .set('Authorization', 'Bearer ' + server.accessToken)
481 .expect(400, done)
482 })
483
484 it('Should fail without a mongodb id', function (done) {
485 request(server.url)
486 .delete(path + 'hello')
487 .set('Authorization', 'Bearer ' + server.accessToken)
488 .expect(400, done)
489 })
490
491 it('Should fail with a video which does not exist', function (done) {
492 request(server.url)
493 .delete(path + '123456789012345678901234')
494 .set('Authorization', 'Bearer ' + server.accessToken)
495 .expect(404, done)
496 })
497
498 it('Should fail with a video of another user')
499
500 it('Should fail with a video of another pod')
501
502 it('Should succeed with the correct parameters')
503 })
504 })
505
506 describe('Of the users API', function () {
507 const path = '/api/v1/users/'
508 let userId = null
509 let rootId = null
510
511 describe('When listing users', function () {
512 it('Should fail with a bad start pagination', function (done) {
513 request(server.url)
514 .get(path)
515 .query({ start: 'hello' })
516 .set('Accept', 'application/json')
517 .expect(400, done)
518 })
519
520 it('Should fail with a bad count pagination', function (done) {
521 request(server.url)
522 .get(path)
523 .query({ count: 'hello' })
524 .set('Accept', 'application/json')
525 .expect(400, done)
526 })
527
528 it('Should fail with an incorrect sort', function (done) {
529 request(server.url)
530 .get(path)
531 .query({ sort: 'hello' })
532 .set('Accept', 'application/json')
533 .expect(400, done)
534 })
535 })
536
537 describe('When adding a new user', function () {
538 it('Should fail with a too small username', function (done) {
539 const data = {
540 username: 'ji',
541 password: 'mysuperpassword'
542 }
543
544 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
545 })
546
547 it('Should fail with a too long username', function (done) {
548 const data = {
549 username: 'mysuperusernamewhichisverylong',
550 password: 'mysuperpassword'
551 }
552
553 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
554 })
555
556 it('Should fail with an incorrect username', function (done) {
557 const data = {
558 username: 'my username',
559 password: 'mysuperpassword'
560 }
561
562 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
563 })
564
565 it('Should fail with a too small password', function (done) {
566 const data = {
567 username: 'myusername',
568 password: 'bla'
569 }
570
571 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
572 })
573
574 it('Should fail with a too long password', function (done) {
575 const data = {
576 username: 'myusername',
577 password: 'my super long password which is very very very very very very very very very very very very very very' +
578 'very very very very very very very very very very very very very very very veryv very very very very' +
579 'very very very very very very very very very very very very very very very very very very very very long'
580 }
581
582 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
583 })
584
585 it('Should fail with an non authenticated user', function (done) {
586 const data = {
587 username: 'myusername',
588 password: 'my super password'
589 }
590
591 requestsUtils.makePostBodyRequest(server.url, path, 'super token', data, done, 401)
592 })
593
594 it('Should fail if we add a user with the same username', function (done) {
595 const data = {
596 username: 'user1',
597 password: 'my super password'
598 }
599
600 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 409)
601 })
602
603 it('Should succeed with the correct params', function (done) {
604 const data = {
605 username: 'user2',
606 password: 'my super password'
607 }
608
609 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 204)
610 })
611
612 it('Should fail with a non admin user', function (done) {
613 server.user = {
614 username: 'user1',
615 password: 'password'
616 }
617
618 loginUtils.loginAndGetAccessToken(server, function (err, accessToken) {
619 if (err) throw err
620
621 userAccessToken = accessToken
622
623 const data = {
624 username: 'user3',
625 password: 'my super password'
626 }
627
628 requestsUtils.makePostBodyRequest(server.url, path, userAccessToken, data, done, 403)
629 })
630 })
631 })
632
633 describe('When updating a user', function () {
634 before(function (done) {
635 usersUtils.getUsersList(server.url, function (err, res) {
636 if (err) throw err
637
638 userId = res.body.data[1].id
639 rootId = res.body.data[2].id
640 done()
641 })
642 })
643
644 it('Should fail with a too small password', function (done) {
645 const data = {
646 password: 'bla'
647 }
648
649 requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done)
650 })
651
652 it('Should fail with a too long password', function (done) {
653 const data = {
654 password: 'my super long password which is very very very very very very very very very very very very very very' +
655 'very very very very very very very very very very very very very very very veryv very very very very' +
656 'very very very very very very very very very very very very very very very very very very very very long'
657 }
658
659 requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done)
660 })
661
662 it('Should fail with an non authenticated user', function (done) {
663 const data = {
664 password: 'my super password'
665 }
666
667 requestsUtils.makePutBodyRequest(server.url, path + userId, 'super token', data, done, 401)
668 })
669
670 it('Should succeed with the correct params', function (done) {
671 const data = {
672 password: 'my super password'
673 }
674
675 requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done, 204)
676 })
677 })
678
679 describe('When getting my information', function () {
680 it('Should fail with a non authenticated user', function (done) {
681 request(server.url)
682 .get(path + 'me')
683 .set('Authorization', 'Bearer faketoken')
684 .set('Accept', 'application/json')
685 .expect(401, done)
686 })
687
688 it('Should success with the correct parameters', function (done) {
689 request(server.url)
690 .get(path + 'me')
691 .set('Authorization', 'Bearer ' + userAccessToken)
692 .set('Accept', 'application/json')
693 .expect(200, done)
694 })
695 })
696
697 describe('When removing an user', function () {
698 it('Should fail with an incorrect id', function (done) {
699 request(server.url)
700 .delete(path + 'bla-bla')
701 .set('Authorization', 'Bearer ' + server.accessToken)
702 .expect(400, done)
703 })
704
705 it('Should fail with the root user', function (done) {
706 request(server.url)
707 .delete(path + rootId)
708 .set('Authorization', 'Bearer ' + server.accessToken)
709 .expect(400, done)
710 })
711
712 it('Should return 404 with a non existing id', function (done) {
713 request(server.url)
714 .delete(path + '579f982228c99c221d8092b8')
715 .set('Authorization', 'Bearer ' + server.accessToken)
716 .expect(404, done)
717 })
718 })
719 })
720
721 describe('Of the remote videos API', function () {
722 describe('When making a secure request', function () {
723 it('Should check a secure request')
724 })
725
726 describe('When adding a video', function () {
727 it('Should check when adding a video')
728 })
729
730 describe('When removing a video', function () {
731 it('Should check when removing a video')
732 })
733 })
734
735 describe('Of the requests API', function () {
736 const path = '/api/v1/requests/stats'
737
738 it('Should fail with an non authenticated user', function (done) {
739 request(server.url)
740 .get(path)
741 .set('Accept', 'application/json')
742 .expect(401, done)
743 })
744
745 it('Should fail with a non admin user', function (done) {
746 request(server.url)
747 .get(path)
748 .set('Authorization', 'Bearer ' + userAccessToken)
749 .set('Accept', 'application/json')
750 .expect(403, done)
751 })
752 })
753
754 after(function (done) {
755 process.kill(-server.app.pid)
756
757 // Keep the logs if the test failed
758 if (this.ok) {
759 serversUtils.flushTests(done)
760 } else {
761 done()
762 }
763 })
764})
diff --git a/server/tests/api/check-params/index.js b/server/tests/api/check-params/index.js
new file mode 100644
index 000000000..d0824f08a
--- /dev/null
+++ b/server/tests/api/check-params/index.js
@@ -0,0 +1,9 @@
1'use strict'
2
3// Order of the tests we want to execute
4require('./pods')
5require('./remotes')
6require('./users')
7require('./requests')
8require('./videos')
9require('./video-abuses')
diff --git a/server/tests/api/check-params/pods.js b/server/tests/api/check-params/pods.js
new file mode 100644
index 000000000..2f85af644
--- /dev/null
+++ b/server/tests/api/check-params/pods.js
@@ -0,0 +1,204 @@
1'use strict'
2
3const request = require('supertest')
4const series = require('async/series')
5
6const loginUtils = require('../../utils/login')
7const requestsUtils = require('../../utils/requests')
8const serversUtils = require('../../utils/servers')
9const usersUtils = require('../../utils/users')
10
11describe('Test pods API validators', function () {
12 const path = '/api/v1/pods/'
13 let server = null
14
15 // ---------------------------------------------------------------
16
17 before(function (done) {
18 this.timeout(20000)
19
20 series([
21 function (next) {
22 serversUtils.flushTests(next)
23 },
24 function (next) {
25 serversUtils.runServer(1, function (server1) {
26 server = server1
27
28 next()
29 })
30 },
31 function (next) {
32 loginUtils.loginAndGetAccessToken(server, function (err, token) {
33 if (err) throw err
34 server.accessToken = token
35
36 next()
37 })
38 }
39 ], done)
40 })
41
42 describe('When making friends', function () {
43 let userAccessToken = null
44
45 before(function (done) {
46 usersUtils.createUser(server.url, server.accessToken, 'user1', 'password', function () {
47 server.user = {
48 username: 'user1',
49 password: 'password'
50 }
51
52 loginUtils.loginAndGetAccessToken(server, function (err, accessToken) {
53 if (err) throw err
54
55 userAccessToken = accessToken
56
57 done()
58 })
59 })
60 })
61
62 describe('When making friends', function () {
63 const body = {
64 hosts: [ 'localhost:9002' ]
65 }
66
67 it('Should fail without hosts', function (done) {
68 request(server.url)
69 .post(path + '/makefriends')
70 .set('Authorization', 'Bearer ' + server.accessToken)
71 .set('Accept', 'application/json')
72 .expect(400, done)
73 })
74
75 it('Should fail if hosts is not an array', function (done) {
76 request(server.url)
77 .post(path + '/makefriends')
78 .send({ hosts: 'localhost:9002' })
79 .set('Authorization', 'Bearer ' + server.accessToken)
80 .set('Accept', 'application/json')
81 .expect(400, done)
82 })
83
84 it('Should fail if the array is not composed by hosts', function (done) {
85 request(server.url)
86 .post(path + '/makefriends')
87 .send({ hosts: [ 'localhost:9002', 'localhost:coucou' ] })
88 .set('Authorization', 'Bearer ' + server.accessToken)
89 .set('Accept', 'application/json')
90 .expect(400, done)
91 })
92
93 it('Should fail if the array is composed with http schemes', function (done) {
94 request(server.url)
95 .post(path + '/makefriends')
96 .send({ hosts: [ 'localhost:9002', 'http://localhost:9003' ] })
97 .set('Authorization', 'Bearer ' + server.accessToken)
98 .set('Accept', 'application/json')
99 .expect(400, done)
100 })
101
102 it('Should fail if hosts are not unique', function (done) {
103 request(server.url)
104 .post(path + '/makefriends')
105 .send({ urls: [ 'localhost:9002', 'localhost:9002' ] })
106 .set('Authorization', 'Bearer ' + server.accessToken)
107 .set('Accept', 'application/json')
108 .expect(400, done)
109 })
110
111 it('Should fail with a invalid token', function (done) {
112 request(server.url)
113 .post(path + '/makefriends')
114 .send(body)
115 .set('Authorization', 'Bearer faketoken')
116 .set('Accept', 'application/json')
117 .expect(401, done)
118 })
119
120 it('Should fail if the user is not an administrator', function (done) {
121 request(server.url)
122 .post(path + '/makefriends')
123 .send(body)
124 .set('Authorization', 'Bearer ' + userAccessToken)
125 .set('Accept', 'application/json')
126 .expect(403, done)
127 })
128 })
129
130 describe('When quitting friends', function () {
131 it('Should fail with a invalid token', function (done) {
132 request(server.url)
133 .get(path + '/quitfriends')
134 .query({ start: 'hello' })
135 .set('Authorization', 'Bearer faketoken')
136 .set('Accept', 'application/json')
137 .expect(401, done)
138 })
139
140 it('Should fail if the user is not an administrator', function (done) {
141 request(server.url)
142 .get(path + '/quitfriends')
143 .query({ start: 'hello' })
144 .set('Authorization', 'Bearer ' + userAccessToken)
145 .set('Accept', 'application/json')
146 .expect(403, done)
147 })
148 })
149 })
150
151 describe('When adding a pod', function () {
152 it('Should fail with nothing', function (done) {
153 const data = {}
154 requestsUtils.makePostBodyRequest(server.url, path, null, data, done)
155 })
156
157 it('Should fail without public key', function (done) {
158 const data = {
159 host: 'coucou.com'
160 }
161 requestsUtils.makePostBodyRequest(server.url, path, null, data, done)
162 })
163
164 it('Should fail without an host', function (done) {
165 const data = {
166 publicKey: 'mysuperpublickey'
167 }
168 requestsUtils.makePostBodyRequest(server.url, path, null, data, done)
169 })
170
171 it('Should fail with an incorrect host', function (done) {
172 const data = {
173 host: 'http://coucou.com',
174 publicKey: 'mysuperpublickey'
175 }
176 requestsUtils.makePostBodyRequest(server.url, path, null, data, function () {
177 data.host = 'http://coucou'
178 requestsUtils.makePostBodyRequest(server.url, path, null, data, function () {
179 data.host = 'coucou'
180 requestsUtils.makePostBodyRequest(server.url, path, null, data, done)
181 })
182 })
183 })
184
185 it('Should succeed with the correct parameters', function (done) {
186 const data = {
187 host: 'coucou.com',
188 publicKey: 'mysuperpublickey'
189 }
190 requestsUtils.makePostBodyRequest(server.url, path, null, data, done, 200)
191 })
192 })
193
194 after(function (done) {
195 process.kill(-server.app.pid)
196
197 // Keep the logs if the test failed
198 if (this.ok) {
199 serversUtils.flushTests(done)
200 } else {
201 done()
202 }
203 })
204})
diff --git a/server/tests/api/check-params/remotes.js b/server/tests/api/check-params/remotes.js
new file mode 100644
index 000000000..c1ab9fb2b
--- /dev/null
+++ b/server/tests/api/check-params/remotes.js
@@ -0,0 +1,64 @@
1'use strict'
2
3const series = require('async/series')
4
5const loginUtils = require('../../utils/login')
6const serversUtils = require('../../utils/servers')
7
8describe('Test remote videos API validators', function () {
9 let server = null
10
11 // ---------------------------------------------------------------
12
13 before(function (done) {
14 this.timeout(20000)
15
16 series([
17 function (next) {
18 serversUtils.flushTests(next)
19 },
20 function (next) {
21 serversUtils.runServer(1, function (server1) {
22 server = server1
23
24 next()
25 })
26 },
27 function (next) {
28 loginUtils.loginAndGetAccessToken(server, function (err, token) {
29 if (err) throw err
30 server.accessToken = token
31
32 next()
33 })
34 }
35 ], done)
36 })
37
38 describe('When making a secure request', function () {
39 it('Should check a secure request')
40 })
41
42 describe('When adding a video', function () {
43 it('Should check when adding a video')
44 })
45
46 describe('When removing a video', function () {
47 it('Should check when removing a video')
48 })
49
50 describe('When reporting abuse on a video', function () {
51 it('Should check when reporting a video abuse')
52 })
53
54 after(function (done) {
55 process.kill(-server.app.pid)
56
57 // Keep the logs if the test failed
58 if (this.ok) {
59 serversUtils.flushTests(done)
60 } else {
61 done()
62 }
63 })
64})
diff --git a/server/tests/api/check-params/requests.js b/server/tests/api/check-params/requests.js
new file mode 100644
index 000000000..08f58db43
--- /dev/null
+++ b/server/tests/api/check-params/requests.js
@@ -0,0 +1,87 @@
1'use strict'
2
3const request = require('supertest')
4const series = require('async/series')
5
6const loginUtils = require('../../utils/login')
7const usersUtils = require('../../utils/users')
8const serversUtils = require('../../utils/servers')
9
10describe('Test requests API validators', function () {
11 const path = '/api/v1/requests/stats'
12 let server = null
13 let userAccessToken = null
14
15 // ---------------------------------------------------------------
16
17 before(function (done) {
18 this.timeout(20000)
19
20 series([
21 function (next) {
22 serversUtils.flushTests(next)
23 },
24 function (next) {
25 serversUtils.runServer(1, function (server1) {
26 server = server1
27
28 next()
29 })
30 },
31 function (next) {
32 loginUtils.loginAndGetAccessToken(server, function (err, token) {
33 if (err) throw err
34 server.accessToken = token
35
36 next()
37 })
38 },
39 function (next) {
40 const username = 'user'
41 const password = 'my super password'
42
43 usersUtils.createUser(server.url, server.accessToken, username, password, next)
44 },
45 function (next) {
46 const user = {
47 username: 'user',
48 password: 'my super password'
49 }
50
51 loginUtils.getUserAccessToken(server, user, function (err, accessToken) {
52 if (err) throw err
53
54 userAccessToken = accessToken
55
56 next()
57 })
58 }
59 ], done)
60 })
61
62 it('Should fail with an non authenticated user', function (done) {
63 request(server.url)
64 .get(path)
65 .set('Accept', 'application/json')
66 .expect(401, done)
67 })
68
69 it('Should fail with a non admin user', function (done) {
70 request(server.url)
71 .get(path)
72 .set('Authorization', 'Bearer ' + userAccessToken)
73 .set('Accept', 'application/json')
74 .expect(403, done)
75 })
76
77 after(function (done) {
78 process.kill(-server.app.pid)
79
80 // Keep the logs if the test failed
81 if (this.ok) {
82 serversUtils.flushTests(done)
83 } else {
84 done()
85 }
86 })
87})
diff --git a/server/tests/api/check-params/users.js b/server/tests/api/check-params/users.js
new file mode 100644
index 000000000..c1fcf34a4
--- /dev/null
+++ b/server/tests/api/check-params/users.js
@@ -0,0 +1,284 @@
1'use strict'
2
3const request = require('supertest')
4const series = require('async/series')
5
6const loginUtils = require('../../utils/login')
7const requestsUtils = require('../../utils/requests')
8const serversUtils = require('../../utils/servers')
9const usersUtils = require('../../utils/users')
10
11describe('Test users API validators', function () {
12 const path = '/api/v1/users/'
13 let userId = null
14 let rootId = null
15 let server = null
16 let userAccessToken = null
17
18 // ---------------------------------------------------------------
19
20 before(function (done) {
21 this.timeout(20000)
22
23 series([
24 function (next) {
25 serversUtils.flushTests(next)
26 },
27 function (next) {
28 serversUtils.runServer(1, function (server1) {
29 server = server1
30
31 next()
32 })
33 },
34 function (next) {
35 loginUtils.loginAndGetAccessToken(server, function (err, token) {
36 if (err) throw err
37 server.accessToken = token
38
39 next()
40 })
41 },
42 function (next) {
43 const username = 'user1'
44 const password = 'my super password'
45
46 usersUtils.createUser(server.url, server.accessToken, username, password, next)
47 },
48 function (next) {
49 const user = {
50 username: 'user1',
51 password: 'my super password'
52 }
53
54 loginUtils.getUserAccessToken(server, user, function (err, accessToken) {
55 if (err) throw err
56
57 userAccessToken = accessToken
58
59 next()
60 })
61 }
62 ], done)
63 })
64
65 describe('When listing users', function () {
66 it('Should fail with a bad start pagination', function (done) {
67 request(server.url)
68 .get(path)
69 .query({ start: 'hello' })
70 .set('Accept', 'application/json')
71 .expect(400, done)
72 })
73
74 it('Should fail with a bad count pagination', function (done) {
75 request(server.url)
76 .get(path)
77 .query({ count: 'hello' })
78 .set('Accept', 'application/json')
79 .expect(400, done)
80 })
81
82 it('Should fail with an incorrect sort', function (done) {
83 request(server.url)
84 .get(path)
85 .query({ sort: 'hello' })
86 .set('Accept', 'application/json')
87 .expect(400, done)
88 })
89 })
90
91 describe('When adding a new user', function () {
92 it('Should fail with a too small username', function (done) {
93 const data = {
94 username: 'ji',
95 password: 'mysuperpassword'
96 }
97
98 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
99 })
100
101 it('Should fail with a too long username', function (done) {
102 const data = {
103 username: 'mysuperusernamewhichisverylong',
104 password: 'mysuperpassword'
105 }
106
107 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
108 })
109
110 it('Should fail with an incorrect username', function (done) {
111 const data = {
112 username: 'my username',
113 password: 'mysuperpassword'
114 }
115
116 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
117 })
118
119 it('Should fail with a too small password', function (done) {
120 const data = {
121 username: 'myusername',
122 password: 'bla'
123 }
124
125 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
126 })
127
128 it('Should fail with a too long password', function (done) {
129 const data = {
130 username: 'myusername',
131 password: 'my super long password which is very very very very very very very very very very very very very very' +
132 'very very very very very very very very very very very very very very very veryv very very very very' +
133 'very very very very very very very very very very very very very very very very very very very very long'
134 }
135
136 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
137 })
138
139 it('Should fail with an non authenticated user', function (done) {
140 const data = {
141 username: 'myusername',
142 password: 'my super password'
143 }
144
145 requestsUtils.makePostBodyRequest(server.url, path, 'super token', data, done, 401)
146 })
147
148 it('Should fail if we add a user with the same username', function (done) {
149 const data = {
150 username: 'user1',
151 password: 'my super password'
152 }
153
154 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 409)
155 })
156
157 it('Should succeed with the correct params', function (done) {
158 const data = {
159 username: 'user2',
160 password: 'my super password'
161 }
162
163 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 204)
164 })
165
166 it('Should fail with a non admin user', function (done) {
167 server.user = {
168 username: 'user1',
169 password: 'my super password'
170 }
171
172 loginUtils.loginAndGetAccessToken(server, function (err, accessToken) {
173 if (err) throw err
174
175 userAccessToken = accessToken
176
177 const data = {
178 username: 'user3',
179 password: 'my super password'
180 }
181
182 requestsUtils.makePostBodyRequest(server.url, path, userAccessToken, data, done, 403)
183 })
184 })
185 })
186
187 describe('When updating a user', function () {
188 before(function (done) {
189 usersUtils.getUsersList(server.url, function (err, res) {
190 if (err) throw err
191
192 userId = res.body.data[1].id
193 rootId = res.body.data[2].id
194 done()
195 })
196 })
197
198 it('Should fail with a too small password', function (done) {
199 const data = {
200 password: 'bla'
201 }
202
203 requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done)
204 })
205
206 it('Should fail with a too long password', function (done) {
207 const data = {
208 password: 'my super long password which is very very very very very very very very very very very very very very' +
209 'very very very very very very very very very very very very very very very veryv very very very very' +
210 'very very very very very very very very very very very very very very very very very very very very long'
211 }
212
213 requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done)
214 })
215
216 it('Should fail with an non authenticated user', function (done) {
217 const data = {
218 password: 'my super password'
219 }
220
221 requestsUtils.makePutBodyRequest(server.url, path + userId, 'super token', data, done, 401)
222 })
223
224 it('Should succeed with the correct params', function (done) {
225 const data = {
226 password: 'my super password'
227 }
228
229 requestsUtils.makePutBodyRequest(server.url, path + userId, userAccessToken, data, done, 204)
230 })
231 })
232
233 describe('When getting my information', function () {
234 it('Should fail with a non authenticated user', function (done) {
235 request(server.url)
236 .get(path + 'me')
237 .set('Authorization', 'Bearer faketoken')
238 .set('Accept', 'application/json')
239 .expect(401, done)
240 })
241
242 it('Should success with the correct parameters', function (done) {
243 request(server.url)
244 .get(path + 'me')
245 .set('Authorization', 'Bearer ' + userAccessToken)
246 .set('Accept', 'application/json')
247 .expect(200, done)
248 })
249 })
250
251 describe('When removing an user', function () {
252 it('Should fail with an incorrect id', function (done) {
253 request(server.url)
254 .delete(path + 'bla-bla')
255 .set('Authorization', 'Bearer ' + server.accessToken)
256 .expect(400, done)
257 })
258
259 it('Should fail with the root user', function (done) {
260 request(server.url)
261 .delete(path + rootId)
262 .set('Authorization', 'Bearer ' + server.accessToken)
263 .expect(400, done)
264 })
265
266 it('Should return 404 with a non existing id', function (done) {
267 request(server.url)
268 .delete(path + '45')
269 .set('Authorization', 'Bearer ' + server.accessToken)
270 .expect(404, done)
271 })
272 })
273
274 after(function (done) {
275 process.kill(-server.app.pid)
276
277 // Keep the logs if the test failed
278 if (this.ok) {
279 serversUtils.flushTests(done)
280 } else {
281 done()
282 }
283 })
284})
diff --git a/server/tests/api/check-params/video-abuses.js b/server/tests/api/check-params/video-abuses.js
new file mode 100644
index 000000000..8cb4ccdc1
--- /dev/null
+++ b/server/tests/api/check-params/video-abuses.js
@@ -0,0 +1,180 @@
1'use strict'
2
3const request = require('supertest')
4const series = require('async/series')
5
6const loginUtils = require('../../utils/login')
7const requestsUtils = require('../../utils/requests')
8const serversUtils = require('../../utils/servers')
9const usersUtils = require('../../utils/users')
10const videosUtils = require('../../utils/videos')
11
12describe('Test video abuses API validators', function () {
13 let server = null
14 let userAccessToken = null
15
16 // ---------------------------------------------------------------
17
18 before(function (done) {
19 this.timeout(20000)
20
21 series([
22 function (next) {
23 serversUtils.flushTests(next)
24 },
25 function (next) {
26 serversUtils.runServer(1, function (server1) {
27 server = server1
28
29 next()
30 })
31 },
32 function (next) {
33 loginUtils.loginAndGetAccessToken(server, function (err, token) {
34 if (err) throw err
35 server.accessToken = token
36
37 next()
38 })
39 },
40 function (next) {
41 const username = 'user1'
42 const password = 'my super password'
43
44 usersUtils.createUser(server.url, server.accessToken, username, password, next)
45 },
46 function (next) {
47 const user = {
48 username: 'user1',
49 password: 'my super password'
50 }
51
52 loginUtils.getUserAccessToken(server, user, function (err, accessToken) {
53 if (err) throw err
54
55 userAccessToken = accessToken
56
57 next()
58 })
59 },
60 // Upload some videos on each pods
61 function (next) {
62 const name = 'my super name for pod'
63 const description = 'my super description for pod'
64 const tags = [ 'tag' ]
65 const file = 'video_short2.webm'
66 videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, file, next)
67 },
68 function (next) {
69 videosUtils.getVideosList(server.url, function (err, res) {
70 if (err) throw err
71
72 const videos = res.body.data
73 server.video = videos[0]
74
75 next()
76 })
77 }
78 ], done)
79 })
80
81 describe('When listing video abuses', function () {
82 const path = '/api/v1/videos/abuse'
83
84 it('Should fail with a bad start pagination', function (done) {
85 request(server.url)
86 .get(path)
87 .query({ start: 'hello' })
88 .set('Authorization', 'Bearer ' + server.accessToken)
89 .set('Accept', 'application/json')
90 .expect(400, done)
91 })
92
93 it('Should fail with a bad count pagination', function (done) {
94 request(server.url)
95 .get(path)
96 .query({ count: 'hello' })
97 .set('Accept', 'application/json')
98 .set('Authorization', 'Bearer ' + server.accessToken)
99 .expect(400, done)
100 })
101
102 it('Should fail with an incorrect sort', function (done) {
103 request(server.url)
104 .get(path)
105 .query({ sort: 'hello' })
106 .set('Accept', 'application/json')
107 .set('Authorization', 'Bearer ' + server.accessToken)
108 .expect(400, done)
109 })
110
111 it('Should fail with a non authenticated user', function (done) {
112 request(server.url)
113 .get(path)
114 .query({ sort: 'hello' })
115 .set('Accept', 'application/json')
116 .expect(401, done)
117 })
118
119 it('Should fail with a non admin user', function (done) {
120 request(server.url)
121 .get(path)
122 .query({ sort: 'hello' })
123 .set('Accept', 'application/json')
124 .set('Authorization', 'Bearer ' + userAccessToken)
125 .expect(403, done)
126 })
127 })
128
129 describe('When reporting a video abuse', function () {
130 const basePath = '/api/v1/videos/'
131
132 it('Should fail with nothing', function (done) {
133 const path = basePath + server.video + '/abuse'
134 const data = {}
135 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
136 })
137
138 it('Should fail with a wrong video', function (done) {
139 const wrongPath = '/api/v1/videos/blabla/abuse'
140 const data = {}
141 requestsUtils.makePostBodyRequest(server.url, wrongPath, server.accessToken, data, done)
142 })
143
144 it('Should fail with a non authenticated user', function (done) {
145 const data = {}
146 const path = basePath + server.video + '/abuse'
147 requestsUtils.makePostBodyRequest(server.url, path, 'hello', data, done, 401)
148 })
149
150 it('Should fail with a reason too short', function (done) {
151 const data = {
152 reason: 'h'
153 }
154 const path = basePath + server.video + '/abuse'
155 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
156 })
157
158 it('Should fail with a reason too big', function (done) {
159 const data = {
160 reason: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
161 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
162 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
163 '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
164 }
165 const path = basePath + server.video + '/abuse'
166 requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
167 })
168 })
169
170 after(function (done) {
171 process.kill(-server.app.pid)
172
173 // Keep the logs if the test failed
174 if (this.ok) {
175 serversUtils.flushTests(done)
176 } else {
177 done()
178 }
179 })
180})
diff --git a/server/tests/api/check-params/videos.js b/server/tests/api/check-params/videos.js
new file mode 100644
index 000000000..fac903715
--- /dev/null
+++ b/server/tests/api/check-params/videos.js
@@ -0,0 +1,460 @@
1'use strict'
2
3const chai = require('chai')
4const expect = chai.expect
5const pathUtils = require('path')
6const request = require('supertest')
7const series = require('async/series')
8
9const loginUtils = require('../../utils/login')
10const requestsUtils = require('../../utils/requests')
11const serversUtils = require('../../utils/servers')
12const videosUtils = require('../../utils/videos')
13
14describe('Test videos API validator', function () {
15 const path = '/api/v1/videos/'
16 let server = null
17
18 // ---------------------------------------------------------------
19
20 before(function (done) {
21 this.timeout(20000)
22
23 series([
24 function (next) {
25 serversUtils.flushTests(next)
26 },
27 function (next) {
28 serversUtils.runServer(1, function (server1) {
29 server = server1
30
31 next()
32 })
33 },
34 function (next) {
35 loginUtils.loginAndGetAccessToken(server, function (err, token) {
36 if (err) throw err
37 server.accessToken = token
38
39 next()
40 })
41 }
42 ], done)
43 })
44
45 describe('When listing a video', function () {
46 it('Should fail with a bad start pagination', function (done) {
47 request(server.url)
48 .get(path)
49 .query({ start: 'hello' })
50 .set('Accept', 'application/json')
51 .expect(400, done)
52 })
53
54 it('Should fail with a bad count pagination', function (done) {
55 request(server.url)
56 .get(path)
57 .query({ count: 'hello' })
58 .set('Accept', 'application/json')
59 .expect(400, done)
60 })
61
62 it('Should fail with an incorrect sort', function (done) {
63 request(server.url)
64 .get(path)
65 .query({ sort: 'hello' })
66 .set('Accept', 'application/json')
67 .expect(400, done)
68 })
69 })
70
71 describe('When searching a video', function () {
72 it('Should fail with nothing', function (done) {
73 request(server.url)
74 .get(pathUtils.join(path, 'search'))
75 .set('Accept', 'application/json')
76 .expect(400, done)
77 })
78
79 it('Should fail with a bad start pagination', function (done) {
80 request(server.url)
81 .get(pathUtils.join(path, 'search', 'test'))
82 .query({ start: 'hello' })
83 .set('Accept', 'application/json')
84 .expect(400, done)
85 })
86
87 it('Should fail with a bad count pagination', function (done) {
88 request(server.url)
89 .get(pathUtils.join(path, 'search', 'test'))
90 .query({ count: 'hello' })
91 .set('Accept', 'application/json')
92 .expect(400, done)
93 })
94
95 it('Should fail with an incorrect sort', function (done) {
96 request(server.url)
97 .get(pathUtils.join(path, 'search', 'test'))
98 .query({ sort: 'hello' })
99 .set('Accept', 'application/json')
100 .expect(400, done)
101 })
102 })
103
104 describe('When adding a video', function () {
105 it('Should fail with nothing', function (done) {
106 const data = {}
107 const attach = {}
108 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
109 })
110
111 it('Should fail without name', function (done) {
112 const data = {
113 description: 'my super description',
114 tags: [ 'tag1', 'tag2' ]
115 }
116 const attach = {
117 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
118 }
119 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
120 })
121
122 it('Should fail with a long name', function (done) {
123 const data = {
124 name: 'My very very very very very very very very very very very very very very very very long name',
125 description: 'my super description',
126 tags: [ 'tag1', 'tag2' ]
127 }
128 const attach = {
129 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
130 }
131 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
132 })
133
134 it('Should fail without description', function (done) {
135 const data = {
136 name: 'my super name',
137 tags: [ 'tag1', 'tag2' ]
138 }
139 const attach = {
140 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
141 }
142 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
143 })
144
145 it('Should fail with a long description', function (done) {
146 const data = {
147 name: 'my super name',
148 description: 'my super description which is very very very very very very very very very very very very very very' +
149 'very very very very very very very very very very very very very very very very very very very very very' +
150 'very very very very very very very very very very very very very very very long',
151 tags: [ 'tag1', 'tag2' ]
152 }
153 const attach = {
154 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
155 }
156 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
157 })
158
159 it('Should fail without tags', function (done) {
160 const data = {
161 name: 'my super name',
162 description: 'my super description'
163 }
164 const attach = {
165 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
166 }
167 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
168 })
169
170 it('Should fail with too many tags', function (done) {
171 const data = {
172 name: 'my super name',
173 description: 'my super description',
174 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
175 }
176 const attach = {
177 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
178 }
179 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
180 })
181
182 it('Should fail with not enough tags', function (done) {
183 const data = {
184 name: 'my super name',
185 description: 'my super description',
186 tags: [ ]
187 }
188 const attach = {
189 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
190 }
191 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
192 })
193
194 it('Should fail with a tag length too low', function (done) {
195 const data = {
196 name: 'my super name',
197 description: 'my super description',
198 tags: [ 'tag1', 't' ]
199 }
200 const attach = {
201 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
202 }
203 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
204 })
205
206 it('Should fail with a tag length too big', function (done) {
207 const data = {
208 name: 'my super name',
209 description: 'my super description',
210 tags: [ 'mysupertagtoolong', 'tag1' ]
211 }
212 const attach = {
213 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
214 }
215 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
216 })
217
218 it('Should fail with malformed tags', function (done) {
219 const data = {
220 name: 'my super name',
221 description: 'my super description',
222 tags: [ 'my tag' ]
223 }
224 const attach = {
225 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
226 }
227 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
228 })
229
230 it('Should fail without an input file', function (done) {
231 const data = {
232 name: 'my super name',
233 description: 'my super description',
234 tags: [ 'tag1', 'tag2' ]
235 }
236 const attach = {}
237 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
238 })
239
240 it('Should fail without an incorrect input file', function (done) {
241 const data = {
242 name: 'my super name',
243 description: 'my super description',
244 tags: [ 'tag1', 'tag2' ]
245 }
246 const attach = {
247 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
248 }
249 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
250 })
251
252 it('Should fail with a too big duration', function (done) {
253 const data = {
254 name: 'my super name',
255 description: 'my super description',
256 tags: [ 'tag1', 'tag2' ]
257 }
258 const attach = {
259 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_too_long.webm')
260 }
261 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
262 })
263
264 it('Should succeed with the correct parameters', function (done) {
265 const data = {
266 name: 'my super name',
267 description: 'my super description',
268 tags: [ 'tag1', 'tag2' ]
269 }
270 const attach = {
271 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
272 }
273 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () {
274 attach.videofile = pathUtils.join(__dirname, '..', 'fixtures', 'video_short.mp4')
275 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () {
276 attach.videofile = pathUtils.join(__dirname, '..', 'fixtures', 'video_short.ogv')
277 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done, 204)
278 }, false)
279 }, false)
280 })
281 })
282
283 describe('When updating a video', function () {
284 let videoId
285
286 before(function (done) {
287 videosUtils.getVideosList(server.url, function (err, res) {
288 if (err) throw err
289
290 videoId = res.body.data[0].id
291
292 return done()
293 })
294 })
295
296 it('Should fail with nothing', function (done) {
297 const data = {}
298 requestsUtils.makePutBodyRequest(server.url, path, server.accessToken, data, done)
299 })
300
301 it('Should fail without a valid uuid', function (done) {
302 const data = {
303 description: 'my super description',
304 tags: [ 'tag1', 'tag2' ]
305 }
306 requestsUtils.makePutBodyRequest(server.url, path + 'blabla', server.accessToken, data, done)
307 })
308
309 it('Should fail with an unknown id', function (done) {
310 const data = {
311 description: 'my super description',
312 tags: [ 'tag1', 'tag2' ]
313 }
314 requestsUtils.makePutBodyRequest(server.url, path + '4da6fde3-88f7-4d16-b119-108df5630b06', server.accessToken, data, done, 404)
315 })
316
317 it('Should fail with a long name', function (done) {
318 const data = {
319 name: 'My very very very very very very very very very very very very very very very very long name',
320 description: 'my super description',
321 tags: [ 'tag1', 'tag2' ]
322 }
323 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
324 })
325
326 it('Should fail with a long description', function (done) {
327 const data = {
328 name: 'my super name',
329 description: 'my super description which is very very very very very very very very very very very very very very' +
330 'very very very very very very very very very very very very very very very very very very very very very' +
331 'very very very very very very very very very very very very very very very long',
332 tags: [ 'tag1', 'tag2' ]
333 }
334 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
335 })
336
337 it('Should fail with too many tags', function (done) {
338 const data = {
339 name: 'my super name',
340 description: 'my super description',
341 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
342 }
343 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
344 })
345
346 it('Should fail with not enough tags', function (done) {
347 const data = {
348 name: 'my super name',
349 description: 'my super description',
350 tags: [ ]
351 }
352 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
353 })
354
355 it('Should fail with a tag length too low', function (done) {
356 const data = {
357 name: 'my super name',
358 description: 'my super description',
359 tags: [ 'tag1', 't' ]
360 }
361 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
362 })
363
364 it('Should fail with a tag length too big', function (done) {
365 const data = {
366 name: 'my super name',
367 description: 'my super description',
368 tags: [ 'mysupertagtoolong', 'tag1' ]
369 }
370 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
371 })
372
373 it('Should fail with malformed tags', function (done) {
374 const data = {
375 name: 'my super name',
376 description: 'my super description',
377 tags: [ 'my tag' ]
378 }
379 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
380 })
381
382 it('Should fail with a video of another user')
383
384 it('Should fail with a video of another pod')
385 })
386
387 describe('When getting a video', function () {
388 it('Should return the list of the videos with nothing', function (done) {
389 request(server.url)
390 .get(path)
391 .set('Accept', 'application/json')
392 .expect(200)
393 .expect('Content-Type', /json/)
394 .end(function (err, res) {
395 if (err) throw err
396
397 expect(res.body.data).to.be.an('array')
398 expect(res.body.data.length).to.equal(3)
399
400 done()
401 })
402 })
403
404 it('Should fail without a correct uuid', function (done) {
405 request(server.url)
406 .get(path + 'coucou')
407 .set('Accept', 'application/json')
408 .expect(400, done)
409 })
410
411 it('Should return 404 with an incorrect video', function (done) {
412 request(server.url)
413 .get(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
414 .set('Accept', 'application/json')
415 .expect(404, done)
416 })
417
418 it('Should succeed with the correct parameters')
419 })
420
421 describe('When removing a video', function () {
422 it('Should have 404 with nothing', function (done) {
423 request(server.url)
424 .delete(path)
425 .set('Authorization', 'Bearer ' + server.accessToken)
426 .expect(400, done)
427 })
428
429 it('Should fail without a correct uuid', function (done) {
430 request(server.url)
431 .delete(path + 'hello')
432 .set('Authorization', 'Bearer ' + server.accessToken)
433 .expect(400, done)
434 })
435
436 it('Should fail with a video which does not exist', function (done) {
437 request(server.url)
438 .delete(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
439 .set('Authorization', 'Bearer ' + server.accessToken)
440 .expect(404, done)
441 })
442
443 it('Should fail with a video of another user')
444
445 it('Should fail with a video of another pod')
446
447 it('Should succeed with the correct parameters')
448 })
449
450 after(function (done) {
451 process.kill(-server.app.pid)
452
453 // Keep the logs if the test failed
454 if (this.ok) {
455 serversUtils.flushTests(done)
456 } else {
457 done()
458 }
459 })
460})
diff --git a/server/tests/api/friends-advanced.js b/server/tests/api/friends-advanced.js
index 0a2d58d82..708138bc9 100644
--- a/server/tests/api/friends-advanced.js
+++ b/server/tests/api/friends-advanced.js
@@ -86,7 +86,7 @@ describe('Test advanced friends', function () {
86 getFriendsList(5, function (err, res) { 86 getFriendsList(5, function (err, res) {
87 if (err) throw err 87 if (err) throw err
88 88
89 expect(res.body.length).to.equal(0) 89 expect(res.body.data.length).to.equal(0)
90 90
91 done() 91 done()
92 }) 92 })
@@ -111,7 +111,7 @@ describe('Test advanced friends', function () {
111 getFriendsList(i, function (err, res) { 111 getFriendsList(i, function (err, res) {
112 if (err) throw err 112 if (err) throw err
113 113
114 expect(res.body.length).to.equal(0) 114 expect(res.body.data.length).to.equal(0)
115 115
116 callback() 116 callback()
117 }) 117 })
@@ -140,7 +140,7 @@ describe('Test advanced friends', function () {
140 getFriendsList(i, function (err, res) { 140 getFriendsList(i, function (err, res) {
141 if (err) throw err 141 if (err) throw err
142 142
143 expect(res.body.length).to.equal(3) 143 expect(res.body.data.length).to.equal(3)
144 144
145 callback() 145 callback()
146 }) 146 })
@@ -182,7 +182,7 @@ describe('Test advanced friends', function () {
182 if (err) throw err 182 if (err) throw err
183 183
184 // Pod 4 didn't know pod 1 and 2 removed it 184 // Pod 4 didn't know pod 1 and 2 removed it
185 expect(res.body.length).to.equal(3) 185 expect(res.body.data.length).to.equal(3)
186 next() 186 next()
187 }) 187 })
188 }, 188 },
@@ -200,7 +200,7 @@ describe('Test advanced friends', function () {
200 if (err) throw err 200 if (err) throw err
201 201
202 // Pod 4 should not be our friend 202 // Pod 4 should not be our friend
203 const result = res.body 203 const result = res.body.data
204 expect(result.length).to.equal(3) 204 expect(result.length).to.equal(3)
205 for (const pod of result) { 205 for (const pod of result) {
206 expect(pod.host).not.equal(servers[3].host) 206 expect(pod.host).not.equal(servers[3].host)
diff --git a/server/tests/api/friends-basic.js b/server/tests/api/friends-basic.js
index a871f9838..6f37ff291 100644
--- a/server/tests/api/friends-basic.js
+++ b/server/tests/api/friends-basic.js
@@ -28,7 +28,7 @@ describe('Test basic friends', function () {
28 podsUtils.getFriendsList(serverToTest.url, function (err, res) { 28 podsUtils.getFriendsList(serverToTest.url, function (err, res) {
29 if (err) throw err 29 if (err) throw err
30 30
31 const result = res.body 31 const result = res.body.data
32 expect(result).to.be.an('array') 32 expect(result).to.be.an('array')
33 expect(result.length).to.equal(2) 33 expect(result.length).to.equal(2)
34 34
@@ -65,7 +65,7 @@ describe('Test basic friends', function () {
65 podsUtils.getFriendsList(server.url, function (err, res) { 65 podsUtils.getFriendsList(server.url, function (err, res) {
66 if (err) throw err 66 if (err) throw err
67 67
68 const result = res.body 68 const result = res.body.data
69 expect(result).to.be.an('array') 69 expect(result).to.be.an('array')
70 expect(result.length).to.equal(0) 70 expect(result.length).to.equal(0)
71 callback() 71 callback()
@@ -90,14 +90,14 @@ describe('Test basic friends', function () {
90 podsUtils.getFriendsList(servers[1].url, function (err, res) { 90 podsUtils.getFriendsList(servers[1].url, function (err, res) {
91 if (err) throw err 91 if (err) throw err
92 92
93 const result = res.body 93 const result = res.body.data
94 expect(result).to.be.an('array') 94 expect(result).to.be.an('array')
95 expect(result.length).to.equal(1) 95 expect(result.length).to.equal(1)
96 96
97 const pod = result[0] 97 const pod = result[0]
98 expect(pod.host).to.equal(servers[2].host) 98 expect(pod.host).to.equal(servers[2].host)
99 expect(pod.score).to.equal(20) 99 expect(pod.score).to.equal(20)
100 expect(miscsUtils.dateIsValid(pod.createdDate)).to.be.true 100 expect(miscsUtils.dateIsValid(pod.createdAt)).to.be.true
101 101
102 next() 102 next()
103 }) 103 })
@@ -107,14 +107,14 @@ describe('Test basic friends', function () {
107 podsUtils.getFriendsList(servers[2].url, function (err, res) { 107 podsUtils.getFriendsList(servers[2].url, function (err, res) {
108 if (err) throw err 108 if (err) throw err
109 109
110 const result = res.body 110 const result = res.body.data
111 expect(result).to.be.an('array') 111 expect(result).to.be.an('array')
112 expect(result.length).to.equal(1) 112 expect(result.length).to.equal(1)
113 113
114 const pod = result[0] 114 const pod = result[0]
115 expect(pod.host).to.equal(servers[1].host) 115 expect(pod.host).to.equal(servers[1].host)
116 expect(pod.score).to.equal(20) 116 expect(pod.score).to.equal(20)
117 expect(miscsUtils.dateIsValid(pod.createdDate)).to.be.true 117 expect(miscsUtils.dateIsValid(pod.createdAt)).to.be.true
118 118
119 next() 119 next()
120 }) 120 })
@@ -154,7 +154,7 @@ describe('Test basic friends', function () {
154 podsUtils.getFriendsList(servers[1].url, function (err, res) { 154 podsUtils.getFriendsList(servers[1].url, function (err, res) {
155 if (err) throw err 155 if (err) throw err
156 156
157 const result = res.body 157 const result = res.body.data
158 expect(result).to.be.an('array') 158 expect(result).to.be.an('array')
159 expect(result.length).to.equal(0) 159 expect(result.length).to.equal(0)
160 160
@@ -167,7 +167,7 @@ describe('Test basic friends', function () {
167 podsUtils.getFriendsList(url, function (err, res) { 167 podsUtils.getFriendsList(url, function (err, res) {
168 if (err) throw err 168 if (err) throw err
169 169
170 const result = res.body 170 const result = res.body.data
171 expect(result).to.be.an('array') 171 expect(result).to.be.an('array')
172 expect(result.length).to.equal(1) 172 expect(result.length).to.equal(1)
173 expect(result[0].host).not.to.be.equal(servers[1].host) 173 expect(result[0].host).not.to.be.equal(servers[1].host)
diff --git a/server/tests/api/multiple-pods.js b/server/tests/api/multiple-pods.js
index be278d7c5..df12ba0e9 100644
--- a/server/tests/api/multiple-pods.js
+++ b/server/tests/api/multiple-pods.js
@@ -4,7 +4,8 @@ const chai = require('chai')
4const each = require('async/each') 4const each = require('async/each')
5const expect = chai.expect 5const expect = chai.expect
6const series = require('async/series') 6const series = require('async/series')
7const webtorrent = new (require('webtorrent'))() 7const WebTorrent = require('webtorrent')
8const webtorrent = new WebTorrent()
8 9
9const loginUtils = require('../utils/login') 10const loginUtils = require('../utils/login')
10const miscsUtils = require('../utils/miscs') 11const miscsUtils = require('../utils/miscs')
@@ -104,7 +105,8 @@ describe('Test multiple pods', function () {
104 expect(video.magnetUri).to.exist 105 expect(video.magnetUri).to.exist
105 expect(video.duration).to.equal(10) 106 expect(video.duration).to.equal(10)
106 expect(video.tags).to.deep.equal([ 'tag1p1', 'tag2p1' ]) 107 expect(video.tags).to.deep.equal([ 'tag1p1', 'tag2p1' ])
107 expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true 108 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
109 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
108 expect(video.author).to.equal('root') 110 expect(video.author).to.equal('root')
109 111
110 if (server.url !== 'http://localhost:9001') { 112 if (server.url !== 'http://localhost:9001') {
@@ -166,7 +168,8 @@ describe('Test multiple pods', function () {
166 expect(video.magnetUri).to.exist 168 expect(video.magnetUri).to.exist
167 expect(video.duration).to.equal(5) 169 expect(video.duration).to.equal(5)
168 expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ]) 170 expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ])
169 expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true 171 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
172 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
170 expect(video.author).to.equal('root') 173 expect(video.author).to.equal('root')
171 174
172 if (server.url !== 'http://localhost:9002') { 175 if (server.url !== 'http://localhost:9002') {
@@ -246,7 +249,8 @@ describe('Test multiple pods', function () {
246 expect(video1.duration).to.equal(5) 249 expect(video1.duration).to.equal(5)
247 expect(video1.tags).to.deep.equal([ 'tag1p3' ]) 250 expect(video1.tags).to.deep.equal([ 'tag1p3' ])
248 expect(video1.author).to.equal('root') 251 expect(video1.author).to.equal('root')
249 expect(miscsUtils.dateIsValid(video1.createdDate)).to.be.true 252 expect(miscsUtils.dateIsValid(video1.createdAt)).to.be.true
253 expect(miscsUtils.dateIsValid(video1.updatedAt)).to.be.true
250 254
251 expect(video2.name).to.equal('my super name for pod 3-2') 255 expect(video2.name).to.equal('my super name for pod 3-2')
252 expect(video2.description).to.equal('my super description for pod 3-2') 256 expect(video2.description).to.equal('my super description for pod 3-2')
@@ -255,7 +259,8 @@ describe('Test multiple pods', function () {
255 expect(video2.duration).to.equal(5) 259 expect(video2.duration).to.equal(5)
256 expect(video2.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ]) 260 expect(video2.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ])
257 expect(video2.author).to.equal('root') 261 expect(video2.author).to.equal('root')
258 expect(miscsUtils.dateIsValid(video2.createdDate)).to.be.true 262 expect(miscsUtils.dateIsValid(video2.createdAt)).to.be.true
263 expect(miscsUtils.dateIsValid(video2.updatedAt)).to.be.true
259 264
260 if (server.url !== 'http://localhost:9003') { 265 if (server.url !== 'http://localhost:9003') {
261 expect(video1.isLocal).to.be.false 266 expect(video1.isLocal).to.be.false
@@ -299,8 +304,8 @@ describe('Test multiple pods', function () {
299 if (err) throw err 304 if (err) throw err
300 305
301 const video = res.body.data[0] 306 const video = res.body.data[0]
302 toRemove.push(res.body.data[2].id) 307 toRemove.push(res.body.data[2])
303 toRemove.push(res.body.data[3].id) 308 toRemove.push(res.body.data[3])
304 309
305 webtorrent.add(video.magnetUri, function (torrent) { 310 webtorrent.add(video.magnetUri, function (torrent) {
306 expect(torrent.files).to.exist 311 expect(torrent.files).to.exist
@@ -368,16 +373,68 @@ describe('Test multiple pods', function () {
368 }) 373 })
369 }) 374 })
370 }) 375 })
376 })
377
378 describe('Should manipulate these videos', function () {
379 it('Should update the video 3 by asking pod 3', function (done) {
380 this.timeout(15000)
381
382 const name = 'my super video updated'
383 const description = 'my super description updated'
384 const tags = [ 'tagup1', 'tagup2' ]
385
386 videosUtils.updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, name, description, tags, function (err) {
387 if (err) throw err
388
389 setTimeout(done, 11000)
390 })
391 })
392
393 it('Should have the video 3 updated on each pod', function (done) {
394 this.timeout(200000)
395
396 each(servers, function (server, callback) {
397 // Avoid "duplicate torrent" errors
398 const webtorrent = new WebTorrent()
399
400 videosUtils.getVideosList(server.url, function (err, res) {
401 if (err) throw err
402
403 const videos = res.body.data
404 const videoUpdated = videos.find(function (video) {
405 return video.name === 'my super video updated'
406 })
407
408 expect(!!videoUpdated).to.be.true
409 expect(videoUpdated.description).to.equal('my super description updated')
410 expect(videoUpdated.tags).to.deep.equal([ 'tagup1', 'tagup2' ])
411 expect(miscsUtils.dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true
412
413 videosUtils.testVideoImage(server.url, 'video_short3.webm', videoUpdated.thumbnailPath, function (err, test) {
414 if (err) throw err
415 expect(test).to.equal(true)
416
417 webtorrent.add(videoUpdated.magnetUri, function (torrent) {
418 expect(torrent.files).to.exist
419 expect(torrent.files.length).to.equal(1)
420 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
421
422 callback()
423 })
424 })
425 })
426 }, done)
427 })
371 428
372 it('Should remove the file 3 and 3-2 by asking pod 3', function (done) { 429 it('Should remove the videos 3 and 3-2 by asking pod 3', function (done) {
373 this.timeout(15000) 430 this.timeout(15000)
374 431
375 series([ 432 series([
376 function (next) { 433 function (next) {
377 videosUtils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[0], next) 434 videosUtils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, next)
378 }, 435 },
379 function (next) { 436 function (next) {
380 videosUtils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[1], next) 437 videosUtils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id, next)
381 }], 438 }],
382 function (err) { 439 function (err) {
383 if (err) throw err 440 if (err) throw err
@@ -394,11 +451,11 @@ describe('Test multiple pods', function () {
394 const videos = res.body.data 451 const videos = res.body.data
395 expect(videos).to.be.an('array') 452 expect(videos).to.be.an('array')
396 expect(videos.length).to.equal(2) 453 expect(videos.length).to.equal(2)
397 expect(videos[0].id).not.to.equal(videos[1].id) 454 expect(videos[0].name).not.to.equal(videos[1].name)
398 expect(videos[0].id).not.to.equal(toRemove[0]) 455 expect(videos[0].name).not.to.equal(toRemove[0].name)
399 expect(videos[1].id).not.to.equal(toRemove[0]) 456 expect(videos[1].name).not.to.equal(toRemove[0].name)
400 expect(videos[0].id).not.to.equal(toRemove[1]) 457 expect(videos[0].name).not.to.equal(toRemove[1].name)
401 expect(videos[1].id).not.to.equal(toRemove[1]) 458 expect(videos[1].name).not.to.equal(toRemove[1].name)
402 459
403 callback() 460 callback()
404 }) 461 })
diff --git a/server/tests/api/requests.js b/server/tests/api/requests.js
index af36f6e34..933ed29b4 100644
--- a/server/tests/api/requests.js
+++ b/server/tests/api/requests.js
@@ -69,7 +69,7 @@ describe('Test requests stats', function () {
69 }) 69 })
70 }) 70 })
71 71
72 it('Should have the correct request', function (done) { 72 it('Should have the correct total request', function (done) {
73 this.timeout(15000) 73 this.timeout(15000)
74 74
75 const server = servers[0] 75 const server = servers[0]
@@ -79,40 +79,16 @@ describe('Test requests stats', function () {
79 uploadVideo(server, function (err) { 79 uploadVideo(server, function (err) {
80 if (err) throw err 80 if (err) throw err
81 81
82 getRequestsStats(server, function (err, res) { 82 setTimeout(function () {
83 if (err) throw err 83 getRequestsStats(server, function (err, res) {
84 84 if (err) throw err
85 const body = res.body
86 expect(body.requests).to.have.lengthOf(1)
87 85
88 const request = body.requests[0] 86 const body = res.body
89 expect(request.to).to.have.lengthOf(1) 87 expect(body.totalRequests).to.equal(1)
90 expect(request.request.type).to.equal('add')
91 88
92 // Wait one cycle 89 done()
93 setTimeout(done, 10000) 90 })
94 }) 91 }, 1000)
95 })
96 })
97
98 it('Should have the correct requests', function (done) {
99 const server = servers[0]
100
101 uploadVideo(server, function (err) {
102 if (err) throw err
103
104 getRequestsStats(server, function (err, res) {
105 if (err) throw err
106
107 const body = res.body
108 expect(body.requests).to.have.lengthOf(2)
109
110 const request = body.requests[1]
111 expect(request.to).to.have.lengthOf(1)
112 expect(request.request.type).to.equal('add')
113
114 done()
115 })
116 }) 92 })
117 }) 93 })
118 94
diff --git a/server/tests/api/single-pod.js b/server/tests/api/single-pod.js
index 65d1a7a65..2db60448f 100644
--- a/server/tests/api/single-pod.js
+++ b/server/tests/api/single-pod.js
@@ -82,7 +82,8 @@ describe('Test a single pod', function () {
82 expect(video.author).to.equal('root') 82 expect(video.author).to.equal('root')
83 expect(video.isLocal).to.be.true 83 expect(video.isLocal).to.be.true
84 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) 84 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
85 expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true 85 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
86 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
86 87
87 videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { 88 videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
88 if (err) throw err 89 if (err) throw err
@@ -116,7 +117,8 @@ describe('Test a single pod', function () {
116 expect(video.author).to.equal('root') 117 expect(video.author).to.equal('root')
117 expect(video.isLocal).to.be.true 118 expect(video.isLocal).to.be.true
118 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) 119 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
119 expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true 120 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
121 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
120 122
121 videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { 123 videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
122 if (err) throw err 124 if (err) throw err
@@ -142,7 +144,8 @@ describe('Test a single pod', function () {
142 expect(video.author).to.equal('root') 144 expect(video.author).to.equal('root')
143 expect(video.isLocal).to.be.true 145 expect(video.isLocal).to.be.true
144 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) 146 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
145 expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true 147 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
148 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
146 149
147 videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { 150 videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
148 if (err) throw err 151 if (err) throw err
@@ -153,31 +156,33 @@ describe('Test a single pod', function () {
153 }) 156 })
154 }) 157 })
155 158
156 it('Should search the video by podHost', function (done) { 159 // Not implemented yet
157 videosUtils.searchVideo(server.url, '9001', 'podHost', function (err, res) { 160 // it('Should search the video by podHost', function (done) {
158 if (err) throw err 161 // videosUtils.searchVideo(server.url, '9001', 'host', function (err, res) {
159 162 // if (err) throw err
160 expect(res.body.total).to.equal(1) 163
161 expect(res.body.data).to.be.an('array') 164 // expect(res.body.total).to.equal(1)
162 expect(res.body.data.length).to.equal(1) 165 // expect(res.body.data).to.be.an('array')
163 166 // expect(res.body.data.length).to.equal(1)
164 const video = res.body.data[0] 167
165 expect(video.name).to.equal('my super name') 168 // const video = res.body.data[0]
166 expect(video.description).to.equal('my super description') 169 // expect(video.name).to.equal('my super name')
167 expect(video.podHost).to.equal('localhost:9001') 170 // expect(video.description).to.equal('my super description')
168 expect(video.author).to.equal('root') 171 // expect(video.podHost).to.equal('localhost:9001')
169 expect(video.isLocal).to.be.true 172 // expect(video.author).to.equal('root')
170 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) 173 // expect(video.isLocal).to.be.true
171 expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true 174 // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
172 175 // expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
173 videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { 176 // expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
174 if (err) throw err 177
175 expect(test).to.equal(true) 178 // videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
176 179 // if (err) throw err
177 done() 180 // expect(test).to.equal(true)
178 }) 181
179 }) 182 // done()
180 }) 183 // })
184 // })
185 // })
181 186
182 it('Should search the video by tag', function (done) { 187 it('Should search the video by tag', function (done) {
183 videosUtils.searchVideo(server.url, 'tag1', 'tags', function (err, res) { 188 videosUtils.searchVideo(server.url, 'tag1', 'tags', function (err, res) {
@@ -194,7 +199,8 @@ describe('Test a single pod', function () {
194 expect(video.author).to.equal('root') 199 expect(video.author).to.equal('root')
195 expect(video.isLocal).to.be.true 200 expect(video.isLocal).to.be.true
196 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) 201 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
197 expect(miscsUtils.dateIsValid(video.createdDate)).to.be.true 202 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
203 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
198 204
199 videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { 205 videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
200 if (err) throw err 206 if (err) throw err
@@ -230,7 +236,7 @@ describe('Test a single pod', function () {
230 }) 236 })
231 237
232 it('Should not find a search by tag', function (done) { 238 it('Should not find a search by tag', function (done) {
233 videosUtils.searchVideo(server.url, 'tag', 'tags', function (err, res) { 239 videosUtils.searchVideo(server.url, 'hello', 'tags', function (err, res) {
234 if (err) throw err 240 if (err) throw err
235 241
236 expect(res.body.total).to.equal(0) 242 expect(res.body.total).to.equal(0)
@@ -332,69 +338,69 @@ describe('Test a single pod', function () {
332 }) 338 })
333 339
334 it('Should list only the two first videos', function (done) { 340 it('Should list only the two first videos', function (done) {
335 videosUtils.getVideosListPagination(server.url, 0, 2, function (err, res) { 341 videosUtils.getVideosListPagination(server.url, 0, 2, 'name', function (err, res) {
336 if (err) throw err 342 if (err) throw err
337 343
338 const videos = res.body.data 344 const videos = res.body.data
339 expect(res.body.total).to.equal(6) 345 expect(res.body.total).to.equal(6)
340 expect(videos.length).to.equal(2) 346 expect(videos.length).to.equal(2)
341 expect(videos[0].name === videosListBase[0].name) 347 expect(videos[0].name).to.equal(videosListBase[0].name)
342 expect(videos[1].name === videosListBase[1].name) 348 expect(videos[1].name).to.equal(videosListBase[1].name)
343 349
344 done() 350 done()
345 }) 351 })
346 }) 352 })
347 353
348 it('Should list only the next three videos', function (done) { 354 it('Should list only the next three videos', function (done) {
349 videosUtils.getVideosListPagination(server.url, 2, 3, function (err, res) { 355 videosUtils.getVideosListPagination(server.url, 2, 3, 'name', function (err, res) {
350 if (err) throw err 356 if (err) throw err
351 357
352 const videos = res.body.data 358 const videos = res.body.data
353 expect(res.body.total).to.equal(6) 359 expect(res.body.total).to.equal(6)
354 expect(videos.length).to.equal(3) 360 expect(videos.length).to.equal(3)
355 expect(videos[0].name === videosListBase[2].name) 361 expect(videos[0].name).to.equal(videosListBase[2].name)
356 expect(videos[1].name === videosListBase[3].name) 362 expect(videos[1].name).to.equal(videosListBase[3].name)
357 expect(videos[2].name === videosListBase[4].name) 363 expect(videos[2].name).to.equal(videosListBase[4].name)
358 364
359 done() 365 done()
360 }) 366 })
361 }) 367 })
362 368
363 it('Should list the last video', function (done) { 369 it('Should list the last video', function (done) {
364 videosUtils.getVideosListPagination(server.url, 5, 6, function (err, res) { 370 videosUtils.getVideosListPagination(server.url, 5, 6, 'name', function (err, res) {
365 if (err) throw err 371 if (err) throw err
366 372
367 const videos = res.body.data 373 const videos = res.body.data
368 expect(res.body.total).to.equal(6) 374 expect(res.body.total).to.equal(6)
369 expect(videos.length).to.equal(1) 375 expect(videos.length).to.equal(1)
370 expect(videos[0].name === videosListBase[5].name) 376 expect(videos[0].name).to.equal(videosListBase[5].name)
371 377
372 done() 378 done()
373 }) 379 })
374 }) 380 })
375 381
376 it('Should search the first video', function (done) { 382 it('Should search the first video', function (done) {
377 videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, function (err, res) { 383 videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, 'name', function (err, res) {
378 if (err) throw err 384 if (err) throw err
379 385
380 const videos = res.body.data 386 const videos = res.body.data
381 expect(res.body.total).to.equal(4) 387 expect(res.body.total).to.equal(4)
382 expect(videos.length).to.equal(1) 388 expect(videos.length).to.equal(1)
383 expect(videos[0].name === 'video_short.webm name') 389 expect(videos[0].name).to.equal('video_short1.webm name')
384 390
385 done() 391 done()
386 }) 392 })
387 }) 393 })
388 394
389 it('Should search the last two videos', function (done) { 395 it('Should search the last two videos', function (done) {
390 videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, function (err, res) { 396 videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, 'name', function (err, res) {
391 if (err) throw err 397 if (err) throw err
392 398
393 const videos = res.body.data 399 const videos = res.body.data
394 expect(res.body.total).to.equal(4) 400 expect(res.body.total).to.equal(4)
395 expect(videos.length).to.equal(2) 401 expect(videos.length).to.equal(2)
396 expect(videos[0].name === 'video_short2.webm name') 402 expect(videos[0].name).to.equal('video_short3.webm name')
397 expect(videos[1].name === 'video_short3.webm name') 403 expect(videos[1].name).to.equal('video_short.webm name')
398 404
399 done() 405 done()
400 }) 406 })
@@ -424,29 +430,30 @@ describe('Test a single pod', function () {
424 }) 430 })
425 }) 431 })
426 432
427 it('Should search all the 9001 port videos', function (done) { 433 // Not implemented yet
428 videosUtils.searchVideoWithPagination(server.url, '9001', 'podHost', 0, 15, function (err, res) { 434 // it('Should search all the 9001 port videos', function (done) {
429 if (err) throw err 435 // videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15, function (err, res) {
436 // if (err) throw err
430 437
431 const videos = res.body.data 438 // const videos = res.body.data
432 expect(res.body.total).to.equal(6) 439 // expect(res.body.total).to.equal(6)
433 expect(videos.length).to.equal(6) 440 // expect(videos.length).to.equal(6)
434 441
435 done() 442 // done()
436 }) 443 // })
437 }) 444 // })
438 445
439 it('Should search all the localhost videos', function (done) { 446 // it('Should search all the localhost videos', function (done) {
440 videosUtils.searchVideoWithPagination(server.url, 'localhost', 'podHost', 0, 15, function (err, res) { 447 // videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15, function (err, res) {
441 if (err) throw err 448 // if (err) throw err
442 449
443 const videos = res.body.data 450 // const videos = res.body.data
444 expect(res.body.total).to.equal(6) 451 // expect(res.body.total).to.equal(6)
445 expect(videos.length).to.equal(6) 452 // expect(videos.length).to.equal(6)
446 453
447 done() 454 // done()
448 }) 455 // })
449 }) 456 // })
450 457
451 it('Should search the good magnetUri video', function (done) { 458 it('Should search the good magnetUri video', function (done) {
452 const video = videosListBase[0] 459 const video = videosListBase[0]
@@ -469,12 +476,12 @@ describe('Test a single pod', function () {
469 const videos = res.body.data 476 const videos = res.body.data
470 expect(res.body.total).to.equal(6) 477 expect(res.body.total).to.equal(6)
471 expect(videos.length).to.equal(6) 478 expect(videos.length).to.equal(6)
472 expect(videos[5].name === 'video_short.mp4 name') 479 expect(videos[0].name).to.equal('video_short.webm name')
473 expect(videos[4].name === 'video_short.ogv name') 480 expect(videos[1].name).to.equal('video_short.ogv name')
474 expect(videos[3].name === 'video_short.webm name') 481 expect(videos[2].name).to.equal('video_short.mp4 name')
475 expect(videos[2].name === 'video_short1.webm name') 482 expect(videos[3].name).to.equal('video_short3.webm name')
476 expect(videos[1].name === 'video_short2.webm name') 483 expect(videos[4].name).to.equal('video_short2.webm name')
477 expect(videos[0].name === 'video_short3.webm name') 484 expect(videos[5].name).to.equal('video_short1.webm name')
478 485
479 done() 486 done()
480 }) 487 })
@@ -488,15 +495,107 @@ describe('Test a single pod', function () {
488 expect(res.body.total).to.equal(4) 495 expect(res.body.total).to.equal(4)
489 expect(videos.length).to.equal(4) 496 expect(videos.length).to.equal(4)
490 497
491 expect(videos[0].name === 'video_short.webm name') 498 expect(videos[0].name).to.equal('video_short1.webm name')
492 expect(videos[1].name === 'video_short1.webm name') 499 expect(videos[1].name).to.equal('video_short2.webm name')
493 expect(videos[2].name === 'video_short2.webm name') 500 expect(videos[2].name).to.equal('video_short3.webm name')
494 expect(videos[3].name === 'video_short3.webm name') 501 expect(videos[3].name).to.equal('video_short.webm name')
502
503 videoId = videos[2].id
495 504
496 done() 505 done()
497 }) 506 })
498 }) 507 })
499 508
509 it('Should update a video', function (done) {
510 const name = 'my super video updated'
511 const description = 'my super description updated'
512 const tags = [ 'tagup1', 'tagup2' ]
513
514 videosUtils.updateVideo(server.url, server.accessToken, videoId, name, description, tags, done)
515 })
516
517 it('Should have the video updated', function (done) {
518 this.timeout(60000)
519
520 videosUtils.getVideo(server.url, videoId, function (err, res) {
521 if (err) throw err
522
523 const video = res.body
524
525 expect(video.name).to.equal('my super video updated')
526 expect(video.description).to.equal('my super description updated')
527 expect(video.podHost).to.equal('localhost:9001')
528 expect(video.author).to.equal('root')
529 expect(video.isLocal).to.be.true
530 expect(video.tags).to.deep.equal([ 'tagup1', 'tagup2' ])
531 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
532 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
533
534 videosUtils.testVideoImage(server.url, 'video_short3.webm', video.thumbnailPath, function (err, test) {
535 if (err) throw err
536 expect(test).to.equal(true)
537
538 webtorrent.add(video.magnetUri, function (torrent) {
539 expect(torrent.files).to.exist
540 expect(torrent.files.length).to.equal(1)
541 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
542
543 done()
544 })
545 })
546 })
547 })
548
549 it('Should update only the tags of a video', function (done) {
550 const tags = [ 'tag1', 'tag2', 'supertag' ]
551
552 videosUtils.updateVideo(server.url, server.accessToken, videoId, null, null, tags, function (err) {
553 if (err) throw err
554
555 videosUtils.getVideo(server.url, videoId, function (err, res) {
556 if (err) throw err
557
558 const video = res.body
559
560 expect(video.name).to.equal('my super video updated')
561 expect(video.description).to.equal('my super description updated')
562 expect(video.podHost).to.equal('localhost:9001')
563 expect(video.author).to.equal('root')
564 expect(video.isLocal).to.be.true
565 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ])
566 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
567 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
568
569 done()
570 })
571 })
572 })
573
574 it('Should update only the description of a video', function (done) {
575 const description = 'hello everybody'
576
577 videosUtils.updateVideo(server.url, server.accessToken, videoId, null, description, null, function (err) {
578 if (err) throw err
579
580 videosUtils.getVideo(server.url, videoId, function (err, res) {
581 if (err) throw err
582
583 const video = res.body
584
585 expect(video.name).to.equal('my super video updated')
586 expect(video.description).to.equal('hello everybody')
587 expect(video.podHost).to.equal('localhost:9001')
588 expect(video.author).to.equal('root')
589 expect(video.isLocal).to.be.true
590 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ])
591 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
592 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
593
594 done()
595 })
596 })
597 })
598
500 after(function (done) { 599 after(function (done) {
501 process.kill(-server.app.pid) 600 process.kill(-server.app.pid)
502 601
diff --git a/server/tests/api/users.js b/server/tests/api/users.js
index 94267f104..e6d937eb0 100644
--- a/server/tests/api/users.js
+++ b/server/tests/api/users.js
@@ -261,8 +261,8 @@ describe('Test users', function () {
261 }) 261 })
262 }) 262 })
263 263
264 it('Should list only the second user by createdDate desc', function (done) { 264 it('Should list only the second user by createdAt desc', function (done) {
265 usersUtils.getUsersListPaginationAndSort(server.url, 0, 1, '-createdDate', function (err, res) { 265 usersUtils.getUsersListPaginationAndSort(server.url, 0, 1, '-createdAt', function (err, res) {
266 if (err) throw err 266 if (err) throw err
267 267
268 const result = res.body 268 const result = res.body
@@ -279,8 +279,8 @@ describe('Test users', function () {
279 }) 279 })
280 }) 280 })
281 281
282 it('Should list all the users by createdDate asc', function (done) { 282 it('Should list all the users by createdAt asc', function (done) {
283 usersUtils.getUsersListPaginationAndSort(server.url, 0, 2, 'createdDate', function (err, res) { 283 usersUtils.getUsersListPaginationAndSort(server.url, 0, 2, 'createdAt', function (err, res) {
284 if (err) throw err 284 if (err) throw err
285 285
286 const result = res.body 286 const result = res.body
diff --git a/server/tests/api/video-abuse.js b/server/tests/api/video-abuse.js
new file mode 100644
index 000000000..58db17c42
--- /dev/null
+++ b/server/tests/api/video-abuse.js
@@ -0,0 +1,191 @@
1'use strict'
2
3const chai = require('chai')
4const each = require('async/each')
5const expect = chai.expect
6const series = require('async/series')
7
8const loginUtils = require('../utils/login')
9const podsUtils = require('../utils/pods')
10const serversUtils = require('../utils/servers')
11const videosUtils = require('../utils/videos')
12const videoAbusesUtils = require('../utils/video-abuses')
13
14describe('Test video abuses', function () {
15 let servers = []
16
17 before(function (done) {
18 this.timeout(30000)
19
20 series([
21 // Run servers
22 function (next) {
23 serversUtils.flushAndRunMultipleServers(2, function (serversRun) {
24 servers = serversRun
25 next()
26 })
27 },
28 // Get the access tokens
29 function (next) {
30 each(servers, function (server, callbackEach) {
31 loginUtils.loginAndGetAccessToken(server, function (err, accessToken) {
32 if (err) return callbackEach(err)
33
34 server.accessToken = accessToken
35 callbackEach()
36 })
37 }, next)
38 },
39 // Pod 1 make friends too
40 function (next) {
41 const server = servers[0]
42 podsUtils.makeFriends(server.url, server.accessToken, next)
43 },
44 // Upload some videos on each pods
45 function (next) {
46 const name = 'my super name for pod 1'
47 const description = 'my super description for pod 1'
48 const tags = [ 'tag' ]
49 const file = 'video_short2.webm'
50 videosUtils.uploadVideo(servers[0].url, servers[0].accessToken, name, description, tags, file, next)
51 },
52 function (next) {
53 const name = 'my super name for pod 2'
54 const description = 'my super description for pod 2'
55 const tags = [ 'tag' ]
56 const file = 'video_short2.webm'
57 videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, name, description, tags, file, next)
58 },
59 // Wait videos propagation
60 function (next) {
61 setTimeout(next, 11000)
62 },
63 function (next) {
64 videosUtils.getVideosList(servers[0].url, function (err, res) {
65 if (err) throw err
66
67 const videos = res.body.data
68
69 expect(videos.length).to.equal(2)
70
71 servers[0].video = videos.find(function (video) { return video.name === 'my super name for pod 1' })
72 servers[1].video = videos.find(function (video) { return video.name === 'my super name for pod 2' })
73
74 next()
75 })
76 }
77 ], done)
78 })
79
80 it('Should not have video abuses', function (done) {
81 videoAbusesUtils.getVideoAbusesList(servers[0].url, servers[0].accessToken, function (err, res) {
82 if (err) throw err
83
84 expect(res.body.total).to.equal(0)
85 expect(res.body.data).to.be.an('array')
86 expect(res.body.data.length).to.equal(0)
87
88 done()
89 })
90 })
91
92 it('Should report abuse on a local video', function (done) {
93 this.timeout(15000)
94
95 const reason = 'my super bad reason'
96 videoAbusesUtils.reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[0].video.id, reason, function (err) {
97 if (err) throw err
98
99 // We wait requests propagation, even if the pod 1 is not supposed to make a request to pod 2
100 setTimeout(done, 11000)
101 })
102 })
103
104 it('Should have 1 video abuses on pod 1 and 0 on pod 2', function (done) {
105 videoAbusesUtils.getVideoAbusesList(servers[0].url, servers[0].accessToken, function (err, res) {
106 if (err) throw err
107
108 expect(res.body.total).to.equal(1)
109 expect(res.body.data).to.be.an('array')
110 expect(res.body.data.length).to.equal(1)
111
112 const abuse = res.body.data[0]
113 expect(abuse.reason).to.equal('my super bad reason')
114 expect(abuse.reporterUsername).to.equal('root')
115 expect(abuse.reporterPodHost).to.equal('localhost:9001')
116 expect(abuse.videoId).to.equal(servers[0].video.id)
117
118 videoAbusesUtils.getVideoAbusesList(servers[1].url, servers[1].accessToken, function (err, res) {
119 if (err) throw err
120
121 expect(res.body.total).to.equal(0)
122 expect(res.body.data).to.be.an('array')
123 expect(res.body.data.length).to.equal(0)
124
125 done()
126 })
127 })
128 })
129
130 it('Should report abuse on a remote video', function (done) {
131 this.timeout(15000)
132
133 const reason = 'my super bad reason 2'
134 videoAbusesUtils.reportVideoAbuse(servers[0].url, servers[0].accessToken, servers[1].video.id, reason, function (err) {
135 if (err) throw err
136
137 // We wait requests propagation
138 setTimeout(done, 11000)
139 })
140 })
141
142 it('Should have 2 video abuse on pod 1 and 1 on pod 2', function (done) {
143 videoAbusesUtils.getVideoAbusesList(servers[0].url, servers[0].accessToken, function (err, res) {
144 if (err) throw err
145
146 expect(res.body.total).to.equal(2)
147 expect(res.body.data).to.be.an('array')
148 expect(res.body.data.length).to.equal(2)
149
150 let abuse = res.body.data[0]
151 expect(abuse.reason).to.equal('my super bad reason')
152 expect(abuse.reporterUsername).to.equal('root')
153 expect(abuse.reporterPodHost).to.equal('localhost:9001')
154 expect(abuse.videoId).to.equal(servers[0].video.id)
155
156 abuse = res.body.data[1]
157 expect(abuse.reason).to.equal('my super bad reason 2')
158 expect(abuse.reporterUsername).to.equal('root')
159 expect(abuse.reporterPodHost).to.equal('localhost:9001')
160 expect(abuse.videoId).to.equal(servers[1].video.id)
161
162 videoAbusesUtils.getVideoAbusesList(servers[1].url, servers[1].accessToken, function (err, res) {
163 if (err) throw err
164
165 expect(res.body.total).to.equal(1)
166 expect(res.body.data).to.be.an('array')
167 expect(res.body.data.length).to.equal(1)
168
169 let abuse = res.body.data[0]
170 expect(abuse.reason).to.equal('my super bad reason 2')
171 expect(abuse.reporterUsername).to.equal('root')
172 expect(abuse.reporterPodHost).to.equal('localhost:9001')
173
174 done()
175 })
176 })
177 })
178
179 after(function (done) {
180 servers.forEach(function (server) {
181 process.kill(-server.app.pid)
182 })
183
184 // Keep the logs if the test failed
185 if (this.ok) {
186 serversUtils.flushTests(done)
187 } else {
188 done()
189 }
190 })
191})
diff --git a/server/tests/real-world/real-world.js b/server/tests/real-world/real-world.js
index dba1970c5..12ab06d6d 100644
--- a/server/tests/real-world/real-world.js
+++ b/server/tests/real-world/real-world.js
@@ -2,6 +2,7 @@
2 2
3const each = require('async/each') 3const each = require('async/each')
4const isEqual = require('lodash/isEqual') 4const isEqual = require('lodash/isEqual')
5const differenceWith = require('lodash/differenceWith')
5const program = require('commander') 6const program = require('commander')
6const series = require('async/series') 7const series = require('async/series')
7 8
@@ -16,32 +17,41 @@ const videosUtils = require('../utils/videos')
16program 17program
17 .option('-c, --create [weight]', 'Weight for creating videos') 18 .option('-c, --create [weight]', 'Weight for creating videos')
18 .option('-r, --remove [weight]', 'Weight for removing videos') 19 .option('-r, --remove [weight]', 'Weight for removing videos')
20 .option('-u, --update [weight]', 'Weight for updating videos')
19 .option('-p, --pods [n]', 'Number of pods to run (3 or 6)', /^3|6$/, 3) 21 .option('-p, --pods [n]', 'Number of pods to run (3 or 6)', /^3|6$/, 3)
20 .option('-a, --action [interval]', 'Interval in ms for an action') 22 .option('-a, --action [interval]', 'Interval in ms for an action')
21 .option('-i, --integrity [interval]', 'Interval in ms for an integrity check') 23 .option('-i, --integrity [interval]', 'Interval in ms for an integrity check')
22 .option('-f, --flush', 'Flush datas on exit') 24 .option('-f, --flush', 'Flush datas on exit')
25 .option('-d, --difference', 'Display difference if integrity is not okay')
23 .parse(process.argv) 26 .parse(process.argv)
24 27
25const createWeight = parseInt(program.create) || 5 28const createWeight = program.create !== undefined ? parseInt(program.create) : 5
26const removeWeight = parseInt(program.remove) || 4 29const removeWeight = program.remove !== undefined ? parseInt(program.remove) : 4
30const updateWeight = program.update !== undefined ? parseInt(program.update) : 4
27const flushAtExit = program.flush || false 31const flushAtExit = program.flush || false
28const actionInterval = parseInt(program.action) || 500 32const actionInterval = program.action !== undefined ? parseInt(program.action) : 500
29let integrityInterval = parseInt(program.integrity) || 60000 33const integrityInterval = program.integrity !== undefined ? parseInt(program.integrity) : 60000
34const displayDiffOnFail = program.integrity || false
30 35
31const numberOfPods = 6 36const numberOfPods = 6
32// Wait requests between pods
33const requestsMaxPerInterval = constants.INTERVAL / actionInterval
34const intervalsToMakeAllRequests = Math.ceil(requestsMaxPerInterval / constants.REQUESTS_LIMIT)
35const waitForBeforeIntegrityCheck = (intervalsToMakeAllRequests * constants.INTERVAL) + 1000
36 37
37integrityInterval += waitForBeforeIntegrityCheck 38// Wait requests between pods
39const baseRequestInterval = integrityInterval < constants.REQUESTS_INTERVAL ? constants.REQUESTS_INTERVAL : integrityInterval
40const requestsMaxPerInterval = baseRequestInterval / actionInterval
41const intervalsToMakeAllRequests = Math.ceil(requestsMaxPerInterval / constants.REQUESTS_LIMIT_PER_POD)
42const waitForBeforeIntegrityCheck = (intervalsToMakeAllRequests * constants.REQUESTS_INTERVAL) - integrityInterval + 1000
38 43
39console.log('Create weight: %d, remove weight: %d.', createWeight, removeWeight) 44console.log('Create weight: %d, update weight: %d, remove weight: %d.', createWeight, updateWeight, removeWeight)
40if (flushAtExit) { 45if (flushAtExit) {
41 console.log('Program will flush data on exit.') 46 console.log('Program will flush data on exit.')
42} else { 47} else {
43 console.log('Program will not flush data on exit.') 48 console.log('Program will not flush data on exit.')
44} 49}
50if (displayDiffOnFail) {
51 console.log('Program will display diff on failure.')
52} else {
53 console.log('Program will not display diff on failure')
54}
45console.log('Interval in ms for each action: %d.', actionInterval) 55console.log('Interval in ms for each action: %d.', actionInterval)
46console.log('Interval in ms for each integrity check: %d.', integrityInterval) 56console.log('Interval in ms for each integrity check: %d.', integrityInterval)
47console.log('Will wait %d ms before an integrity check.', waitForBeforeIntegrityCheck) 57console.log('Will wait %d ms before an integrity check.', waitForBeforeIntegrityCheck)
@@ -63,16 +73,20 @@ runServers(numberOfPods, function (err, servers) {
63 setInterval(function () { 73 setInterval(function () {
64 if (checking === true) return 74 if (checking === true) return
65 75
66 const rand = getRandomInt(0, createWeight + removeWeight) 76 const rand = getRandomInt(0, createWeight + updateWeight + removeWeight)
67 77
68 if (rand < createWeight) { 78 if (rand < createWeight) {
69 upload(servers, getRandomNumServer(servers)) 79 upload(servers, getRandomNumServer(servers))
80 } else if (rand < createWeight + updateWeight) {
81 update(servers, getRandomNumServer(servers))
70 } else { 82 } else {
71 remove(servers, getRandomNumServer(servers)) 83 remove(servers, getRandomNumServer(servers))
72 } 84 }
73 }, actionInterval) 85 }, actionInterval)
74 86
75 setInterval(function () { 87 setInterval(function () {
88 if (checking === true) return
89
76 console.log('Checking integrity...') 90 console.log('Checking integrity...')
77 checking = true 91 checking = true
78 92
@@ -160,9 +174,9 @@ function exitServers (servers, callback) {
160function upload (servers, numServer, callback) { 174function upload (servers, numServer, callback) {
161 if (!callback) callback = function () {} 175 if (!callback) callback = function () {}
162 176
163 const name = 'my super name for pod 1' 177 const name = Date.now() + ' name'
164 const description = 'my super description for pod 1' 178 const description = Date.now() + ' description'
165 const tags = [ 'tag1p1', 'tag2p1' ] 179 const tags = [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ]
166 const file = 'video_short1.webm' 180 const file = 'video_short1.webm'
167 181
168 console.log('Upload video to server ' + numServer) 182 console.log('Upload video to server ' + numServer)
@@ -170,6 +184,26 @@ function upload (servers, numServer, callback) {
170 videosUtils.uploadVideo(servers[numServer].url, servers[numServer].accessToken, name, description, tags, file, callback) 184 videosUtils.uploadVideo(servers[numServer].url, servers[numServer].accessToken, name, description, tags, file, callback)
171} 185}
172 186
187function update (servers, numServer, callback) {
188 if (!callback) callback = function () {}
189
190 videosUtils.getVideosList(servers[numServer].url, function (err, res) {
191 if (err) throw err
192
193 const videos = res.body.data.filter(function (video) { return video.isLocal })
194 if (videos.length === 0) return callback()
195
196 const toUpdate = videos[getRandomInt(0, videos.length)].id
197 const name = Date.now() + ' name'
198 const description = Date.now() + ' description'
199 const tags = [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ]
200
201 console.log('Updating video of server ' + numServer)
202
203 videosUtils.updateVideo(servers[numServer].url, servers[numServer].accessToken, toUpdate, name, description, tags, callback)
204 })
205}
206
173function remove (servers, numServer, callback) { 207function remove (servers, numServer, callback) {
174 if (!callback) callback = function () {} 208 if (!callback) callback = function () {}
175 209
@@ -196,6 +230,7 @@ function checkIntegrity (servers, callback) {
196 delete serverVideo.id 230 delete serverVideo.id
197 delete serverVideo.isLocal 231 delete serverVideo.isLocal
198 delete serverVideo.thumbnailPath 232 delete serverVideo.thumbnailPath
233 delete serverVideo.updatedAt
199 } 234 }
200 235
201 videos.push(serverVideos) 236 videos.push(serverVideos)
@@ -205,6 +240,11 @@ function checkIntegrity (servers, callback) {
205 for (const video of videos) { 240 for (const video of videos) {
206 if (!isEqual(video, videos[0])) { 241 if (!isEqual(video, videos[0])) {
207 console.error('Integrity not ok!') 242 console.error('Integrity not ok!')
243
244 if (displayDiffOnFail) {
245 console.log(differenceWith(videos[0], video, isEqual))
246 }
247
208 process.exit(-1) 248 process.exit(-1)
209 } 249 }
210 } 250 }
diff --git a/server/tests/utils/login.js b/server/tests/utils/login.js
index 465564e14..c984c0baf 100644
--- a/server/tests/utils/login.js
+++ b/server/tests/utils/login.js
@@ -4,7 +4,8 @@ const request = require('supertest')
4 4
5const loginUtils = { 5const loginUtils = {
6 login, 6 login,
7 loginAndGetAccessToken 7 loginAndGetAccessToken,
8 getUserAccessToken
8} 9}
9 10
10// ---------------------- Export functions -------------------- 11// ---------------------- Export functions --------------------
@@ -43,6 +44,14 @@ function loginAndGetAccessToken (server, callback) {
43 }) 44 })
44} 45}
45 46
47function getUserAccessToken (server, user, callback) {
48 login(server.url, server.client, user, 200, function (err, res) {
49 if (err) return callback(err)
50
51 return callback(null, res.body.access_token)
52 })
53}
54
46// --------------------------------------------------------------------------- 55// ---------------------------------------------------------------------------
47 56
48module.exports = loginUtils 57module.exports = loginUtils
diff --git a/server/tests/utils/miscs.js b/server/tests/utils/miscs.js
index 4ceff65df..c4b661496 100644
--- a/server/tests/utils/miscs.js
+++ b/server/tests/utils/miscs.js
@@ -6,12 +6,14 @@ const miscsUtils = {
6 6
7// ---------------------- Export functions -------------------- 7// ---------------------- Export functions --------------------
8 8
9function dateIsValid (dateString) { 9function dateIsValid (dateString, interval) {
10 const dateToCheck = new Date(dateString) 10 const dateToCheck = new Date(dateString)
11 const now = new Date() 11 const now = new Date()
12 12
13 // Check if the interval is more than 2 minutes 13 // Check if the interval is more than 2 minutes
14 if (now - dateToCheck > 120000) return false 14 if (!interval) interval = 120000
15
16 if (now - dateToCheck > interval) return false
15 17
16 return true 18 return true
17} 19}
diff --git a/server/tests/utils/servers.js b/server/tests/utils/servers.js
index 01c9a2f39..1946ef49a 100644
--- a/server/tests/utils/servers.js
+++ b/server/tests/utils/servers.js
@@ -34,7 +34,7 @@ function flushAndRunMultipleServers (totalServers, serversRun) {
34 runServer(j, function (app, url) { 34 runServer(j, function (app, url) {
35 anotherServerDone(j, app, url) 35 anotherServerDone(j, app, url)
36 }) 36 })
37 }, 1000 * j) 37 }, 1000 * (j - 1))
38 } 38 }
39 }) 39 })
40} 40}
@@ -60,12 +60,12 @@ function runServer (number, callback) {
60 60
61 // These actions are async so we need to be sure that they have both been done 61 // These actions are async so we need to be sure that they have both been done
62 const serverRunString = { 62 const serverRunString = {
63 'Connected to mongodb': false, 63 'Database is ready': false,
64 'Server listening on port': false 64 'Server listening on port': false
65 } 65 }
66 66
67 const regexps = { 67 const regexps = {
68 client_id: 'Client id: ([a-f0-9]+)', 68 client_id: 'Client id: (.+)',
69 client_secret: 'Client secret: (.+)', 69 client_secret: 'Client secret: (.+)',
70 user_username: 'Username: (.+)', 70 user_username: 'Username: (.+)',
71 user_password: 'User password: (.+)' 71 user_password: 'User password: (.+)'
@@ -103,7 +103,7 @@ function runServer (number, callback) {
103 if (serverRunString[key] === false) dontContinue = true 103 if (serverRunString[key] === false) dontContinue = true
104 } 104 }
105 105
106 // If no, there is maybe one thing not already initialized (mongodb...) 106 // If no, there is maybe one thing not already initialized (client/user credentials generation...)
107 if (dontContinue === true) return 107 if (dontContinue === true) return
108 108
109 server.app.stdout.removeListener('data', onStdout) 109 server.app.stdout.removeListener('data', onStdout)
diff --git a/server/tests/utils/video-abuses.js b/server/tests/utils/video-abuses.js
new file mode 100644
index 000000000..596c824b3
--- /dev/null
+++ b/server/tests/utils/video-abuses.js
@@ -0,0 +1,73 @@
1'use strict'
2
3const request = require('supertest')
4
5const videosUtils = {
6 getVideoAbusesList,
7 getVideoAbusesListPagination,
8 getVideoAbusesListSort,
9 reportVideoAbuse
10}
11
12// ---------------------- Export functions --------------------
13
14function reportVideoAbuse (url, token, videoId, reason, specialStatus, end) {
15 if (!end) {
16 end = specialStatus
17 specialStatus = 204
18 }
19
20 const path = '/api/v1/videos/' + videoId + '/abuse'
21
22 request(url)
23 .post(path)
24 .set('Accept', 'application/json')
25 .set('Authorization', 'Bearer ' + token)
26 .send({ reason })
27 .expect(specialStatus)
28 .end(end)
29}
30
31function getVideoAbusesList (url, token, end) {
32 const path = '/api/v1/videos/abuse'
33
34 request(url)
35 .get(path)
36 .query({ sort: 'createdAt' })
37 .set('Accept', 'application/json')
38 .set('Authorization', 'Bearer ' + token)
39 .expect(200)
40 .expect('Content-Type', /json/)
41 .end(end)
42}
43
44function getVideoAbusesListPagination (url, token, start, count, end) {
45 const path = '/api/v1/videos/abuse'
46
47 request(url)
48 .get(path)
49 .query({ start: start })
50 .query({ count: count })
51 .set('Accept', 'application/json')
52 .set('Authorization', 'Bearer ' + token)
53 .expect(200)
54 .expect('Content-Type', /json/)
55 .end(end)
56}
57
58function getVideoAbusesListSort (url, token, sort, end) {
59 const path = '/api/v1/videos/abuse'
60
61 request(url)
62 .get(path)
63 .query({ sort: sort })
64 .set('Accept', 'application/json')
65 .set('Authorization', 'Bearer ' + token)
66 .expect(200)
67 .expect('Content-Type', /json/)
68 .end(end)
69}
70
71// ---------------------------------------------------------------------------
72
73module.exports = videosUtils
diff --git a/server/tests/utils/videos.js b/server/tests/utils/videos.js
index 536093db1..f94368437 100644
--- a/server/tests/utils/videos.js
+++ b/server/tests/utils/videos.js
@@ -15,7 +15,8 @@ const videosUtils = {
15 searchVideoWithPagination, 15 searchVideoWithPagination,
16 searchVideoWithSort, 16 searchVideoWithSort,
17 testVideoImage, 17 testVideoImage,
18 uploadVideo 18 uploadVideo,
19 updateVideo
19} 20}
20 21
21// ---------------------- Export functions -------------------- 22// ---------------------- Export functions --------------------
@@ -25,7 +26,7 @@ function getAllVideosListBy (url, end) {
25 26
26 request(url) 27 request(url)
27 .get(path) 28 .get(path)
28 .query({ sort: 'createdDate' }) 29 .query({ sort: 'createdAt' })
29 .query({ start: 0 }) 30 .query({ start: 0 })
30 .query({ count: 10000 }) 31 .query({ count: 10000 })
31 .set('Accept', 'application/json') 32 .set('Accept', 'application/json')
@@ -57,17 +58,25 @@ function getVideosList (url, end) {
57 .end(end) 58 .end(end)
58} 59}
59 60
60function getVideosListPagination (url, start, count, end) { 61function getVideosListPagination (url, start, count, sort, end) {
62 if (!end) {
63 end = sort
64 sort = null
65 }
66
61 const path = '/api/v1/videos' 67 const path = '/api/v1/videos'
62 68
63 request(url) 69 const req = request(url)
64 .get(path) 70 .get(path)
65 .query({ start: start }) 71 .query({ start: start })
66 .query({ count: count }) 72 .query({ count: count })
67 .set('Accept', 'application/json') 73
68 .expect(200) 74 if (sort) req.query({ sort })
69 .expect('Content-Type', /json/) 75
70 .end(end) 76 req.set('Accept', 'application/json')
77 .expect(200)
78 .expect('Content-Type', /json/)
79 .end(end)
71} 80}
72 81
73function getVideosListSort (url, sort, end) { 82function getVideosListSort (url, sort, end) {
@@ -115,18 +124,26 @@ function searchVideo (url, search, field, end) {
115 .end(end) 124 .end(end)
116} 125}
117 126
118function searchVideoWithPagination (url, search, field, start, count, end) { 127function searchVideoWithPagination (url, search, field, start, count, sort, end) {
128 if (!end) {
129 end = sort
130 sort = null
131 }
132
119 const path = '/api/v1/videos' 133 const path = '/api/v1/videos'
120 134
121 request(url) 135 const req = request(url)
122 .get(path + '/search/' + search) 136 .get(path + '/search/' + search)
123 .query({ start: start }) 137 .query({ start: start })
124 .query({ count: count }) 138 .query({ count: count })
125 .query({ field: field }) 139 .query({ field: field })
126 .set('Accept', 'application/json') 140
127 .expect(200) 141 if (sort) req.query({ sort })
128 .expect('Content-Type', /json/) 142
129 .end(end) 143 req.set('Accept', 'application/json')
144 .expect(200)
145 .expect('Content-Type', /json/)
146 .end(end)
130} 147}
131 148
132function searchVideoWithSort (url, search, sort, end) { 149function searchVideoWithSort (url, search, sort, end) {
@@ -194,6 +211,31 @@ function uploadVideo (url, accessToken, name, description, tags, fixture, specia
194 .end(end) 211 .end(end)
195} 212}
196 213
214function updateVideo (url, accessToken, id, name, description, tags, specialStatus, end) {
215 if (!end) {
216 end = specialStatus
217 specialStatus = 204
218 }
219
220 const path = '/api/v1/videos/' + id
221
222 const req = request(url)
223 .put(path)
224 .set('Accept', 'application/json')
225 .set('Authorization', 'Bearer ' + accessToken)
226
227 if (name) req.field('name', name)
228 if (description) req.field('description', description)
229
230 if (tags) {
231 for (let i = 0; i < tags.length; i++) {
232 req.field('tags[' + i + ']', tags[i])
233 }
234 }
235
236 req.expect(specialStatus).end(end)
237}
238
197// --------------------------------------------------------------------------- 239// ---------------------------------------------------------------------------
198 240
199module.exports = videosUtils 241module.exports = videosUtils