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