]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/videos.js
Relax on tags (accept any characters and not required anymore)
[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 description: 'my super description',
117 tags: [ 'tag1', 'tag2' ]
118 }
119 const attach = {
120 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
121 }
122 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
123 })
124
125 it('Should fail with a long name', function (done) {
126 const data = {
127 name: 'My very very very very very very very very very very very very very very very very long name',
128 category: 5,
129 description: 'my super description',
130 tags: [ 'tag1', 'tag2' ]
131 }
132 const attach = {
133 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
134 }
135 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
136 })
137
138 it('Should fail without a category', function (done) {
139 const data = {
140 name: 'my super name',
141 description: 'my super description',
142 tags: [ 'tag1', 'tag2' ]
143 }
144 const attach = {
145 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
146 }
147 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
148 })
149
150 it('Should fail with a bad category', function (done) {
151 const data = {
152 name: 'my super name',
153 category: 125,
154 description: 'my super description',
155 tags: [ 'tag1', 'tag2' ]
156 }
157 const attach = {
158 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
159 }
160 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
161 })
162
163 it('Should fail without description', function (done) {
164 const data = {
165 name: 'my super name',
166 category: 5,
167 tags: [ 'tag1', 'tag2' ]
168 }
169 const attach = {
170 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
171 }
172 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
173 })
174
175 it('Should fail with a long description', function (done) {
176 const data = {
177 name: 'my super name',
178 category: 5,
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' ]
183 }
184 const attach = {
185 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
186 }
187 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
188 })
189
190 it('Should fail without tags', function (done) {
191 const data = {
192 name: 'my super name',
193 category: 5,
194 description: 'my super description'
195 }
196 const attach = {
197 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
198 }
199 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
200 })
201
202 it('Should fail with too many tags', function (done) {
203 const data = {
204 name: 'my super name',
205 category: 5,
206 description: 'my super description',
207 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
208 }
209 const attach = {
210 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
211 }
212 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
213 })
214
215 it('Should fail with not enough tags', function (done) {
216 const data = {
217 name: 'my super name',
218 category: 5,
219 description: 'my super description',
220 tags: [ ]
221 }
222 const attach = {
223 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
224 }
225 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
226 })
227
228 it('Should fail with a tag length too low', function (done) {
229 const data = {
230 name: 'my super name',
231 category: 5,
232 description: 'my super description',
233 tags: [ 'tag1', 't' ]
234 }
235 const attach = {
236 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
237 }
238 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
239 })
240
241 it('Should fail with a tag length too big', function (done) {
242 const data = {
243 name: 'my super name',
244 category: 5,
245 description: 'my super description',
246 tags: [ 'mysupertagtoolong', 'tag1' ]
247 }
248 const attach = {
249 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
250 }
251 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
252 })
253
254 it('Should fail without an input file', function (done) {
255 const data = {
256 name: 'my super name',
257 category: 5,
258 description: 'my super description',
259 tags: [ 'tag1', 'tag2' ]
260 }
261 const attach = {}
262 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
263 })
264
265 it('Should fail without an incorrect input file', function (done) {
266 const data = {
267 name: 'my super name',
268 category: 5,
269 description: 'my super description',
270 tags: [ 'tag1', 'tag2' ]
271 }
272 const attach = {
273 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
274 }
275 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
276 })
277
278 it('Should fail with a too big duration', function (done) {
279 const data = {
280 name: 'my super name',
281 category: 5,
282 description: 'my super description',
283 tags: [ 'tag1', 'tag2' ]
284 }
285 const attach = {
286 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_too_long.webm')
287 }
288 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
289 })
290
291 it('Should succeed with the correct parameters', function (done) {
292 const data = {
293 name: 'my super name',
294 category: 5,
295 description: 'my super description',
296 tags: [ 'tag1', 'tag2' ]
297 }
298 const attach = {
299 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
300 }
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)
306 }, false)
307 }, false)
308 })
309 })
310
311 describe('When updating a video', function () {
312 let videoId
313
314 before(function (done) {
315 videosUtils.getVideosList(server.url, function (err, res) {
316 if (err) throw err
317
318 videoId = res.body.data[0].id
319
320 return done()
321 })
322 })
323
324 it('Should fail with nothing', function (done) {
325 const data = {}
326 requestsUtils.makePutBodyRequest(server.url, path, server.accessToken, data, done)
327 })
328
329 it('Should fail without a valid uuid', function (done) {
330 const data = {
331 category: 5,
332 description: 'my super description',
333 tags: [ 'tag1', 'tag2' ]
334 }
335 requestsUtils.makePutBodyRequest(server.url, path + 'blabla', server.accessToken, data, done)
336 })
337
338 it('Should fail with an unknown id', function (done) {
339 const data = {
340 category: 5,
341 description: 'my super description',
342 tags: [ 'tag1', 'tag2' ]
343 }
344 requestsUtils.makePutBodyRequest(server.url, path + '4da6fde3-88f7-4d16-b119-108df5630b06', server.accessToken, data, done, 404)
345 })
346
347 it('Should fail with a long name', function (done) {
348 const data = {
349 name: 'My very very very very very very very very very very very very very very very very long name',
350 category: 5,
351 description: 'my super description',
352 tags: [ 'tag1', 'tag2' ]
353 }
354 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
355 })
356
357 it('Should fail with a bad category', function (done) {
358 const data = {
359 name: 'my super name',
360 category: 128,
361 description: 'my super description',
362 tags: [ 'tag1', 'tag2' ]
363 }
364 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
365 })
366
367 it('Should fail with a long description', function (done) {
368 const data = {
369 name: 'my super name',
370 category: 5,
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' ]
375 }
376 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
377 })
378
379 it('Should fail with too many tags', function (done) {
380 const data = {
381 name: 'my super name',
382 category: 5,
383 description: 'my super description',
384 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
385 }
386 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
387 })
388
389 it('Should fail with not enough tags', function (done) {
390 const data = {
391 name: 'my super name',
392 category: 5,
393 description: 'my super description',
394 tags: [ ]
395 }
396 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
397 })
398
399 it('Should fail with a tag length too low', function (done) {
400 const data = {
401 name: 'my super name',
402 category: 5,
403 description: 'my super description',
404 tags: [ 'tag1', 't' ]
405 }
406 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
407 })
408
409 it('Should fail with a tag length too big', function (done) {
410 const data = {
411 name: 'my super name',
412 category: 5,
413 description: 'my super description',
414 tags: [ 'mysupertagtoolong', 'tag1' ]
415 }
416 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
417 })
418
419 it('Should fail with malformed tags', function (done) {
420 const data = {
421 name: 'my super name',
422 category: 5,
423 description: 'my super description',
424 tags: [ 'my tag' ]
425 }
426 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
427 })
428
429 it('Should fail with a video of another user')
430
431 it('Should fail with a video of another pod')
432 })
433
434 describe('When getting a video', function () {
435 it('Should return the list of the videos with nothing', function (done) {
436 request(server.url)
437 .get(path)
438 .set('Accept', 'application/json')
439 .expect(200)
440 .expect('Content-Type', /json/)
441 .end(function (err, res) {
442 if (err) throw err
443
444 expect(res.body.data).to.be.an('array')
445 expect(res.body.data.length).to.equal(3)
446
447 done()
448 })
449 })
450
451 it('Should fail without a correct uuid', function (done) {
452 request(server.url)
453 .get(path + 'coucou')
454 .set('Accept', 'application/json')
455 .expect(400, done)
456 })
457
458 it('Should return 404 with an incorrect video', function (done) {
459 request(server.url)
460 .get(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
461 .set('Accept', 'application/json')
462 .expect(404, done)
463 })
464
465 it('Should succeed with the correct parameters')
466 })
467
468 describe('When rating a video', function () {
469 let videoId
470
471 before(function (done) {
472 videosUtils.getVideosList(server.url, function (err, res) {
473 if (err) throw err
474
475 videoId = res.body.data[0].id
476
477 return done()
478 })
479 })
480
481 it('Should fail without a valid uuid', function (done) {
482 const data = {
483 rating: 'like'
484 }
485 requestsUtils.makePutBodyRequest(server.url, path + 'blabla/rate', server.accessToken, data, done)
486 })
487
488 it('Should fail with an unknown id', function (done) {
489 const data = {
490 rating: 'like'
491 }
492 requestsUtils.makePutBodyRequest(server.url, path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate', server.accessToken, data, done, 404)
493 })
494
495 it('Should fail with a wrong rating', function (done) {
496 const data = {
497 rating: 'likes'
498 }
499 requestsUtils.makePutBodyRequest(server.url, path + videoId + '/rate', server.accessToken, data, done)
500 })
501
502 it('Should succeed with the correct parameters', function (done) {
503 const data = {
504 rating: 'like'
505 }
506 requestsUtils.makePutBodyRequest(server.url, path + videoId + '/rate', server.accessToken, data, done, 204)
507 })
508 })
509
510 describe('When removing a video', function () {
511 it('Should have 404 with nothing', function (done) {
512 request(server.url)
513 .delete(path)
514 .set('Authorization', 'Bearer ' + server.accessToken)
515 .expect(400, done)
516 })
517
518 it('Should fail without a correct uuid', function (done) {
519 request(server.url)
520 .delete(path + 'hello')
521 .set('Authorization', 'Bearer ' + server.accessToken)
522 .expect(400, done)
523 })
524
525 it('Should fail with a video which does not exist', function (done) {
526 request(server.url)
527 .delete(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
528 .set('Authorization', 'Bearer ' + server.accessToken)
529 .expect(404, done)
530 })
531
532 it('Should fail with a video of another user')
533
534 it('Should fail with a video of another pod')
535
536 it('Should succeed with the correct parameters')
537 })
538
539 after(function (done) {
540 process.kill(-server.app.pid)
541
542 // Keep the logs if the test failed
543 if (this.ok) {
544 serversUtils.flushTests(done)
545 } else {
546 done()
547 }
548 })
549 })