aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/videos.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params/videos.ts')
-rw-r--r--server/tests/api/check-params/videos.ts677
1 files changed, 677 insertions, 0 deletions
diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts
new file mode 100644
index 000000000..8d30769d3
--- /dev/null
+++ b/server/tests/api/check-params/videos.ts
@@ -0,0 +1,677 @@
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 = {}
99 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
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 }
114 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
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 }
130 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
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 }
145 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
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 }
161 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
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 }
176 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
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 }
192 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
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 }
208 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
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 }
223 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
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 }
239 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
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 }
254 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
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 }
272 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
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 }
288 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
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 }
304 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
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 }
320 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
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 = {}
334 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
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 }
350 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
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 }
366 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
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
385 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches, statusCodeExpected: 204 })
386
387 attaches.videofile = join(__dirname, '..', 'fixtures', 'video_short.mp4')
388 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches, statusCodeExpected: 204 })
389
390 attaches.videofile = join(__dirname, '..', 'fixtures', 'video_short.ogv')
391 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches, statusCodeExpected: 204 })
392 })
393 })
394
395 describe('When updating a video', function () {
396 let videoId
397
398 before(async function () {
399 const res = await getVideosList(server.url)
400 videoId = res.body.data[0].id
401 })
402
403 it('Should fail with nothing', async function () {
404 const fields = {}
405 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
406 })
407
408 it('Should fail without a valid uuid', async function () {
409 const fields = {
410 category: 5,
411 licence: 2,
412 language: 6,
413 nsfw: false,
414 description: 'my super description',
415 tags: [ 'tag1', 'tag2' ]
416 }
417 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
418 })
419
420 it('Should fail with an unknown id', async function () {
421 const fields = {
422 category: 5,
423 licence: 2,
424 language: 6,
425 nsfw: false,
426 description: 'my super description',
427 tags: [ 'tag1', 'tag2' ]
428 }
429 await makePutBodyRequest({
430 url: server.url,
431 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
432 token: server.accessToken,
433 fields,
434 statusCodeExpected: 404
435 })
436 })
437
438 it('Should fail with a long name', async function () {
439 const fields = {
440 name: 'My very very very very very very very very very very very very very very very very long name',
441 category: 5,
442 licence: 2,
443 language: 6,
444 nsfw: false,
445 description: 'my super description',
446 tags: [ 'tag1', 'tag2' ]
447 }
448 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
449 })
450
451 it('Should fail with a bad category', async function () {
452 const fields = {
453 name: 'my super name',
454 category: 128,
455 licence: 2,
456 language: 6,
457 nsfw: false,
458 description: 'my super description',
459 tags: [ 'tag1', 'tag2' ]
460 }
461 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
462 })
463
464 it('Should fail with a bad licence', async function () {
465 const fields = {
466 name: 'my super name',
467 category: 5,
468 licence: 128,
469 language: 6,
470 nsfw: false,
471 description: 'my super description',
472 tags: [ 'tag1', 'tag2' ]
473 }
474 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
475 })
476
477 it('Should fail with a bad language', async function () {
478 const fields = {
479 name: 'my super name',
480 category: 5,
481 licence: 3,
482 language: 896,
483 nsfw: false,
484 description: 'my super description',
485 tags: [ 'tag1', 'tag2' ]
486 }
487 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
488 })
489
490 it('Should fail with a bad nsfw attribute', async function () {
491 const fields = {
492 name: 'my super name',
493 category: 5,
494 licence: 5,
495 language: 6,
496 nsfw: -4,
497 description: 'my super description',
498 tags: [ 'tag1', 'tag2' ]
499 }
500 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
501 })
502
503 it('Should fail with a long description', async function () {
504 const fields = {
505 name: 'my super name',
506 category: 5,
507 licence: 2,
508 language: 6,
509 nsfw: false,
510 description: 'my super description which is very very very very very very very very very very very very very very' +
511 'very very very very very very very very very very very very very very very very very very very very very' +
512 'very very very very very very very very very very very very very very very long',
513 tags: [ 'tag1', 'tag2' ]
514 }
515 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
516 })
517
518 it('Should fail with too many tags', async function () {
519 const fields = {
520 name: 'my super name',
521 category: 5,
522 licence: 2,
523 language: 6,
524 nsfw: false,
525 description: 'my super description',
526 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
527 }
528 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
529 })
530
531 it('Should fail with a tag length too low', async function () {
532 const fields = {
533 name: 'my super name',
534 category: 5,
535 licence: 2,
536 language: 6,
537 nsfw: false,
538 description: 'my super description',
539 tags: [ 'tag1', 't' ]
540 }
541 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
542 })
543
544 it('Should fail with a tag length too big', async function () {
545 const fields = {
546 name: 'my super name',
547 category: 5,
548 licence: 2,
549 language: 6,
550 nsfw: false,
551 description: 'my super description',
552 tags: [ 'my_super_tag_too_long', 'tag1' ]
553 }
554 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
555 })
556
557 it('Should fail with a video of another user')
558
559 it('Should fail with a video of another pod')
560 })
561
562 describe('When getting a video', function () {
563 it('Should return the list of the videos with nothing', async function () {
564 const res = await request(server.url)
565 .get(path)
566 .set('Accept', 'application/json')
567 .expect(200)
568 .expect('Content-Type', /json/)
569
570 expect(res.body.data).to.be.an('array')
571 expect(res.body.data.length).to.equal(3)
572 })
573
574 it('Should fail without a correct uuid', async function () {
575 await request(server.url)
576 .get(path + 'coucou')
577 .set('Accept', 'application/json')
578 .expect(400)
579 })
580
581 it('Should return 404 with an incorrect video', async function () {
582 await request(server.url)
583 .get(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
584 .set('Accept', 'application/json')
585 .expect(404)
586 })
587
588 it('Should succeed with the correct parameters')
589 })
590
591 describe('When rating a video', function () {
592 let videoId
593
594 before(async function () {
595 const res = await getVideosList(server.url)
596 videoId = res.body.data[0].id
597 })
598
599 it('Should fail without a valid uuid', async function () {
600 const fields = {
601 rating: 'like'
602 }
603 await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields })
604 })
605
606 it('Should fail with an unknown id', async function () {
607 const fields = {
608 rating: 'like'
609 }
610 await makePutBodyRequest({
611 url: server.url,
612 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
613 token: server.accessToken,
614 fields,
615 statusCodeExpected: 404
616 })
617 })
618
619 it('Should fail with a wrong rating', async function () {
620 const fields = {
621 rating: 'likes'
622 }
623 await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields })
624 })
625
626 it('Should succeed with the correct parameters', async function () {
627 const fields = {
628 rating: 'like'
629 }
630 await makePutBodyRequest({
631 url: server.url,
632 path: path + videoId + '/rate',
633 token: server.accessToken,
634 fields,
635 statusCodeExpected: 204
636 })
637 })
638 })
639
640 describe('When removing a video', function () {
641 it('Should have 404 with nothing', async function () {
642 await request(server.url)
643 .delete(path)
644 .set('Authorization', 'Bearer ' + server.accessToken)
645 .expect(400)
646 })
647
648 it('Should fail without a correct uuid', async function () {
649 await request(server.url)
650 .delete(path + 'hello')
651 .set('Authorization', 'Bearer ' + server.accessToken)
652 .expect(400)
653 })
654
655 it('Should fail with a video which does not exist', async function () {
656 await request(server.url)
657 .delete(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
658 .set('Authorization', 'Bearer ' + server.accessToken)
659 .expect(404)
660 })
661
662 it('Should fail with a video of another user')
663
664 it('Should fail with a video of another pod')
665
666 it('Should succeed with the correct parameters')
667 })
668
669 after(async function () {
670 killallServers([ server ])
671
672 // Keep the logs if the test failed
673 if (this['ok']) {
674 await flushTests()
675 }
676 })
677})