]>
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
) {
382 name: 'my super name',
387 description: 'my super description',
388 tags: [ 'tag1', 'tag2' ]
391 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
393 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, function () {
394 attach
.videofile
= pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.mp4')
395 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, function () {
396 attach
.videofile
= pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.ogv')
397 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
, 204)
403 describe('When updating a video', function () {
406 before(function (done
) {
407 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
410 videoId
= res
.body
.data
[0].id
416 it('Should fail with nothing', function (done
) {
418 requestsUtils
.makePutBodyRequest(server
.url
, path
, server
.accessToken
, data
, done
)
421 it('Should fail without a valid uuid', function (done
) {
427 description: 'my super description',
428 tags: [ 'tag1', 'tag2' ]
430 requestsUtils
.makePutBodyRequest(server
.url
, path
+ 'blabla', server
.accessToken
, data
, done
)
433 it('Should fail with an unknown id', function (done
) {
439 description: 'my super description',
440 tags: [ 'tag1', 'tag2' ]
442 requestsUtils
.makePutBodyRequest(server
.url
, path
+ '4da6fde3-88f7-4d16-b119-108df5630b06', server
.accessToken
, data
, done
, 404)
445 it('Should fail with a long name', function (done
) {
447 name: 'My very very very very very very very very very very very very very very very very long name',
452 description: 'my super description',
453 tags: [ 'tag1', 'tag2' ]
455 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
458 it('Should fail with a bad category', function (done
) {
460 name: 'my super name',
465 description: 'my super description',
466 tags: [ 'tag1', 'tag2' ]
468 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
471 it('Should fail with a bad licence', function (done
) {
473 name: 'my super name',
478 description: 'my super description',
479 tags: [ 'tag1', 'tag2' ]
481 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
484 it('Should fail with a bad language', function (done
) {
486 name: 'my super name',
491 description: 'my super description',
492 tags: [ 'tag1', 'tag2' ]
494 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
497 it('Should fail with a bad nsfw attribute', function (done
) {
499 name: 'my super name',
504 description: 'my super description',
505 tags: [ 'tag1', 'tag2' ]
507 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
510 it('Should fail with a long description', function (done
) {
512 name: 'my super name',
517 description: 'my super description which is very very very very very very very very very very very very very very' +
518 'very very very very very very very very very very very very very very very very very very very very very' +
519 'very very very very very very very very very very very very very very very long',
520 tags: [ 'tag1', 'tag2' ]
522 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
525 it('Should fail with too many tags', function (done
) {
527 name: 'my super name',
532 description: 'my super description',
533 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
535 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
538 it('Should fail with a tag length too low', function (done
) {
540 name: 'my super name',
545 description: 'my super description',
546 tags: [ 'tag1', 't' ]
548 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
551 it('Should fail with a tag length too big', function (done
) {
553 name: 'my super name',
558 description: 'my super description',
559 tags: [ 'mysupertagtoolong', 'tag1' ]
561 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
564 it('Should fail with a video of another user')
566 it('Should fail with a video of another pod')
569 describe('When getting a video', function () {
570 it('Should return the list of the videos with nothing', function (done
) {
573 .set('Accept', 'application/json')
575 .expect('Content-Type', /json/)
576 .end(function (err
, res
) {
579 expect(res
.body
.data
).to
.be
.an('array')
580 expect(res
.body
.data
.length
).to
.equal(3)
586 it('Should fail without a correct uuid', function (done
) {
588 .get(path
+ 'coucou')
589 .set('Accept', 'application/json')
593 it('Should return 404 with an incorrect video', function (done
) {
595 .get(path
+ '4da6fde3-88f7-4d16-b119-108df5630b06')
596 .set('Accept', 'application/json')
600 it('Should succeed with the correct parameters')
603 describe('When rating a video', function () {
606 before(function (done
) {
607 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
610 videoId
= res
.body
.data
[0].id
616 it('Should fail without a valid uuid', function (done
) {
620 requestsUtils
.makePutBodyRequest(server
.url
, path
+ 'blabla/rate', server
.accessToken
, data
, done
)
623 it('Should fail with an unknown id', function (done
) {
627 requestsUtils
.makePutBodyRequest(server
.url
, path
+ '4da6fde3-88f7-4d16-b119-108df5630b06/rate', server
.accessToken
, data
, done
, 404)
630 it('Should fail with a wrong rating', function (done
) {
634 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
+ '/rate', server
.accessToken
, data
, done
)
637 it('Should succeed with the correct parameters', function (done
) {
641 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
+ '/rate', server
.accessToken
, data
, done
, 204)
645 describe('When removing a video', function () {
646 it('Should have 404 with nothing', function (done
) {
649 .set('Authorization', 'Bearer ' + server
.accessToken
)
653 it('Should fail without a correct uuid', function (done
) {
655 .delete(path
+ 'hello')
656 .set('Authorization', 'Bearer ' + server
.accessToken
)
660 it('Should fail with a video which does not exist', function (done
) {
662 .delete(path
+ '4da6fde3-88f7-4d16-b119-108df5630b06')
663 .set('Authorization', 'Bearer ' + server
.accessToken
)
667 it('Should fail with a video of another user')
669 it('Should fail with a video of another pod')
671 it('Should succeed with the correct parameters')
674 after(function (done
) {
675 process
.kill(-server
.app
.pid
)
677 // Keep the logs if the test failed
679 serversUtils
.flushTests(done
)