]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/videos.js
d1830529119c8d35881d558de11bab98232ea5cb
3 const chai
= require('chai')
4 const expect
= chai
.expect
5 const pathUtils
= require('path')
6 const request
= require('supertest')
7 const series
= require('async/series')
9 const loginUtils
= require('../../utils/login')
10 const requestsUtils
= require('../../utils/requests')
11 const serversUtils
= require('../../utils/servers')
12 const videosUtils
= require('../../utils/videos')
14 describe('Test videos API validator', function () {
15 const path
= '/api/v1/videos/'
18 // ---------------------------------------------------------------
20 before(function (done
) {
25 serversUtils
.flushTests(next
)
28 serversUtils
.runServer(1, function (server1
) {
35 loginUtils
.loginAndGetAccessToken(server
, function (err
, token
) {
37 server
.accessToken
= token
45 describe('When listing a video', function () {
46 it('Should fail with a bad start pagination', function (done
) {
49 .query({ start: 'hello' })
50 .set('Accept', 'application/json')
54 it('Should fail with a bad count pagination', function (done
) {
57 .query({ count: 'hello' })
58 .set('Accept', 'application/json')
62 it('Should fail with an incorrect sort', function (done
) {
65 .query({ sort: 'hello' })
66 .set('Accept', 'application/json')
71 describe('When searching a video', function () {
72 it('Should fail with nothing', function (done
) {
74 .get(pathUtils
.join(path
, 'search'))
75 .set('Accept', 'application/json')
79 it('Should fail with a bad start pagination', function (done
) {
81 .get(pathUtils
.join(path
, 'search', 'test'))
82 .query({ start: 'hello' })
83 .set('Accept', 'application/json')
87 it('Should fail with a bad count pagination', function (done
) {
89 .get(pathUtils
.join(path
, 'search', 'test'))
90 .query({ count: 'hello' })
91 .set('Accept', 'application/json')
95 it('Should fail with an incorrect sort', function (done
) {
97 .get(pathUtils
.join(path
, 'search', 'test'))
98 .query({ sort: 'hello' })
99 .set('Accept', 'application/json')
104 describe('When adding a video', function () {
105 it('Should fail with nothing', function (done
) {
108 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
111 it('Should fail without name', function (done
) {
113 description: 'my super description',
114 tags: [ 'tag1', 'tag2' ]
117 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
119 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
122 it('Should fail with a long name', function (done
) {
124 name: 'My very very very very very very very very very very very very very very very very long name',
125 description: 'my super description',
126 tags: [ 'tag1', 'tag2' ]
129 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
131 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
134 it('Should fail without description', function (done
) {
136 name: 'my super name',
137 tags: [ 'tag1', 'tag2' ]
140 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
142 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
145 it('Should fail with a long description', function (done
) {
147 name: 'my super name',
148 description: 'my super description which is very very very very very very very very very very very very very very' +
149 'very very very very very very very very very very very very very very very very very very very very very' +
150 'very very very very very very very very very very very very very very very long',
151 tags: [ 'tag1', 'tag2' ]
154 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
156 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
159 it('Should fail without tags', function (done
) {
161 name: 'my super name',
162 description: 'my super description'
165 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
167 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
170 it('Should fail with too many tags', function (done
) {
172 name: 'my super name',
173 description: 'my super description',
174 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
177 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
179 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
182 it('Should fail with not enough tags', function (done
) {
184 name: 'my super name',
185 description: 'my super description',
189 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
191 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
194 it('Should fail with a tag length too low', function (done
) {
196 name: 'my super name',
197 description: 'my super description',
198 tags: [ 'tag1', 't' ]
201 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
203 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
206 it('Should fail with a tag length too big', function (done
) {
208 name: 'my super name',
209 description: 'my super description',
210 tags: [ 'mysupertagtoolong', 'tag1' ]
213 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
215 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
218 it('Should fail with malformed tags', function (done
) {
220 name: 'my super name',
221 description: 'my super description',
225 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
227 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
230 it('Should fail without an input file', function (done
) {
232 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',
243 description: 'my super description',
244 tags: [ 'tag1', 'tag2' ]
247 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short_fake.webm')
249 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
252 it('Should fail with a too big duration', function (done
) {
254 name: 'my super name',
255 description: 'my super description',
256 tags: [ 'tag1', 'tag2' ]
259 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_too_long.webm')
261 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
)
264 it('Should succeed with the correct parameters', function (done
) {
266 name: 'my super name',
267 description: 'my super description',
268 tags: [ 'tag1', 'tag2' ]
271 'videofile': pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.webm')
273 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, function () {
274 attach
.videofile
= pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.mp4')
275 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, function () {
276 attach
.videofile
= pathUtils
.join(__dirname
, '..', 'fixtures', 'video_short.ogv')
277 requestsUtils
.makePostUploadRequest(server
.url
, path
, server
.accessToken
, data
, attach
, done
, 204)
283 describe('When updating a video', function () {
286 before(function (done
) {
287 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
290 videoId
= res
.body
.data
[0].id
296 it('Should fail with nothing', function (done
) {
298 requestsUtils
.makePutBodyRequest(server
.url
, path
, server
.accessToken
, data
, done
)
301 it('Should fail without a valid uuid', function (done
) {
303 description: 'my super description',
304 tags: [ 'tag1', 'tag2' ]
306 requestsUtils
.makePutBodyRequest(server
.url
, path
+ 'blabla', server
.accessToken
, data
, done
)
309 it('Should fail with an unknown id', function (done
) {
311 description: 'my super description',
312 tags: [ 'tag1', 'tag2' ]
314 requestsUtils
.makePutBodyRequest(server
.url
, path
+ '4da6fde3-88f7-4d16-b119-108df5630b06', server
.accessToken
, data
, done
, 404)
317 it('Should fail with a long name', function (done
) {
319 name: 'My very very very very very very very very very very very very very very very very long name',
320 description: 'my super description',
321 tags: [ 'tag1', 'tag2' ]
323 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
326 it('Should fail with a long description', function (done
) {
328 name: 'my super name',
329 description: 'my super description which is very very very very very very very very very very very very very very' +
330 'very very very very very very very very very very very very very very very very very very very very very' +
331 'very very very very very very very very very very very very very very very long',
332 tags: [ 'tag1', 'tag2' ]
334 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
337 it('Should fail with too many tags', function (done
) {
339 name: 'my super name',
340 description: 'my super description',
341 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
343 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
346 it('Should fail with not enough tags', function (done
) {
348 name: 'my super name',
349 description: 'my super description',
352 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
355 it('Should fail with a tag length too low', function (done
) {
357 name: 'my super name',
358 description: 'my super description',
359 tags: [ 'tag1', 't' ]
361 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
364 it('Should fail with a tag length too big', function (done
) {
366 name: 'my super name',
367 description: 'my super description',
368 tags: [ 'mysupertagtoolong', 'tag1' ]
370 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
373 it('Should fail with malformed tags', function (done
) {
375 name: 'my super name',
376 description: 'my super description',
379 requestsUtils
.makePutBodyRequest(server
.url
, path
+ videoId
, server
.accessToken
, data
, done
)
383 describe('When getting a video', function () {
384 it('Should return the list of the videos with nothing', function (done
) {
387 .set('Accept', 'application/json')
389 .expect('Content-Type', /json/)
390 .end(function (err
, res
) {
393 expect(res
.body
.data
).to
.be
.an('array')
394 expect(res
.body
.data
.length
).to
.equal(3)
400 it('Should fail without a correct uuid', function (done
) {
402 .get(path
+ 'coucou')
403 .set('Accept', 'application/json')
407 it('Should return 404 with an incorrect video', function (done
) {
409 .get(path
+ '4da6fde3-88f7-4d16-b119-108df5630b06')
410 .set('Accept', 'application/json')
414 it('Should succeed with the correct parameters')
417 describe('When removing a video', function () {
418 it('Should have 404 with nothing', function (done
) {
421 .set('Authorization', 'Bearer ' + server
.accessToken
)
425 it('Should fail without a correct uuid', function (done
) {
427 .delete(path
+ 'hello')
428 .set('Authorization', 'Bearer ' + server
.accessToken
)
432 it('Should fail with a video which does not exist', function (done
) {
434 .delete(path
+ '4da6fde3-88f7-4d16-b119-108df5630b06')
435 .set('Authorization', 'Bearer ' + server
.accessToken
)
439 it('Should fail with a video of another user')
441 it('Should fail with a video of another pod')
443 it('Should succeed with the correct parameters')
446 after(function (done
) {
447 process
.kill(-server
.app
.pid
)
449 // Keep the logs if the test failed
451 serversUtils
.flushTests(done
)