]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/videos.js
Fix test (#71)
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / videos.js
CommitLineData
72329aaa
C
1/* eslint-disable no-unused-expressions */
2
efe923bc
C
3'use strict'
4
5const chai = require('chai')
6const expect = chai.expect
7const pathUtils = require('path')
8const request = require('supertest')
9const series = require('async/series')
10
11const loginUtils = require('../../utils/login')
12const requestsUtils = require('../../utils/requests')
13const serversUtils = require('../../utils/servers')
14const videosUtils = require('../../utils/videos')
15
16describe('Test videos API validator', function () {
17 const path = '/api/v1/videos/'
18 let server = null
19
20 // ---------------------------------------------------------------
21
22 before(function (done) {
23 this.timeout(20000)
24
25 series([
26 function (next) {
27 serversUtils.flushTests(next)
28 },
29 function (next) {
30 serversUtils.runServer(1, function (server1) {
31 server = server1
32
33 next()
34 })
35 },
36 function (next) {
37 loginUtils.loginAndGetAccessToken(server, function (err, token) {
38 if (err) throw err
39 server.accessToken = token
40
41 next()
42 })
43 }
44 ], done)
45 })
46
47 describe('When listing a video', function () {
48 it('Should fail with a bad start pagination', function (done) {
49 request(server.url)
50 .get(path)
51 .query({ start: 'hello' })
52 .set('Accept', 'application/json')
53 .expect(400, done)
54 })
55
56 it('Should fail with a bad count pagination', function (done) {
57 request(server.url)
58 .get(path)
59 .query({ count: 'hello' })
60 .set('Accept', 'application/json')
61 .expect(400, done)
62 })
63
64 it('Should fail with an incorrect sort', function (done) {
65 request(server.url)
66 .get(path)
67 .query({ sort: 'hello' })
68 .set('Accept', 'application/json')
69 .expect(400, done)
70 })
71 })
72
73 describe('When searching a video', function () {
74 it('Should fail with nothing', function (done) {
75 request(server.url)
76 .get(pathUtils.join(path, 'search'))
77 .set('Accept', 'application/json')
78 .expect(400, done)
79 })
80
81 it('Should fail with a bad start pagination', function (done) {
82 request(server.url)
83 .get(pathUtils.join(path, 'search', 'test'))
84 .query({ start: 'hello' })
85 .set('Accept', 'application/json')
86 .expect(400, done)
87 })
88
89 it('Should fail with a bad count pagination', function (done) {
90 request(server.url)
91 .get(pathUtils.join(path, 'search', 'test'))
92 .query({ count: 'hello' })
93 .set('Accept', 'application/json')
94 .expect(400, done)
95 })
96
97 it('Should fail with an incorrect sort', function (done) {
98 request(server.url)
99 .get(pathUtils.join(path, 'search', 'test'))
100 .query({ sort: 'hello' })
101 .set('Accept', 'application/json')
102 .expect(400, done)
103 })
104 })
105
106 describe('When adding a video', function () {
107 it('Should fail with nothing', function (done) {
108 const data = {}
109 const attach = {}
110 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
111 })
112
113 it('Should fail without name', function (done) {
114 const data = {
6e07c3de 115 category: 5,
6f0c39e2 116 licence: 1,
3092476e 117 language: 6,
31b59b47 118 nsfw: false,
efe923bc
C
119 description: 'my super description',
120 tags: [ 'tag1', 'tag2' ]
121 }
122 const attach = {
123 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
124 }
125 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
126 })
127
128 it('Should fail with a long name', function (done) {
129 const data = {
130 name: 'My very very very very very very very very very very very very very very very very long name',
6e07c3de 131 category: 5,
6f0c39e2 132 licence: 1,
3092476e 133 language: 6,
31b59b47 134 nsfw: false,
6e07c3de
C
135 description: 'my super description',
136 tags: [ 'tag1', 'tag2' ]
137 }
138 const attach = {
139 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
140 }
141 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
142 })
143
144 it('Should fail without a category', function (done) {
145 const data = {
146 name: 'my super name',
6f0c39e2 147 licence: 1,
3092476e 148 language: 6,
31b59b47 149 nsfw: false,
6e07c3de
C
150 description: 'my super description',
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 with a bad category', function (done) {
160 const data = {
161 name: 'my super name',
162 category: 125,
6f0c39e2 163 licence: 1,
3092476e 164 language: 6,
31b59b47 165 nsfw: false,
6f0c39e2
C
166 description: 'my super description',
167 tags: [ 'tag1', 'tag2' ]
168 }
169 const attach = {
170 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
171 }
172 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
173 })
174
175 it('Should fail without a licence', function (done) {
176 const data = {
177 name: 'my super name',
178 category: 5,
3092476e 179 language: 6,
31b59b47 180 nsfw: false,
6f0c39e2
C
181 description: 'my super description',
182 tags: [ 'tag1', 'tag2' ]
183 }
184 const attach = {
185 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
186 }
187 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
188 })
189
190 it('Should fail with a bad licence', function (done) {
191 const data = {
192 name: 'my super name',
193 category: 5,
194 licence: 125,
3092476e
C
195 language: 6,
196 nsfw: false,
197 description: 'my super description',
198 tags: [ 'tag1', 'tag2' ]
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 bad language', function (done) {
207 const data = {
208 name: 'my super name',
209 category: 5,
210 licence: 4,
211 language: 563,
31b59b47
C
212 nsfw: false,
213 description: 'my super description',
214 tags: [ 'tag1', 'tag2' ]
215 }
216 const attach = {
217 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
218 }
219 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
220 })
221
222 it('Should fail without nsfw attribute', function (done) {
223 const data = {
224 name: 'my super name',
225 category: 5,
226 licence: 4,
3092476e 227 language: 6,
31b59b47
C
228 description: 'my super description',
229 tags: [ 'tag1', 'tag2' ]
230 }
231 const attach = {
232 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
233 }
234 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
235 })
236
237 it('Should fail with a bad nsfw attribue', function (done) {
238 const data = {
239 name: 'my super name',
240 category: 5,
241 licence: 4,
3092476e 242 language: 6,
31b59b47 243 nsfw: 2,
efe923bc
C
244 description: 'my super description',
245 tags: [ 'tag1', 'tag2' ]
246 }
247 const attach = {
248 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
249 }
250 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
251 })
252
253 it('Should fail without description', function (done) {
254 const data = {
255 name: 'my super name',
6e07c3de 256 category: 5,
6f0c39e2 257 licence: 1,
3092476e 258 language: 6,
31b59b47 259 nsfw: false,
efe923bc
C
260 tags: [ 'tag1', 'tag2' ]
261 }
262 const attach = {
263 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
264 }
265 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
266 })
267
268 it('Should fail with a long description', function (done) {
269 const data = {
270 name: 'my super name',
6e07c3de 271 category: 5,
6f0c39e2 272 licence: 1,
3092476e 273 language: 6,
31b59b47 274 nsfw: false,
efe923bc
C
275 description: 'my super description which is very very very very very very very very very very very very very very' +
276 'very very very very very very very very very very very very very very very very very very very very very' +
277 'very very very very very very very very very very very very very very very long',
278 tags: [ 'tag1', 'tag2' ]
279 }
280 const attach = {
281 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
282 }
283 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
284 })
285
efe923bc
C
286 it('Should fail with too many tags', function (done) {
287 const data = {
288 name: 'my super name',
6e07c3de 289 category: 5,
6f0c39e2 290 licence: 1,
3092476e 291 language: 6,
31b59b47 292 nsfw: false,
efe923bc
C
293 description: 'my super description',
294 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
295 }
296 const attach = {
297 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
298 }
299 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
300 })
301
efe923bc
C
302 it('Should fail with a tag length too low', function (done) {
303 const data = {
304 name: 'my super name',
6e07c3de 305 category: 5,
6f0c39e2 306 licence: 1,
3092476e 307 language: 6,
31b59b47 308 nsfw: false,
efe923bc
C
309 description: 'my super description',
310 tags: [ 'tag1', 't' ]
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 with a tag length too big', function (done) {
319 const data = {
320 name: 'my super name',
6e07c3de 321 category: 5,
6f0c39e2 322 licence: 1,
3092476e 323 language: 6,
31b59b47 324 nsfw: false,
efe923bc
C
325 description: 'my super description',
326 tags: [ 'mysupertagtoolong', 'tag1' ]
327 }
328 const attach = {
329 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
330 }
331 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
332 })
333
efe923bc
C
334 it('Should fail without an input file', function (done) {
335 const data = {
336 name: 'my super name',
6e07c3de 337 category: 5,
6f0c39e2 338 licence: 1,
3092476e 339 language: 6,
31b59b47 340 nsfw: false,
efe923bc
C
341 description: 'my super description',
342 tags: [ 'tag1', 'tag2' ]
343 }
344 const attach = {}
345 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
346 })
347
348 it('Should fail without an incorrect input file', function (done) {
349 const data = {
350 name: 'my super name',
6e07c3de 351 category: 5,
6f0c39e2 352 licence: 1,
3092476e 353 language: 6,
31b59b47 354 nsfw: false,
efe923bc
C
355 description: 'my super description',
356 tags: [ 'tag1', 'tag2' ]
357 }
358 const attach = {
359 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
360 }
361 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
362 })
363
364 it('Should fail with a too big duration', function (done) {
365 const data = {
366 name: 'my super name',
6e07c3de 367 category: 5,
6f0c39e2 368 licence: 1,
3092476e 369 language: 6,
31b59b47 370 nsfw: false,
efe923bc
C
371 description: 'my super description',
372 tags: [ 'tag1', 'tag2' ]
373 }
374 const attach = {
375 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_too_long.webm')
376 }
377 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
378 })
379
380 it('Should succeed with the correct parameters', function (done) {
5fe7e898 381 this.timeout(10000)
8635a2c7 382
efe923bc
C
383 const data = {
384 name: 'my super name',
6e07c3de 385 category: 5,
6f0c39e2 386 licence: 1,
3092476e 387 language: 6,
31b59b47 388 nsfw: false,
efe923bc
C
389 description: 'my super description',
390 tags: [ 'tag1', 'tag2' ]
391 }
392 const attach = {
393 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
394 }
5fe7e898 395
efe923bc
C
396 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () {
397 attach.videofile = pathUtils.join(__dirname, '..', 'fixtures', 'video_short.mp4')
398 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () {
399 attach.videofile = pathUtils.join(__dirname, '..', 'fixtures', 'video_short.ogv')
400 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done, 204)
401 }, false)
402 }, false)
403 })
404 })
405
406 describe('When updating a video', function () {
407 let videoId
408
409 before(function (done) {
410 videosUtils.getVideosList(server.url, function (err, res) {
411 if (err) throw err
412
413 videoId = res.body.data[0].id
414
415 return done()
416 })
417 })
418
419 it('Should fail with nothing', function (done) {
420 const data = {}
421 requestsUtils.makePutBodyRequest(server.url, path, server.accessToken, data, done)
422 })
423
424 it('Should fail without a valid uuid', function (done) {
425 const data = {
6e07c3de 426 category: 5,
6f0c39e2 427 licence: 2,
3092476e 428 language: 6,
31b59b47 429 nsfw: false,
efe923bc
C
430 description: 'my super description',
431 tags: [ 'tag1', 'tag2' ]
432 }
433 requestsUtils.makePutBodyRequest(server.url, path + 'blabla', server.accessToken, data, done)
434 })
435
436 it('Should fail with an unknown id', function (done) {
437 const data = {
6e07c3de 438 category: 5,
6f0c39e2 439 licence: 2,
3092476e 440 language: 6,
31b59b47 441 nsfw: false,
efe923bc
C
442 description: 'my super description',
443 tags: [ 'tag1', 'tag2' ]
444 }
445 requestsUtils.makePutBodyRequest(server.url, path + '4da6fde3-88f7-4d16-b119-108df5630b06', server.accessToken, data, done, 404)
446 })
447
448 it('Should fail with a long name', function (done) {
449 const data = {
450 name: 'My very very very very very very very very very very very very very very very very long name',
6e07c3de 451 category: 5,
6f0c39e2 452 licence: 2,
3092476e 453 language: 6,
31b59b47 454 nsfw: false,
6e07c3de
C
455 description: 'my super description',
456 tags: [ 'tag1', 'tag2' ]
457 }
458 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
459 })
460
461 it('Should fail with a bad category', function (done) {
462 const data = {
463 name: 'my super name',
464 category: 128,
6f0c39e2 465 licence: 2,
3092476e 466 language: 6,
31b59b47 467 nsfw: false,
6f0c39e2
C
468 description: 'my super description',
469 tags: [ 'tag1', 'tag2' ]
470 }
471 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
472 })
473
474 it('Should fail with a bad licence', function (done) {
475 const data = {
476 name: 'my super name',
477 category: 5,
478 licence: 128,
3092476e
C
479 language: 6,
480 nsfw: false,
481 description: 'my super description',
482 tags: [ 'tag1', 'tag2' ]
483 }
484 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
485 })
486
487 it('Should fail with a bad language', function (done) {
488 const data = {
489 name: 'my super name',
490 category: 5,
491 licence: 3,
492 language: 896,
31b59b47
C
493 nsfw: false,
494 description: 'my super description',
495 tags: [ 'tag1', 'tag2' ]
496 }
497 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
498 })
499
500 it('Should fail with a bad nsfw attribute', function (done) {
501 const data = {
502 name: 'my super name',
503 category: 5,
504 licence: 5,
3092476e 505 language: 6,
31b59b47 506 nsfw: -4,
efe923bc
C
507 description: 'my super description',
508 tags: [ 'tag1', 'tag2' ]
509 }
510 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
511 })
512
513 it('Should fail with a long description', function (done) {
514 const data = {
515 name: 'my super name',
6e07c3de 516 category: 5,
6f0c39e2 517 licence: 2,
3092476e 518 language: 6,
31b59b47 519 nsfw: false,
efe923bc
C
520 description: 'my super description which is very very very very very very very very very very very very very very' +
521 'very very very very very very very very very very very very very very very very very very very very very' +
522 'very very very very very very very very very very very very very very very long',
523 tags: [ 'tag1', 'tag2' ]
524 }
525 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
526 })
527
528 it('Should fail with too many tags', function (done) {
529 const data = {
530 name: 'my super name',
6e07c3de 531 category: 5,
6f0c39e2 532 licence: 2,
3092476e 533 language: 6,
31b59b47 534 nsfw: false,
efe923bc
C
535 description: 'my super description',
536 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
537 }
538 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
539 })
540
efe923bc
C
541 it('Should fail with a tag length too low', function (done) {
542 const data = {
543 name: 'my super name',
6e07c3de 544 category: 5,
6f0c39e2 545 licence: 2,
3092476e 546 language: 6,
31b59b47 547 nsfw: false,
efe923bc
C
548 description: 'my super description',
549 tags: [ 'tag1', 't' ]
550 }
551 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
552 })
553
554 it('Should fail with a tag length too big', function (done) {
555 const data = {
556 name: 'my super name',
6e07c3de 557 category: 5,
6f0c39e2 558 licence: 2,
3092476e 559 language: 6,
31b59b47 560 nsfw: false,
efe923bc
C
561 description: 'my super description',
562 tags: [ 'mysupertagtoolong', 'tag1' ]
563 }
564 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
565 })
566
45abb8b9
C
567 it('Should fail with a video of another user')
568
569 it('Should fail with a video of another pod')
efe923bc
C
570 })
571
572 describe('When getting a video', function () {
573 it('Should return the list of the videos with nothing', function (done) {
574 request(server.url)
575 .get(path)
576 .set('Accept', 'application/json')
577 .expect(200)
578 .expect('Content-Type', /json/)
579 .end(function (err, res) {
580 if (err) throw err
581
582 expect(res.body.data).to.be.an('array')
583 expect(res.body.data.length).to.equal(3)
584
585 done()
586 })
587 })
588
589 it('Should fail without a correct uuid', function (done) {
590 request(server.url)
591 .get(path + 'coucou')
592 .set('Accept', 'application/json')
593 .expect(400, done)
594 })
595
596 it('Should return 404 with an incorrect video', function (done) {
597 request(server.url)
598 .get(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
599 .set('Accept', 'application/json')
600 .expect(404, done)
601 })
602
603 it('Should succeed with the correct parameters')
604 })
605
d38b8281
C
606 describe('When rating a video', function () {
607 let videoId
608
609 before(function (done) {
610 videosUtils.getVideosList(server.url, function (err, res) {
611 if (err) throw err
612
613 videoId = res.body.data[0].id
614
615 return done()
616 })
617 })
618
619 it('Should fail without a valid uuid', function (done) {
620 const data = {
621 rating: 'like'
622 }
623 requestsUtils.makePutBodyRequest(server.url, path + 'blabla/rate', server.accessToken, data, done)
624 })
625
626 it('Should fail with an unknown id', function (done) {
627 const data = {
628 rating: 'like'
629 }
630 requestsUtils.makePutBodyRequest(server.url, path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate', server.accessToken, data, done, 404)
631 })
632
633 it('Should fail with a wrong rating', function (done) {
634 const data = {
635 rating: 'likes'
636 }
637 requestsUtils.makePutBodyRequest(server.url, path + videoId + '/rate', server.accessToken, data, done)
638 })
639
640 it('Should succeed with the correct parameters', function (done) {
641 const data = {
642 rating: 'like'
643 }
644 requestsUtils.makePutBodyRequest(server.url, path + videoId + '/rate', server.accessToken, data, done, 204)
645 })
646 })
647
efe923bc
C
648 describe('When removing a video', function () {
649 it('Should have 404 with nothing', function (done) {
650 request(server.url)
651 .delete(path)
652 .set('Authorization', 'Bearer ' + server.accessToken)
653 .expect(400, done)
654 })
655
656 it('Should fail without a correct uuid', function (done) {
657 request(server.url)
658 .delete(path + 'hello')
659 .set('Authorization', 'Bearer ' + server.accessToken)
660 .expect(400, done)
661 })
662
663 it('Should fail with a video which does not exist', function (done) {
664 request(server.url)
665 .delete(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
666 .set('Authorization', 'Bearer ' + server.accessToken)
667 .expect(404, done)
668 })
669
670 it('Should fail with a video of another user')
671
672 it('Should fail with a video of another pod')
673
674 it('Should succeed with the correct parameters')
675 })
676
677 after(function (done) {
678 process.kill(-server.app.pid)
679
680 // Keep the logs if the test failed
681 if (this.ok) {
682 serversUtils.flushTests(done)
683 } else {
684 done()
685 }
686 })
687})