]>
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 without an input file', function (done
) {
256 name: 'my super name',
258 description: 'my super description',
259 tags: [ 'tag1', 'tag2' ]
262 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
265 it('Should fail without an incorrect input file', function (done
) {
267 name: 'my super name',
269 description: 'my super description',
270 tags: [ 'tag1', 'tag2' ]
273 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short_fake.webm')
275 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
278 it('Should fail with a too big duration', function (done
) {
280 name: 'my super name',
282 description: 'my super description',
283 tags: [ 'tag1', 'tag2' ]
286 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_too_long.webm')
288 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
291 it('Should succeed with the correct parameters', function (done
) {
293 name: 'my super name',
295 description: 'my super description',
296 tags: [ 'tag1', 'tag2' ]
299 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
301 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, function () {
302 attach
.videofile
= pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.mp4')
303 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, function () {
304 attach
.videofile
= pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.ogv')
305 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
, 204)
311 describe('When updating a video', function () {
314 before(function (done
) {
315 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
318 videoId
= res
.body
.data
[0].id
324 it('Should fail with nothing', function (done
) {
326 requestsUtils
.makePutBodyRequest(server
.url
, path
, server
.accessToken
, data
, done
)
329 it('Should fail without a valid uuid', function (done
) {
332 description: 'my super description',
333 tags: [ 'tag1', 'tag2' ]
335 requestsUtils
.makePutBodyRequest(server
.url
, path
+ 'blabla', server
.accessToken
, data
, done
)
338 it('Should fail with an unknown id', function (done
) {
341 description: 'my super description',
342 tags: [ 'tag1', 'tag2' ]
344 requestsUtils
.makePutBodyRequest(server
.url
, path
+ '4da6fde3-88f7-4d16-b119-108df5630b06', server
.accessToken
, data
, done
, 404)
347 it('Should fail with a long name', function (done
) {
349 name: 'My very very very very very very very very very very very very very very very very long name',
351 description: 'my super description',
352 tags: [ 'tag1', 'tag2' ]
354 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
357 it('Should fail with a bad category', function (done
) {
359 name: 'my super name',
361 description: 'my super description',
362 tags: [ 'tag1', 'tag2' ]
364 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
367 it('Should fail with a long description', function (done
) {
369 name: 'my super name',
371 description: 'my super description which is very very very very very very very very very very very very very very' +
372 'very very very very very very very very very very very very very very very very very very very very very' +
373 'very very very very very very very very very very very very very very very long',
374 tags: [ 'tag1', 'tag2' ]
376 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
379 it('Should fail with too many tags', function (done
) {
381 name: 'my super name',
383 description: 'my super description',
384 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
386 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
389 it('Should fail with not enough tags', function (done
) {
391 name: 'my super name',
393 description: 'my super description',
396 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
399 it('Should fail with a tag length too low', function (done
) {
401 name: 'my super name',
403 description: 'my super description',
404 tags: [ 'tag1', 't' ]
406 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
409 it('Should fail with a tag length too big', function (done
) {
411 name: 'my super name',
413 description: 'my super description',
414 tags: [ 'mysupertagtoolong', 'tag1' ]
416 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
419 it('Should fail with malformed tags', function (done
) {
421 name: 'my super name',
423 description: 'my super description',
426 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
429 it('Should fail with a video of another user')
431 it('Should fail with a video of another pod')
434 describe('When getting a video', function () {
435 it('Should return the list of the videos with nothing', function (done
) {
438 .set('Accept', 'application/json')
440 .expect('Content-Type', /json/)
441 .end(function (err
, res
) {
444 expect(res
.body
.data
).to
.be
.an('array')
445 expect(res
.body
.data
.length
).to
.equal(3)
451 it('Should fail without a correct uuid', function (done
) {
453 .get(path
+ 'coucou')
454 .set('Accept', 'application/json')
458 it('Should return 404 with an incorrect video', function (done
) {
460 .get(path
+ '4da6fde3-88f7-4d16-b119-108df5630b06')
461 .set('Accept', 'application/json')
465 it('Should succeed with the correct parameters')
468 describe('When rating a video', function () {
471 before(function (done
) {
472 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
475 videoId
= res
.body
.data
[0].id
481 it('Should fail without a valid uuid', function (done
) {
485 requestsUtils
.makePutBodyRequest(server
.url
, path
+ 'blabla/rate', server
.accessToken
, data
, done
)
488 it('Should fail with an unknown id', function (done
) {
492 requestsUtils
.makePutBodyRequest(server
.url
, path
+ '4da6fde3-88f7-4d16-b119-108df5630b06/rate', server
.accessToken
, data
, done
, 404)
495 it('Should fail with a wrong rating', function (done
) {
499 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
+ '/rate', server
.accessToken
, data
, done
)
502 it('Should succeed with the correct parameters', function (done
) {
506 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
+ '/rate', server
.accessToken
, data
, done
, 204)
510 describe('When removing a video', function () {
511 it('Should have 404 with nothing', function (done
) {
514 .set('Authorization', 'Bearer ' + server
.accessToken
)
518 it('Should fail without a correct uuid', function (done
) {
520 .delete(path
+ 'hello')
521 .set('Authorization', 'Bearer ' + server
.accessToken
)
525 it('Should fail with a video which does not exist', function (done
) {
527 .delete(path
+ '4da6fde3-88f7-4d16-b119-108df5630b06')
528 .set('Authorization', 'Bearer ' + server
.accessToken
)
532 it('Should fail with a video of another user')
534 it('Should fail with a video of another pod')
536 it('Should succeed with the correct parameters')
539 after(function (done
) {
540 process
.kill(-server
.app
.pid
)
542 // Keep the logs if the test failed
544 serversUtils
.flushTests(done
)