]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/videos.js
1 /* eslint-disable no-unused-expressions */
5 const chai
= require('chai')
6 const expect
= chai
.expect
7 const pathUtils
= require('path')
8 const request
= require('supertest')
9 const series
= require('async/series')
11 const loginUtils
= require('../../utils/login')
12 const requestsUtils
= require('../../utils/requests')
13 const serversUtils
= require('../../utils/servers')
14 const videosUtils
= require('../../utils/videos')
16 describe('Test videos API validator', function () {
17 const path
= '/api/v1/videos/'
20 // ---------------------------------------------------------------
22 before(function (done
) {
27 serversUtils
.flushTests(next
)
30 serversUtils
.runServer(1, function (server1
) {
37 loginUtils
.loginAndGetAccessToken(server
, function (err
, token
) {
39 server
.accessToken
= token
47 describe('When listing a video', function () {
48 it('Should fail with a bad start pagination', function (done
) {
51 .query({ start: 'hello' })
52 .set('Accept', 'application/json')
56 it('Should fail with a bad count pagination', function (done
) {
59 .query({ count: 'hello' })
60 .set('Accept', 'application/json')
64 it('Should fail with an incorrect sort', function (done
) {
67 .query({ sort: 'hello' })
68 .set('Accept', 'application/json')
73 describe('When searching a video', function () {
74 it('Should fail with nothing', function (done
) {
76 .get(pathUtils
.join(path
, 'search'))
77 .set('Accept', 'application/json')
81 it('Should fail with a bad start pagination', function (done
) {
83 .get(pathUtils
.join(path
, 'search', 'test'))
84 .query({ start: 'hello' })
85 .set('Accept', 'application/json')
89 it('Should fail with a bad count pagination', function (done
) {
91 .get(pathUtils
.join(path
, 'search', 'test'))
92 .query({ count: 'hello' })
93 .set('Accept', 'application/json')
97 it('Should fail with an incorrect sort', function (done
) {
99 .get(pathUtils
.join(path
, 'search', 'test'))
100 .query({ sort: 'hello' })
101 .set('Accept', 'application/json')
106 describe('When adding a video', function () {
107 it('Should fail with nothing', function (done
) {
110 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
113 it('Should fail without name', function (done
) {
119 description: 'my super description',
120 tags: [ 'tag1', 'tag2' ]
123 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
125 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
128 it('Should fail with a long name', function (done
) {
130 name: 'My very very very very very very very very very very very very very very very very long name',
135 description: 'my super description',
136 tags: [ 'tag1', 'tag2' ]
139 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
141 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
144 it('Should fail without a category', function (done
) {
146 name: 'my super name',
150 description: 'my super description',
151 tags: [ 'tag1', 'tag2' ]
154 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
156 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
159 it('Should fail with a bad category', function (done
) {
161 name: 'my super name',
166 description: 'my super description',
167 tags: [ 'tag1', 'tag2' ]
170 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
172 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
175 it('Should fail without a licence', function (done
) {
177 name: 'my super name',
181 description: 'my super description',
182 tags: [ 'tag1', 'tag2' ]
185 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
187 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
190 it('Should fail with a bad licence', function (done
) {
192 name: 'my super name',
197 description: 'my super description',
198 tags: [ 'tag1', 'tag2' ]
201 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
203 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
206 it('Should fail with a bad language', function (done
) {
208 name: 'my super name',
213 description: 'my super description',
214 tags: [ 'tag1', 'tag2' ]
217 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
219 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
222 it('Should fail without nsfw attribute', function (done
) {
224 name: 'my super name',
228 description: 'my super description',
229 tags: [ 'tag1', 'tag2' ]
232 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
234 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
237 it('Should fail with a bad nsfw attribue', function (done
) {
239 name: 'my super name',
244 description: 'my super description',
245 tags: [ 'tag1', 'tag2' ]
248 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
250 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
253 it('Should fail without description', function (done
) {
255 name: 'my super name',
260 tags: [ 'tag1', 'tag2' ]
263 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
265 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
268 it('Should fail with a long description', function (done
) {
270 name: 'my super name',
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' ]
281 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
283 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
286 it('Should fail with too many tags', function (done
) {
288 name: 'my super name',
293 description: 'my super description',
294 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
297 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
299 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
302 it('Should fail with a tag length too low', function (done
) {
304 name: 'my super name',
309 description: 'my super description',
310 tags: [ 'tag1', 't' ]
313 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
315 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
318 it('Should fail with a tag length too big', function (done
) {
320 name: 'my super name',
325 description: 'my super description',
326 tags: [ 'mysupertagtoolong', 'tag1' ]
329 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
331 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
334 it('Should fail without an input file', function (done
) {
336 name: 'my super name',
341 description: 'my super description',
342 tags: [ 'tag1', 'tag2' ]
345 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
348 it('Should fail without an incorrect input file', function (done
) {
350 name: 'my super name',
355 description: 'my super description',
356 tags: [ 'tag1', 'tag2' ]
359 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short_fake.webm')
361 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
364 it('Should fail with a too big duration', function (done
) {
366 name: 'my super name',
371 description: 'my super description',
372 tags: [ 'tag1', 'tag2' ]
375 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_too_long.webm')
377 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
380 it('Should succeed with the correct parameters', function (done
) {
384 name: 'my super name',
389 description: 'my super description',
390 tags: [ 'tag1', 'tag2' ]
393 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
395 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, function () {
396 attach
.videofile
= pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.mp4')
397 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, function () {
398 attach
.videofile
= pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.ogv')
399 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
, 204)
405 describe('When updating a video', function () {
408 before(function (done
) {
409 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
412 videoId
= res
.body
.data
[0].id
418 it('Should fail with nothing', function (done
) {
420 requestsUtils
.makePutBodyRequest(server
.url
, path
, server
.accessToken
, data
, done
)
423 it('Should fail without a valid uuid', function (done
) {
429 description: 'my super description',
430 tags: [ 'tag1', 'tag2' ]
432 requestsUtils
.makePutBodyRequest(server
.url
, path
+ 'blabla', server
.accessToken
, data
, done
)
435 it('Should fail with an unknown id', function (done
) {
441 description: 'my super description',
442 tags: [ 'tag1', 'tag2' ]
444 requestsUtils
.makePutBodyRequest(server
.url
, path
+ '4da6fde3-88f7-4d16-b119-108df5630b06', server
.accessToken
, data
, done
, 404)
447 it('Should fail with a long name', function (done
) {
449 name: 'My very very very very very very very very very very very very very very very very long name',
454 description: 'my super description',
455 tags: [ 'tag1', 'tag2' ]
457 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
460 it('Should fail with a bad category', function (done
) {
462 name: 'my super name',
467 description: 'my super description',
468 tags: [ 'tag1', 'tag2' ]
470 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
473 it('Should fail with a bad licence', function (done
) {
475 name: 'my super name',
480 description: 'my super description',
481 tags: [ 'tag1', 'tag2' ]
483 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
486 it('Should fail with a bad language', function (done
) {
488 name: 'my super name',
493 description: 'my super description',
494 tags: [ 'tag1', 'tag2' ]
496 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
499 it('Should fail with a bad nsfw attribute', function (done
) {
501 name: 'my super name',
506 description: 'my super description',
507 tags: [ 'tag1', 'tag2' ]
509 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
512 it('Should fail with a long description', function (done
) {
514 name: 'my super name',
519 description: 'my super description which is very very very very very very very very very very very very very very' +
520 'very very very very very very very 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 long',
522 tags: [ 'tag1', 'tag2' ]
524 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
527 it('Should fail with too many tags', function (done
) {
529 name: 'my super name',
534 description: 'my super description',
535 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
537 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
540 it('Should fail with a tag length too low', function (done
) {
542 name: 'my super name',
547 description: 'my super description',
548 tags: [ 'tag1', 't' ]
550 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
553 it('Should fail with a tag length too big', function (done
) {
555 name: 'my super name',
560 description: 'my super description',
561 tags: [ 'mysupertagtoolong', 'tag1' ]
563 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
566 it('Should fail with a video of another user')
568 it('Should fail with a video of another pod')
571 describe('When getting a video', function () {
572 it('Should return the list of the videos with nothing', function (done
) {
575 .set('Accept', 'application/json')
577 .expect('Content-Type', /json/)
578 .end(function (err
, res
) {
581 expect(res
.body
.data
).to
.be
.an('array')
582 expect(res
.body
.data
.length
).to
.equal(3)
588 it('Should fail without a correct uuid', function (done
) {
590 .get(path
+ 'coucou')
591 .set('Accept', 'application/json')
595 it('Should return 404 with an incorrect video', function (done
) {
597 .get(path
+ '4da6fde3-88f7-4d16-b119-108df5630b06')
598 .set('Accept', 'application/json')
602 it('Should succeed with the correct parameters')
605 describe('When rating a video', function () {
608 before(function (done
) {
609 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
612 videoId
= res
.body
.data
[0].id
618 it('Should fail without a valid uuid', function (done
) {
622 requestsUtils
.makePutBodyRequest(server
.url
, path
+ 'blabla/rate', server
.accessToken
, data
, done
)
625 it('Should fail with an unknown id', function (done
) {
629 requestsUtils
.makePutBodyRequest(server
.url
, path
+ '4da6fde3-88f7-4d16-b119-108df5630b06/rate', server
.accessToken
, data
, done
, 404)
632 it('Should fail with a wrong rating', function (done
) {
636 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
+ '/rate', server
.accessToken
, data
, done
)
639 it('Should succeed with the correct parameters', function (done
) {
643 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
+ '/rate', server
.accessToken
, data
, done
, 204)
647 describe('When removing a video', function () {
648 it('Should have 404 with nothing', function (done
) {
651 .set('Authorization', 'Bearer ' + server
.accessToken
)
655 it('Should fail without a correct uuid', function (done
) {
657 .delete(path
+ 'hello')
658 .set('Authorization', 'Bearer ' + server
.accessToken
)
662 it('Should fail with a video which does not exist', function (done
) {
664 .delete(path
+ '4da6fde3-88f7-4d16-b119-108df5630b06')
665 .set('Authorization', 'Bearer ' + server
.accessToken
)
669 it('Should fail with a video of another user')
671 it('Should fail with a video of another pod')
673 it('Should succeed with the correct parameters')
676 after(function (done
) {
677 process
.kill(-server
.app
.pid
)
679 // Keep the logs if the test failed
681 serversUtils
.flushTests(done
)