]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/videos.js
Server: add licence video attribute
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / videos.js
1 /* eslint-disable no-unused-expressions */
2
3 'use strict'
4
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')
10
11 const loginUtils = require('../../utils/login')
12 const requestsUtils = require('../../utils/requests')
13 const serversUtils = require('../../utils/servers')
14 const videosUtils = require('../../utils/videos')
15
16 describe('Test videos API validator', function () {
17 const path = '/api/v1/videos/'
18 let server = null
19
20 // ---------------------------------------------------------------
21
22 before(function (done) {
23 this.timeout(20000)
24
25 series([
26 function (next) {
27 serversUtils.flushTests(next)
28 },
29 function (next) {
30 serversUtils.runServer(1, function (server1) {
31 server = server1
32
33 next()
34 })
35 },
36 function (next) {
37 loginUtils.loginAndGetAccessToken(server, function (err, token) {
38 if (err) throw err
39 server.accessToken = token
40
41 next()
42 })
43 }
44 ], done)
45 })
46
47 describe('When listing a video', function () {
48 it('Should fail with a bad start pagination', function (done) {
49 request(server.url)
50 .get(path)
51 .query({ start: 'hello' })
52 .set('Accept', 'application/json')
53 .expect(400, done)
54 })
55
56 it('Should fail with a bad count pagination', function (done) {
57 request(server.url)
58 .get(path)
59 .query({ count: 'hello' })
60 .set('Accept', 'application/json')
61 .expect(400, done)
62 })
63
64 it('Should fail with an incorrect sort', function (done) {
65 request(server.url)
66 .get(path)
67 .query({ sort: 'hello' })
68 .set('Accept', 'application/json')
69 .expect(400, done)
70 })
71 })
72
73 describe('When searching a video', function () {
74 it('Should fail with nothing', function (done) {
75 request(server.url)
76 .get(pathUtils.join(path, 'search'))
77 .set('Accept', 'application/json')
78 .expect(400, done)
79 })
80
81 it('Should fail with a bad start pagination', function (done) {
82 request(server.url)
83 .get(pathUtils.join(path, 'search', 'test'))
84 .query({ start: 'hello' })
85 .set('Accept', 'application/json')
86 .expect(400, done)
87 })
88
89 it('Should fail with a bad count pagination', function (done) {
90 request(server.url)
91 .get(pathUtils.join(path, 'search', 'test'))
92 .query({ count: 'hello' })
93 .set('Accept', 'application/json')
94 .expect(400, done)
95 })
96
97 it('Should fail with an incorrect sort', function (done) {
98 request(server.url)
99 .get(pathUtils.join(path, 'search', 'test'))
100 .query({ sort: 'hello' })
101 .set('Accept', 'application/json')
102 .expect(400, done)
103 })
104 })
105
106 describe('When adding a video', function () {
107 it('Should fail with nothing', function (done) {
108 const data = {}
109 const attach = {}
110 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
111 })
112
113 it('Should fail without name', function (done) {
114 const data = {
115 category: 5,
116 licence: 1,
117 description: 'my super description',
118 tags: [ 'tag1', 'tag2' ]
119 }
120 const attach = {
121 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
122 }
123 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
124 })
125
126 it('Should fail with a long name', function (done) {
127 const data = {
128 name: 'My very very very very very very very very very very very very very very very very long name',
129 category: 5,
130 licence: 1,
131 description: 'my super description',
132 tags: [ 'tag1', 'tag2' ]
133 }
134 const attach = {
135 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
136 }
137 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
138 })
139
140 it('Should fail without a category', function (done) {
141 const data = {
142 name: 'my super name',
143 licence: 1,
144 description: 'my super description',
145 tags: [ 'tag1', 'tag2' ]
146 }
147 const attach = {
148 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
149 }
150 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
151 })
152
153 it('Should fail with a bad category', function (done) {
154 const data = {
155 name: 'my super name',
156 category: 125,
157 licence: 1,
158 description: 'my super description',
159 tags: [ 'tag1', 'tag2' ]
160 }
161 const attach = {
162 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
163 }
164 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
165 })
166
167 it('Should fail without a licence', function (done) {
168 const data = {
169 name: 'my super name',
170 category: 5,
171 description: 'my super description',
172 tags: [ 'tag1', 'tag2' ]
173 }
174 const attach = {
175 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
176 }
177 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
178 })
179
180 it('Should fail with a bad licence', function (done) {
181 const data = {
182 name: 'my super name',
183 category: 5,
184 licence: 125,
185 description: 'my super description',
186 tags: [ 'tag1', 'tag2' ]
187 }
188 const attach = {
189 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
190 }
191 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
192 })
193
194 it('Should fail without description', function (done) {
195 const data = {
196 name: 'my super name',
197 category: 5,
198 licence: 1,
199 tags: [ 'tag1', 'tag2' ]
200 }
201 const attach = {
202 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
203 }
204 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
205 })
206
207 it('Should fail with a long description', function (done) {
208 const data = {
209 name: 'my super name',
210 category: 5,
211 licence: 1,
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' ]
216 }
217 const attach = {
218 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
219 }
220 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
221 })
222
223 it('Should fail with too many tags', function (done) {
224 const data = {
225 name: 'my super name',
226 category: 5,
227 licence: 1,
228 description: 'my super description',
229 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
230 }
231 const attach = {
232 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
233 }
234 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
235 })
236
237 it('Should fail with a tag length too low', function (done) {
238 const data = {
239 name: 'my super name',
240 category: 5,
241 licence: 1,
242 description: 'my super description',
243 tags: [ 'tag1', 't' ]
244 }
245 const attach = {
246 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
247 }
248 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
249 })
250
251 it('Should fail with a tag length too big', function (done) {
252 const data = {
253 name: 'my super name',
254 category: 5,
255 licence: 1,
256 description: 'my super description',
257 tags: [ 'mysupertagtoolong', 'tag1' ]
258 }
259 const attach = {
260 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
261 }
262 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
263 })
264
265 it('Should fail without an input file', function (done) {
266 const data = {
267 name: 'my super name',
268 category: 5,
269 licence: 1,
270 description: 'my super description',
271 tags: [ 'tag1', 'tag2' ]
272 }
273 const attach = {}
274 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
275 })
276
277 it('Should fail without an incorrect input file', function (done) {
278 const data = {
279 name: 'my super name',
280 category: 5,
281 licence: 1,
282 description: 'my super description',
283 tags: [ 'tag1', 'tag2' ]
284 }
285 const attach = {
286 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
287 }
288 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
289 })
290
291 it('Should fail with a too big duration', function (done) {
292 const data = {
293 name: 'my super name',
294 category: 5,
295 licence: 1,
296 description: 'my super description',
297 tags: [ 'tag1', 'tag2' ]
298 }
299 const attach = {
300 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_too_long.webm')
301 }
302 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
303 })
304
305 it('Should succeed with the correct parameters', function (done) {
306 const data = {
307 name: 'my super name',
308 category: 5,
309 licence: 1,
310 description: 'my super description',
311 tags: [ 'tag1', 'tag2' ]
312 }
313 const attach = {
314 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
315 }
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)
321 }, false)
322 }, false)
323 })
324 })
325
326 describe('When updating a video', function () {
327 let videoId
328
329 before(function (done) {
330 videosUtils.getVideosList(server.url, function (err, res) {
331 if (err) throw err
332
333 videoId = res.body.data[0].id
334
335 return done()
336 })
337 })
338
339 it('Should fail with nothing', function (done) {
340 const data = {}
341 requestsUtils.makePutBodyRequest(server.url, path, server.accessToken, data, done)
342 })
343
344 it('Should fail without a valid uuid', function (done) {
345 const data = {
346 category: 5,
347 licence: 2,
348 description: 'my super description',
349 tags: [ 'tag1', 'tag2' ]
350 }
351 requestsUtils.makePutBodyRequest(server.url, path + 'blabla', server.accessToken, data, done)
352 })
353
354 it('Should fail with an unknown id', function (done) {
355 const data = {
356 category: 5,
357 licence: 2,
358 description: 'my super description',
359 tags: [ 'tag1', 'tag2' ]
360 }
361 requestsUtils.makePutBodyRequest(server.url, path + '4da6fde3-88f7-4d16-b119-108df5630b06', server.accessToken, data, done, 404)
362 })
363
364 it('Should fail with a long name', function (done) {
365 const data = {
366 name: 'My very very very very very very very very very very very very very very very very long name',
367 category: 5,
368 licence: 2,
369 description: 'my super description',
370 tags: [ 'tag1', 'tag2' ]
371 }
372 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
373 })
374
375 it('Should fail with a bad category', function (done) {
376 const data = {
377 name: 'my super name',
378 category: 128,
379 licence: 2,
380 description: 'my super description',
381 tags: [ 'tag1', 'tag2' ]
382 }
383 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
384 })
385
386 it('Should fail with a bad licence', function (done) {
387 const data = {
388 name: 'my super name',
389 category: 5,
390 licence: 128,
391 description: 'my super description',
392 tags: [ 'tag1', 'tag2' ]
393 }
394 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
395 })
396
397 it('Should fail with a long description', function (done) {
398 const data = {
399 name: 'my super name',
400 category: 5,
401 licence: 2,
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' ]
406 }
407 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
408 })
409
410 it('Should fail with too many tags', function (done) {
411 const data = {
412 name: 'my super name',
413 category: 5,
414 licence: 2,
415 description: 'my super description',
416 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
417 }
418 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
419 })
420
421 it('Should fail with a tag length too low', function (done) {
422 const data = {
423 name: 'my super name',
424 category: 5,
425 licence: 2,
426 description: 'my super description',
427 tags: [ 'tag1', 't' ]
428 }
429 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
430 })
431
432 it('Should fail with a tag length too big', function (done) {
433 const data = {
434 name: 'my super name',
435 category: 5,
436 licence: 2,
437 description: 'my super description',
438 tags: [ 'mysupertagtoolong', 'tag1' ]
439 }
440 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
441 })
442
443 it('Should fail with a video of another user')
444
445 it('Should fail with a video of another pod')
446 })
447
448 describe('When getting a video', function () {
449 it('Should return the list of the videos with nothing', function (done) {
450 request(server.url)
451 .get(path)
452 .set('Accept', 'application/json')
453 .expect(200)
454 .expect('Content-Type', /json/)
455 .end(function (err, res) {
456 if (err) throw err
457
458 expect(res.body.data).to.be.an('array')
459 expect(res.body.data.length).to.equal(3)
460
461 done()
462 })
463 })
464
465 it('Should fail without a correct uuid', function (done) {
466 request(server.url)
467 .get(path + 'coucou')
468 .set('Accept', 'application/json')
469 .expect(400, done)
470 })
471
472 it('Should return 404 with an incorrect video', function (done) {
473 request(server.url)
474 .get(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
475 .set('Accept', 'application/json')
476 .expect(404, done)
477 })
478
479 it('Should succeed with the correct parameters')
480 })
481
482 describe('When rating a video', function () {
483 let videoId
484
485 before(function (done) {
486 videosUtils.getVideosList(server.url, function (err, res) {
487 if (err) throw err
488
489 videoId = res.body.data[0].id
490
491 return done()
492 })
493 })
494
495 it('Should fail without a valid uuid', function (done) {
496 const data = {
497 rating: 'like'
498 }
499 requestsUtils.makePutBodyRequest(server.url, path + 'blabla/rate', server.accessToken, data, done)
500 })
501
502 it('Should fail with an unknown id', function (done) {
503 const data = {
504 rating: 'like'
505 }
506 requestsUtils.makePutBodyRequest(server.url, path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate', server.accessToken, data, done, 404)
507 })
508
509 it('Should fail with a wrong rating', function (done) {
510 const data = {
511 rating: 'likes'
512 }
513 requestsUtils.makePutBodyRequest(server.url, path + videoId + '/rate', server.accessToken, data, done)
514 })
515
516 it('Should succeed with the correct parameters', function (done) {
517 const data = {
518 rating: 'like'
519 }
520 requestsUtils.makePutBodyRequest(server.url, path + videoId + '/rate', server.accessToken, data, done, 204)
521 })
522 })
523
524 describe('When removing a video', function () {
525 it('Should have 404 with nothing', function (done) {
526 request(server.url)
527 .delete(path)
528 .set('Authorization', 'Bearer ' + server.accessToken)
529 .expect(400, done)
530 })
531
532 it('Should fail without a correct uuid', function (done) {
533 request(server.url)
534 .delete(path + 'hello')
535 .set('Authorization', 'Bearer ' + server.accessToken)
536 .expect(400, done)
537 })
538
539 it('Should fail with a video which does not exist', function (done) {
540 request(server.url)
541 .delete(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
542 .set('Authorization', 'Bearer ' + server.accessToken)
543 .expect(404, done)
544 })
545
546 it('Should fail with a video of another user')
547
548 it('Should fail with a video of another pod')
549
550 it('Should succeed with the correct parameters')
551 })
552
553 after(function (done) {
554 process.kill(-server.app.pid)
555
556 // Keep the logs if the test failed
557 if (this.ok) {
558 serversUtils.flushTests(done)
559 } else {
560 done()
561 }
562 })
563 })