]>
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
) {
118 description: 'my super description',
119 tags: [ 'tag1', 'tag2' ]
122 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
124 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
127 it('Should fail with a long name', function (done
) {
129 name: 'My very very very very very very very very very very very very very very very very long name',
133 description: 'my super description',
134 tags: [ 'tag1', 'tag2' ]
137 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
139 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
142 it('Should fail without a category', function (done
) {
144 name: 'my super name',
147 description: 'my super description',
148 tags: [ 'tag1', 'tag2' ]
151 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
153 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
156 it('Should fail with a bad category', function (done
) {
158 name: 'my super name',
162 description: 'my super description',
163 tags: [ 'tag1', 'tag2' ]
166 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
168 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
171 it('Should fail without a licence', function (done
) {
173 name: 'my super name',
176 description: 'my super description',
177 tags: [ 'tag1', 'tag2' ]
180 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
182 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
185 it('Should fail with a bad licence', function (done
) {
187 name: 'my super name',
191 description: 'my super description',
192 tags: [ 'tag1', 'tag2' ]
195 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
197 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
200 it('Should fail without nsfw attribute', function (done
) {
202 name: 'my super name',
205 description: 'my super description',
206 tags: [ 'tag1', 'tag2' ]
209 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
211 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
214 it('Should fail with a bad nsfw attribue', function (done
) {
216 name: 'my super name',
220 description: 'my super description',
221 tags: [ 'tag1', 'tag2' ]
224 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
226 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
229 it('Should fail without description', function (done
) {
231 name: 'my super name',
235 tags: [ 'tag1', 'tag2' ]
238 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
240 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
243 it('Should fail with a long description', function (done
) {
245 name: 'my super name',
249 description: 'my super description which is very very very very very very very very very very very very very very' +
250 'very very very very very very very very very very very very very very very very very very very very very' +
251 'very very very very very very very very very very very very very very very long',
252 tags: [ 'tag1', 'tag2' ]
255 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
257 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
260 it('Should fail with too many tags', function (done
) {
262 name: 'my super name',
266 description: 'my super description',
267 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
270 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
272 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
275 it('Should fail with a tag length too low', function (done
) {
277 name: 'my super name',
281 description: 'my super description',
282 tags: [ 'tag1', 't' ]
285 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
287 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
290 it('Should fail with a tag length too big', function (done
) {
292 name: 'my super name',
296 description: 'my super description',
297 tags: [ 'mysupertagtoolong', 'tag1' ]
300 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
302 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
305 it('Should fail without an input file', function (done
) {
307 name: 'my super name',
311 description: 'my super description',
312 tags: [ 'tag1', 'tag2' ]
315 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
318 it('Should fail without an incorrect input file', function (done
) {
320 name: 'my super name',
324 description: 'my super description',
325 tags: [ 'tag1', 'tag2' ]
328 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short_fake.webm')
330 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
333 it('Should fail with a too big duration', function (done
) {
335 name: 'my super name',
339 description: 'my super description',
340 tags: [ 'tag1', 'tag2' ]
343 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_too_long.webm')
345 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
348 it('Should succeed with the correct parameters', function (done
) {
350 name: 'my super name',
354 description: 'my super description',
355 tags: [ 'tag1', 'tag2' ]
358 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
360 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, function () {
361 attach
.videofile
= pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.mp4')
362 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, function () {
363 attach
.videofile
= pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.ogv')
364 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
, 204)
370 describe('When updating a video', function () {
373 before(function (done
) {
374 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
377 videoId
= res
.body
.data
[0].id
383 it('Should fail with nothing', function (done
) {
385 requestsUtils
.makePutBodyRequest(server
.url
, path
, server
.accessToken
, data
, done
)
388 it('Should fail without a valid uuid', function (done
) {
393 description: 'my super description',
394 tags: [ 'tag1', 'tag2' ]
396 requestsUtils
.makePutBodyRequest(server
.url
, path
+ 'blabla', server
.accessToken
, data
, done
)
399 it('Should fail with an unknown id', function (done
) {
404 description: 'my super description',
405 tags: [ 'tag1', 'tag2' ]
407 requestsUtils
.makePutBodyRequest(server
.url
, path
+ '4da6fde3-88f7-4d16-b119-108df5630b06', server
.accessToken
, data
, done
, 404)
410 it('Should fail with a long name', function (done
) {
412 name: 'My very very very very very very very very very very very very very very very very long name',
416 description: 'my super description',
417 tags: [ 'tag1', 'tag2' ]
419 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
422 it('Should fail with a bad category', function (done
) {
424 name: 'my super name',
428 description: 'my super description',
429 tags: [ 'tag1', 'tag2' ]
431 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
434 it('Should fail with a bad licence', function (done
) {
436 name: 'my super name',
440 description: 'my super description',
441 tags: [ 'tag1', 'tag2' ]
443 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
446 it('Should fail with a bad nsfw attribute', function (done
) {
448 name: 'my super 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 long description', function (done
) {
460 name: 'my super name',
464 description: 'my super description which is very very very very very very very very very very very very very very' +
465 'very very very very very very very very very very very very very very very very very very very very very' +
466 'very very very very very very very very very very very very very very very long',
467 tags: [ 'tag1', 'tag2' ]
469 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
472 it('Should fail with too many tags', function (done
) {
474 name: 'my super name',
478 description: 'my super description',
479 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
481 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
484 it('Should fail with a tag length too low', function (done
) {
486 name: 'my super name',
490 description: 'my super description',
491 tags: [ 'tag1', 't' ]
493 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
496 it('Should fail with a tag length too big', function (done
) {
498 name: 'my super name',
502 description: 'my super description',
503 tags: [ 'mysupertagtoolong', 'tag1' ]
505 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
508 it('Should fail with a video of another user')
510 it('Should fail with a video of another pod')
513 describe('When getting a video', function () {
514 it('Should return the list of the videos with nothing', function (done
) {
517 .set('Accept', 'application/json')
519 .expect('Content-Type', /json/)
520 .end(function (err
, res
) {
523 expect(res
.body
.data
).to
.be
.an('array')
524 expect(res
.body
.data
.length
).to
.equal(3)
530 it('Should fail without a correct uuid', function (done
) {
532 .get(path
+ 'coucou')
533 .set('Accept', 'application/json')
537 it('Should return 404 with an incorrect video', function (done
) {
539 .get(path
+ '4da6fde3-88f7-4d16-b119-108df5630b06')
540 .set('Accept', 'application/json')
544 it('Should succeed with the correct parameters')
547 describe('When rating a video', function () {
550 before(function (done
) {
551 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
554 videoId
= res
.body
.data
[0].id
560 it('Should fail without a valid uuid', function (done
) {
564 requestsUtils
.makePutBodyRequest(server
.url
, path
+ 'blabla/rate', server
.accessToken
, data
, done
)
567 it('Should fail with an unknown id', function (done
) {
571 requestsUtils
.makePutBodyRequest(server
.url
, path
+ '4da6fde3-88f7-4d16-b119-108df5630b06/rate', server
.accessToken
, data
, done
, 404)
574 it('Should fail with a wrong rating', function (done
) {
578 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
+ '/rate', server
.accessToken
, data
, done
)
581 it('Should succeed with the correct parameters', function (done
) {
585 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
+ '/rate', server
.accessToken
, data
, done
, 204)
589 describe('When removing a video', function () {
590 it('Should have 404 with nothing', function (done
) {
593 .set('Authorization', 'Bearer ' + server
.accessToken
)
597 it('Should fail without a correct uuid', function (done
) {
599 .delete(path
+ 'hello')
600 .set('Authorization', 'Bearer ' + server
.accessToken
)
604 it('Should fail with a video which does not exist', function (done
) {
606 .delete(path
+ '4da6fde3-88f7-4d16-b119-108df5630b06')
607 .set('Authorization', 'Bearer ' + server
.accessToken
)
611 it('Should fail with a video of another user')
613 it('Should fail with a video of another pod')
615 it('Should succeed with the correct parameters')
618 after(function (done
) {
619 process
.kill(-server
.app
.pid
)
621 // Keep the logs if the test failed
623 serversUtils
.flushTests(done
)