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