]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/videos.js
03b4db3fe68d72ebd680eed9135672852dd5334a
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 with too many tags', function (done
) {
192 name: 'my super name',
194 description: 'my super description',
195 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
198 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
200 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
203 it('Should fail with a tag length too low', function (done
) {
205 name: 'my super name',
207 description: 'my super description',
208 tags: [ 'tag1', 't' ]
211 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
213 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
216 it('Should fail with a tag length too big', function (done
) {
218 name: 'my super name',
220 description: 'my super description',
221 tags: [ 'mysupertagtoolong', 'tag1' ]
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 an input file', function (done
) {
231 name: 'my super name',
233 description: 'my super description',
234 tags: [ 'tag1', 'tag2' ]
237 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
240 it('Should fail without an incorrect input file', function (done
) {
242 name: 'my super name',
244 description: 'my super description',
245 tags: [ 'tag1', 'tag2' ]
248 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short_fake.webm')
250 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
253 it('Should fail with a too big duration', function (done
) {
255 name: 'my super name',
257 description: 'my super description',
258 tags: [ 'tag1', 'tag2' ]
261 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_too_long.webm')
263 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
266 it('Should succeed with the correct parameters', function (done
) {
268 name: 'my super name',
270 description: 'my super description',
271 tags: [ 'tag1', 'tag2' ]
274 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
276 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, function () {
277 attach
.videofile
= pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.mp4')
278 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, function () {
279 attach
.videofile
= pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.ogv')
280 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
, 204)
286 describe('When updating a video', function () {
289 before(function (done
) {
290 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
293 videoId
= res
.body
.data
[0].id
299 it('Should fail with nothing', function (done
) {
301 requestsUtils
.makePutBodyRequest(server
.url
, path
, server
.accessToken
, data
, done
)
304 it('Should fail without a valid uuid', function (done
) {
307 description: 'my super description',
308 tags: [ 'tag1', 'tag2' ]
310 requestsUtils
.makePutBodyRequest(server
.url
, path
+ 'blabla', server
.accessToken
, data
, done
)
313 it('Should fail with an unknown id', function (done
) {
316 description: 'my super description',
317 tags: [ 'tag1', 'tag2' ]
319 requestsUtils
.makePutBodyRequest(server
.url
, path
+ '4da6fde3-88f7-4d16-b119-108df5630b06', server
.accessToken
, data
, done
, 404)
322 it('Should fail with a long name', function (done
) {
324 name: 'My very very very very very very very very very very very very very very very very long name',
326 description: 'my super description',
327 tags: [ 'tag1', 'tag2' ]
329 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
332 it('Should fail with a bad category', function (done
) {
334 name: 'my super name',
336 description: 'my super description',
337 tags: [ 'tag1', 'tag2' ]
339 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
342 it('Should fail with a long description', function (done
) {
344 name: 'my super name',
346 description: 'my super description which is very very very very very very very very very very very very very very' +
347 'very very very very very very very very very very very very very very very very very very very very very' +
348 'very very very very very very very very very very very very very very very long',
349 tags: [ 'tag1', 'tag2' ]
351 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
354 it('Should fail with too many tags', function (done
) {
356 name: 'my super name',
358 description: 'my super description',
359 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
361 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
364 it('Should fail with a tag length too low', function (done
) {
366 name: 'my super name',
368 description: 'my super description',
369 tags: [ 'tag1', 't' ]
371 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
374 it('Should fail with a tag length too big', function (done
) {
376 name: 'my super name',
378 description: 'my super description',
379 tags: [ 'mysupertagtoolong', 'tag1' ]
381 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
384 it('Should fail with a video of another user')
386 it('Should fail with a video of another pod')
389 describe('When getting a video', function () {
390 it('Should return the list of the videos with nothing', function (done
) {
393 .set('Accept', 'application/json')
395 .expect('Content-Type', /json/)
396 .end(function (err
, res
) {
399 expect(res
.body
.data
).to
.be
.an('array')
400 expect(res
.body
.data
.length
).to
.equal(3)
406 it('Should fail without a correct uuid', function (done
) {
408 .get(path
+ 'coucou')
409 .set('Accept', 'application/json')
413 it('Should return 404 with an incorrect video', function (done
) {
415 .get(path
+ '4da6fde3-88f7-4d16-b119-108df5630b06')
416 .set('Accept', 'application/json')
420 it('Should succeed with the correct parameters')
423 describe('When rating a video', function () {
426 before(function (done
) {
427 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
430 videoId
= res
.body
.data
[0].id
436 it('Should fail without a valid uuid', function (done
) {
440 requestsUtils
.makePutBodyRequest(server
.url
, path
+ 'blabla/rate', server
.accessToken
, data
, done
)
443 it('Should fail with an unknown id', function (done
) {
447 requestsUtils
.makePutBodyRequest(server
.url
, path
+ '4da6fde3-88f7-4d16-b119-108df5630b06/rate', server
.accessToken
, data
, done
, 404)
450 it('Should fail with a wrong rating', function (done
) {
454 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
+ '/rate', server
.accessToken
, data
, done
)
457 it('Should succeed with the correct parameters', function (done
) {
461 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
+ '/rate', server
.accessToken
, data
, done
, 204)
465 describe('When removing a video', function () {
466 it('Should have 404 with nothing', function (done
) {
469 .set('Authorization', 'Bearer ' + server
.accessToken
)
473 it('Should fail without a correct uuid', function (done
) {
475 .delete(path
+ 'hello')
476 .set('Authorization', 'Bearer ' + server
.accessToken
)
480 it('Should fail with a video which does not exist', function (done
) {
482 .delete(path
+ '4da6fde3-88f7-4d16-b119-108df5630b06')
483 .set('Authorization', 'Bearer ' + server
.accessToken
)
487 it('Should fail with a video of another user')
489 it('Should fail with a video of another pod')
491 it('Should succeed with the correct parameters')
494 after(function (done
) {
495 process
.kill(-server
.app
.pid
)
497 // Keep the logs if the test failed
499 serversUtils
.flushTests(done
)