]>
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
) {
117 description: 'my super description',
118 tags: [ 'tag1', 'tag2' ]
121 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
123 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
126 it('Should fail with a long name', function (done
) {
128 name: 'My very very very very very very very very very very very very very very very very long name',
131 description: 'my super description',
132 tags: [ 'tag1', 'tag2' ]
135 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
137 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
140 it('Should fail without a category', function (done
) {
142 name: 'my super name',
144 description: 'my super description',
145 tags: [ 'tag1', 'tag2' ]
148 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
150 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
153 it('Should fail with a bad category', function (done
) {
155 name: 'my super name',
158 description: 'my super description',
159 tags: [ 'tag1', 'tag2' ]
162 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
164 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
167 it('Should fail without a licence', function (done
) {
169 name: 'my super name',
171 description: 'my super description',
172 tags: [ 'tag1', 'tag2' ]
175 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
177 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
180 it('Should fail with a bad licence', function (done
) {
182 name: 'my super name',
185 description: 'my super description',
186 tags: [ 'tag1', 'tag2' ]
189 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
191 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
194 it('Should fail without description', function (done
) {
196 name: 'my super name',
199 tags: [ 'tag1', 'tag2' ]
202 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
204 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
207 it('Should fail with a long description', function (done
) {
209 name: 'my super name',
212 description: 'my super description which is very very very very very very very very very very very very very very' +
213 'very very very very very very very very very very very very very very very very very very very very very' +
214 'very very very very very very very very very very very very very very very long',
215 tags: [ 'tag1', 'tag2' ]
218 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
220 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
223 it('Should fail with too many tags', function (done
) {
225 name: 'my super name',
228 description: 'my super description',
229 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
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 tag length too low', function (done
) {
239 name: 'my super name',
242 description: 'my super description',
243 tags: [ 'tag1', 't' ]
246 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
248 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
251 it('Should fail with a tag length too big', function (done
) {
253 name: 'my super name',
256 description: 'my super description',
257 tags: [ 'mysupertagtoolong', 'tag1' ]
260 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
262 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
265 it('Should fail without an input file', function (done
) {
267 name: 'my super name',
270 description: 'my super description',
271 tags: [ 'tag1', 'tag2' ]
274 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
277 it('Should fail without an incorrect input file', function (done
) {
279 name: 'my super name',
282 description: 'my super description',
283 tags: [ 'tag1', 'tag2' ]
286 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short_fake.webm')
288 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
291 it('Should fail with a too big duration', function (done
) {
293 name: 'my super name',
296 description: 'my super description',
297 tags: [ 'tag1', 'tag2' ]
300 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_too_long.webm')
302 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
305 it('Should succeed with the correct parameters', function (done
) {
307 name: 'my super name',
310 description: 'my super description',
311 tags: [ 'tag1', 'tag2' ]
314 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
316 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, function () {
317 attach
.videofile
= pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.mp4')
318 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, function () {
319 attach
.videofile
= pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.ogv')
320 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
, 204)
326 describe('When updating a video', function () {
329 before(function (done
) {
330 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
333 videoId
= res
.body
.data
[0].id
339 it('Should fail with nothing', function (done
) {
341 requestsUtils
.makePutBodyRequest(server
.url
, path
, server
.accessToken
, data
, done
)
344 it('Should fail without a valid uuid', function (done
) {
348 description: 'my super description',
349 tags: [ 'tag1', 'tag2' ]
351 requestsUtils
.makePutBodyRequest(server
.url
, path
+ 'blabla', server
.accessToken
, data
, done
)
354 it('Should fail with an unknown id', function (done
) {
358 description: 'my super description',
359 tags: [ 'tag1', 'tag2' ]
361 requestsUtils
.makePutBodyRequest(server
.url
, path
+ '4da6fde3-88f7-4d16-b119-108df5630b06', server
.accessToken
, data
, done
, 404)
364 it('Should fail with a long name', function (done
) {
366 name: 'My very very very very very very very very very very very very very very very very long name',
369 description: 'my super description',
370 tags: [ 'tag1', 'tag2' ]
372 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
375 it('Should fail with a bad category', function (done
) {
377 name: 'my super name',
380 description: 'my super description',
381 tags: [ 'tag1', 'tag2' ]
383 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
386 it('Should fail with a bad licence', function (done
) {
388 name: 'my super name',
391 description: 'my super description',
392 tags: [ 'tag1', 'tag2' ]
394 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
397 it('Should fail with a long description', function (done
) {
399 name: 'my super name',
402 description: 'my super description which is very very very very very very very very very very very very very very' +
403 'very very very very very very very very very very very very very very very very very very very very very' +
404 'very very very very very very very very very very very very very very very long',
405 tags: [ 'tag1', 'tag2' ]
407 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
410 it('Should fail with too many tags', function (done
) {
412 name: 'my super name',
415 description: 'my super description',
416 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
418 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
421 it('Should fail with a tag length too low', function (done
) {
423 name: 'my super name',
426 description: 'my super description',
427 tags: [ 'tag1', 't' ]
429 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
432 it('Should fail with a tag length too big', function (done
) {
434 name: 'my super name',
437 description: 'my super description',
438 tags: [ 'mysupertagtoolong', 'tag1' ]
440 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
443 it('Should fail with a video of another user')
445 it('Should fail with a video of another pod')
448 describe('When getting a video', function () {
449 it('Should return the list of the videos with nothing', function (done
) {
452 .set('Accept', 'application/json')
454 .expect('Content-Type', /json/)
455 .end(function (err
, res
) {
458 expect(res
.body
.data
).to
.be
.an('array')
459 expect(res
.body
.data
.length
).to
.equal(3)
465 it('Should fail without a correct uuid', function (done
) {
467 .get(path
+ 'coucou')
468 .set('Accept', 'application/json')
472 it('Should return 404 with an incorrect video', function (done
) {
474 .get(path
+ '4da6fde3-88f7-4d16-b119-108df5630b06')
475 .set('Accept', 'application/json')
479 it('Should succeed with the correct parameters')
482 describe('When rating a video', function () {
485 before(function (done
) {
486 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
489 videoId
= res
.body
.data
[0].id
495 it('Should fail without a valid uuid', function (done
) {
499 requestsUtils
.makePutBodyRequest(server
.url
, path
+ 'blabla/rate', server
.accessToken
, data
, done
)
502 it('Should fail with an unknown id', function (done
) {
506 requestsUtils
.makePutBodyRequest(server
.url
, path
+ '4da6fde3-88f7-4d16-b119-108df5630b06/rate', server
.accessToken
, data
, done
, 404)
509 it('Should fail with a wrong rating', function (done
) {
513 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
+ '/rate', server
.accessToken
, data
, done
)
516 it('Should succeed with the correct parameters', function (done
) {
520 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
+ '/rate', server
.accessToken
, data
, done
, 204)
524 describe('When removing a video', function () {
525 it('Should have 404 with nothing', function (done
) {
528 .set('Authorization', 'Bearer ' + server
.accessToken
)
532 it('Should fail without a correct uuid', function (done
) {
534 .delete(path
+ 'hello')
535 .set('Authorization', 'Bearer ' + server
.accessToken
)
539 it('Should fail with a video which does not exist', function (done
) {
541 .delete(path
+ '4da6fde3-88f7-4d16-b119-108df5630b06')
542 .set('Authorization', 'Bearer ' + server
.accessToken
)
546 it('Should fail with a video of another user')
548 it('Should fail with a video of another pod')
550 it('Should succeed with the correct parameters')
553 after(function (done
) {
554 process
.kill(-server
.app
.pid
)
556 // Keep the logs if the test failed
558 serversUtils
.flushTests(done
)