]>
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
) {
116 description: 'my super description',
117 tags: [ 'tag1', 'tag2' ]
120 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
122 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
125 it('Should fail with a long name', function (done
) {
127 name: 'My very very very very very very very very very very very very very very very very long name',
129 description: 'my super description',
130 tags: [ 'tag1', 'tag2' ]
133 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
135 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
138 it('Should fail without a category', function (done
) {
140 name: 'my super name',
141 description: 'my super description',
142 tags: [ 'tag1', 'tag2' ]
145 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
147 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
150 it('Should fail with a bad category', function (done
) {
152 name: 'my super name',
154 description: 'my super description',
155 tags: [ 'tag1', 'tag2' ]
158 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
160 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
163 it('Should fail without description', function (done
) {
165 name: 'my super name',
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 with a long description', function (done
) {
177 name: 'my super name',
179 description: 'my super description which is very very very very very very very very very very very very very very' +
180 'very very very very very very very very very very very very very very very very very very very very very' +
181 'very very very very very very very very very very very very very very very long',
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 without tags', function (done
) {
192 name: 'my super name',
194 description: 'my super description'
197 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
199 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
202 it('Should fail with too many tags', function (done
) {
204 name: 'my super name',
206 description: 'my super description',
207 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
210 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
212 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
215 it('Should fail with not enough tags', function (done
) {
217 name: 'my super name',
219 description: 'my super description',
223 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
225 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
228 it('Should fail with a tag length too low', function (done
) {
230 name: 'my super name',
232 description: 'my super description',
233 tags: [ 'tag1', 't' ]
236 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
238 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
241 it('Should fail with a tag length too big', function (done
) {
243 name: 'my super name',
245 description: 'my super description',
246 tags: [ 'mysupertagtoolong', 'tag1' ]
249 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
251 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
254 it('Should fail with malformed tags', function (done
) {
256 name: 'my super name',
258 description: 'my super description',
262 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
264 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
267 it('Should fail without an input file', function (done
) {
269 name: 'my super name',
271 description: 'my super description',
272 tags: [ 'tag1', 'tag2' ]
275 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
278 it('Should fail without an incorrect input file', function (done
) {
280 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',
295 description: 'my super description',
296 tags: [ 'tag1', 'tag2' ]
299 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_too_long.webm')
301 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
304 it('Should succeed with the correct parameters', function (done
) {
306 name: 'my super name',
308 description: 'my super description',
309 tags: [ 'tag1', 'tag2' ]
312 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
314 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, function () {
315 attach
.videofile
= pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.mp4')
316 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, function () {
317 attach
.videofile
= pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.ogv')
318 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
, 204)
324 describe('When updating a video', function () {
327 before(function (done
) {
328 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
331 videoId
= res
.body
.data
[0].id
337 it('Should fail with nothing', function (done
) {
339 requestsUtils
.makePutBodyRequest(server
.url
, path
, server
.accessToken
, data
, done
)
342 it('Should fail without a valid uuid', function (done
) {
345 description: 'my super description',
346 tags: [ 'tag1', 'tag2' ]
348 requestsUtils
.makePutBodyRequest(server
.url
, path
+ 'blabla', server
.accessToken
, data
, done
)
351 it('Should fail with an unknown id', function (done
) {
354 description: 'my super description',
355 tags: [ 'tag1', 'tag2' ]
357 requestsUtils
.makePutBodyRequest(server
.url
, path
+ '4da6fde3-88f7-4d16-b119-108df5630b06', server
.accessToken
, data
, done
, 404)
360 it('Should fail with a long name', function (done
) {
362 name: 'My very very very very very very very very very very very very very very very very long name',
364 description: 'my super description',
365 tags: [ 'tag1', 'tag2' ]
367 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
370 it('Should fail with a bad category', function (done
) {
372 name: 'my super name',
374 description: 'my super description',
375 tags: [ 'tag1', 'tag2' ]
377 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
380 it('Should fail with a long description', function (done
) {
382 name: 'my super name',
384 description: 'my super description which is very very very very very very very very very very very very very very' +
385 'very very very very very very very very very very very very very very very very very very very very very' +
386 'very very very very very very very very very very very very very very very long',
387 tags: [ 'tag1', 'tag2' ]
389 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
392 it('Should fail with too many tags', function (done
) {
394 name: 'my super name',
396 description: 'my super description',
397 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
399 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
402 it('Should fail with not enough tags', function (done
) {
404 name: 'my super name',
406 description: 'my super description',
409 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
412 it('Should fail with a tag length too low', function (done
) {
414 name: 'my super name',
416 description: 'my super description',
417 tags: [ 'tag1', 't' ]
419 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
422 it('Should fail with a tag length too big', function (done
) {
424 name: 'my super name',
426 description: 'my super description',
427 tags: [ 'mysupertagtoolong', 'tag1' ]
429 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
432 it('Should fail with malformed tags', function (done
) {
434 name: 'my super name',
436 description: 'my super description',
439 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
442 it('Should fail with a video of another user')
444 it('Should fail with a video of another pod')
447 describe('When getting a video', function () {
448 it('Should return the list of the videos with nothing', function (done
) {
451 .set('Accept', 'application/json')
453 .expect('Content-Type', /json/)
454 .end(function (err
, res
) {
457 expect(res
.body
.data
).to
.be
.an('array')
458 expect(res
.body
.data
.length
).to
.equal(3)
464 it('Should fail without a correct uuid', function (done
) {
466 .get(path
+ 'coucou')
467 .set('Accept', 'application/json')
471 it('Should return 404 with an incorrect video', function (done
) {
473 .get(path
+ '4da6fde3-88f7-4d16-b119-108df5630b06')
474 .set('Accept', 'application/json')
478 it('Should succeed with the correct parameters')
481 describe('When rating a video', function () {
484 before(function (done
) {
485 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
488 videoId
= res
.body
.data
[0].id
494 it('Should fail without a valid uuid', function (done
) {
498 requestsUtils
.makePutBodyRequest(server
.url
, path
+ 'blabla/rate', server
.accessToken
, data
, done
)
501 it('Should fail with an unknown id', function (done
) {
505 requestsUtils
.makePutBodyRequest(server
.url
, path
+ '4da6fde3-88f7-4d16-b119-108df5630b06/rate', server
.accessToken
, data
, done
, 404)
508 it('Should fail with a wrong rating', function (done
) {
512 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
+ '/rate', server
.accessToken
, data
, done
)
515 it('Should succeed with the correct parameters', function (done
) {
519 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
+ '/rate', server
.accessToken
, data
, done
, 204)
523 describe('When removing a video', function () {
524 it('Should have 404 with nothing', function (done
) {
527 .set('Authorization', 'Bearer ' + server
.accessToken
)
531 it('Should fail without a correct uuid', function (done
) {
533 .delete(path
+ 'hello')
534 .set('Authorization', 'Bearer ' + server
.accessToken
)
538 it('Should fail with a video which does not exist', function (done
) {
540 .delete(path
+ '4da6fde3-88f7-4d16-b119-108df5630b06')
541 .set('Authorization', 'Bearer ' + server
.accessToken
)
545 it('Should fail with a video of another user')
547 it('Should fail with a video of another pod')
549 it('Should succeed with the correct parameters')
552 after(function (done
) {
553 process
.kill(-server
.app
.pid
)
555 // Keep the logs if the test failed
557 serversUtils
.flushTests(done
)