]>
Commit | Line | Data |
---|---|---|
72329aaa C |
1 | /* eslint-disable no-unused-expressions */ |
2 | ||
efe923bc C |
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 = { | |
6e07c3de | 115 | category: 5, |
efe923bc C |
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', | |
6e07c3de C |
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, | |
efe923bc C |
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', | |
6e07c3de | 166 | category: 5, |
efe923bc C |
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', | |
6e07c3de | 178 | category: 5, |
efe923bc C |
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', | |
6e07c3de | 193 | category: 5, |
efe923bc C |
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', | |
6e07c3de | 205 | category: 5, |
efe923bc C |
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', | |
6e07c3de | 218 | category: 5, |
efe923bc C |
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', | |
6e07c3de | 231 | category: 5, |
efe923bc C |
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', | |
6e07c3de | 244 | category: 5, |
efe923bc C |
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 with malformed tags', function (done) { | |
255 | const data = { | |
256 | name: 'my super name', | |
6e07c3de | 257 | category: 5, |
efe923bc C |
258 | description: 'my super description', |
259 | tags: [ 'my tag' ] | |
260 | } | |
261 | const attach = { | |
262 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | |
263 | } | |
264 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | |
265 | }) | |
266 | ||
267 | it('Should fail without an input file', function (done) { | |
268 | const data = { | |
269 | name: 'my super name', | |
6e07c3de | 270 | category: 5, |
efe923bc C |
271 | description: 'my super description', |
272 | tags: [ 'tag1', 'tag2' ] | |
273 | } | |
274 | const attach = {} | |
275 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | |
276 | }) | |
277 | ||
278 | it('Should fail without an incorrect input file', function (done) { | |
279 | const data = { | |
280 | name: 'my super name', | |
6e07c3de | 281 | category: 5, |
efe923bc C |
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', | |
6e07c3de | 294 | category: 5, |
efe923bc C |
295 | description: 'my super description', |
296 | tags: [ 'tag1', 'tag2' ] | |
297 | } | |
298 | const attach = { | |
299 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_too_long.webm') | |
300 | } | |
301 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | |
302 | }) | |
303 | ||
304 | it('Should succeed with the correct parameters', function (done) { | |
305 | const data = { | |
306 | name: 'my super name', | |
6e07c3de | 307 | category: 5, |
efe923bc C |
308 | description: 'my super description', |
309 | tags: [ 'tag1', 'tag2' ] | |
310 | } | |
311 | const attach = { | |
312 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | |
313 | } | |
314 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () { | |
315 | attach.videofile = pathUtils.join(__dirname, '..', 'fixtures', 'video_short.mp4') | |
316 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () { | |
317 | attach.videofile = pathUtils.join(__dirname, '..', 'fixtures', 'video_short.ogv') | |
318 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done, 204) | |
319 | }, false) | |
320 | }, false) | |
321 | }) | |
322 | }) | |
323 | ||
324 | describe('When updating a video', function () { | |
325 | let videoId | |
326 | ||
327 | before(function (done) { | |
328 | videosUtils.getVideosList(server.url, function (err, res) { | |
329 | if (err) throw err | |
330 | ||
331 | videoId = res.body.data[0].id | |
332 | ||
333 | return done() | |
334 | }) | |
335 | }) | |
336 | ||
337 | it('Should fail with nothing', function (done) { | |
338 | const data = {} | |
339 | requestsUtils.makePutBodyRequest(server.url, path, server.accessToken, data, done) | |
340 | }) | |
341 | ||
342 | it('Should fail without a valid uuid', function (done) { | |
343 | const data = { | |
6e07c3de | 344 | category: 5, |
efe923bc C |
345 | description: 'my super description', |
346 | tags: [ 'tag1', 'tag2' ] | |
347 | } | |
348 | requestsUtils.makePutBodyRequest(server.url, path + 'blabla', server.accessToken, data, done) | |
349 | }) | |
350 | ||
351 | it('Should fail with an unknown id', function (done) { | |
352 | const data = { | |
6e07c3de | 353 | category: 5, |
efe923bc C |
354 | description: 'my super description', |
355 | tags: [ 'tag1', 'tag2' ] | |
356 | } | |
357 | requestsUtils.makePutBodyRequest(server.url, path + '4da6fde3-88f7-4d16-b119-108df5630b06', server.accessToken, data, done, 404) | |
358 | }) | |
359 | ||
360 | it('Should fail with a long name', function (done) { | |
361 | const data = { | |
362 | name: 'My very very very very very very very very very very very very very very very very long name', | |
6e07c3de C |
363 | category: 5, |
364 | description: 'my super description', | |
365 | tags: [ 'tag1', 'tag2' ] | |
366 | } | |
367 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | |
368 | }) | |
369 | ||
370 | it('Should fail with a bad category', function (done) { | |
371 | const data = { | |
372 | name: 'my super name', | |
373 | category: 128, | |
efe923bc C |
374 | description: 'my super description', |
375 | tags: [ 'tag1', 'tag2' ] | |
376 | } | |
377 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | |
378 | }) | |
379 | ||
380 | it('Should fail with a long description', function (done) { | |
381 | const data = { | |
382 | name: 'my super name', | |
6e07c3de | 383 | category: 5, |
efe923bc C |
384 | description: 'my super description which is very very very very very very very very very very very very very very' + |
385 | 'very very very very very very very very very very very very very very very very very very very very very' + | |
386 | 'very very very very very very very very very very very very very very very long', | |
387 | tags: [ 'tag1', 'tag2' ] | |
388 | } | |
389 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | |
390 | }) | |
391 | ||
392 | it('Should fail with too many tags', function (done) { | |
393 | const data = { | |
394 | name: 'my super name', | |
6e07c3de | 395 | category: 5, |
efe923bc C |
396 | description: 'my super description', |
397 | tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] | |
398 | } | |
399 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | |
400 | }) | |
401 | ||
402 | it('Should fail with not enough tags', function (done) { | |
403 | const data = { | |
404 | name: 'my super name', | |
6e07c3de | 405 | category: 5, |
efe923bc C |
406 | description: 'my super description', |
407 | tags: [ ] | |
408 | } | |
409 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | |
410 | }) | |
411 | ||
412 | it('Should fail with a tag length too low', function (done) { | |
413 | const data = { | |
414 | name: 'my super name', | |
6e07c3de | 415 | category: 5, |
efe923bc C |
416 | description: 'my super description', |
417 | tags: [ 'tag1', 't' ] | |
418 | } | |
419 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | |
420 | }) | |
421 | ||
422 | it('Should fail with a tag length too big', function (done) { | |
423 | const data = { | |
424 | name: 'my super name', | |
6e07c3de | 425 | category: 5, |
efe923bc C |
426 | description: 'my super description', |
427 | tags: [ 'mysupertagtoolong', 'tag1' ] | |
428 | } | |
429 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | |
430 | }) | |
431 | ||
432 | it('Should fail with malformed tags', function (done) { | |
433 | const data = { | |
434 | name: 'my super name', | |
6e07c3de | 435 | category: 5, |
efe923bc C |
436 | description: 'my super description', |
437 | tags: [ 'my tag' ] | |
438 | } | |
439 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | |
440 | }) | |
45abb8b9 C |
441 | |
442 | it('Should fail with a video of another user') | |
443 | ||
444 | it('Should fail with a video of another pod') | |
efe923bc C |
445 | }) |
446 | ||
447 | describe('When getting a video', function () { | |
448 | it('Should return the list of the videos with nothing', function (done) { | |
449 | request(server.url) | |
450 | .get(path) | |
451 | .set('Accept', 'application/json') | |
452 | .expect(200) | |
453 | .expect('Content-Type', /json/) | |
454 | .end(function (err, res) { | |
455 | if (err) throw err | |
456 | ||
457 | expect(res.body.data).to.be.an('array') | |
458 | expect(res.body.data.length).to.equal(3) | |
459 | ||
460 | done() | |
461 | }) | |
462 | }) | |
463 | ||
464 | it('Should fail without a correct uuid', function (done) { | |
465 | request(server.url) | |
466 | .get(path + 'coucou') | |
467 | .set('Accept', 'application/json') | |
468 | .expect(400, done) | |
469 | }) | |
470 | ||
471 | it('Should return 404 with an incorrect video', function (done) { | |
472 | request(server.url) | |
473 | .get(path + '4da6fde3-88f7-4d16-b119-108df5630b06') | |
474 | .set('Accept', 'application/json') | |
475 | .expect(404, done) | |
476 | }) | |
477 | ||
478 | it('Should succeed with the correct parameters') | |
479 | }) | |
480 | ||
d38b8281 C |
481 | describe('When rating a video', function () { |
482 | let videoId | |
483 | ||
484 | before(function (done) { | |
485 | videosUtils.getVideosList(server.url, function (err, res) { | |
486 | if (err) throw err | |
487 | ||
488 | videoId = res.body.data[0].id | |
489 | ||
490 | return done() | |
491 | }) | |
492 | }) | |
493 | ||
494 | it('Should fail without a valid uuid', function (done) { | |
495 | const data = { | |
496 | rating: 'like' | |
497 | } | |
498 | requestsUtils.makePutBodyRequest(server.url, path + 'blabla/rate', server.accessToken, data, done) | |
499 | }) | |
500 | ||
501 | it('Should fail with an unknown id', function (done) { | |
502 | const data = { | |
503 | rating: 'like' | |
504 | } | |
505 | requestsUtils.makePutBodyRequest(server.url, path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate', server.accessToken, data, done, 404) | |
506 | }) | |
507 | ||
508 | it('Should fail with a wrong rating', function (done) { | |
509 | const data = { | |
510 | rating: 'likes' | |
511 | } | |
512 | requestsUtils.makePutBodyRequest(server.url, path + videoId + '/rate', server.accessToken, data, done) | |
513 | }) | |
514 | ||
515 | it('Should succeed with the correct parameters', function (done) { | |
516 | const data = { | |
517 | rating: 'like' | |
518 | } | |
519 | requestsUtils.makePutBodyRequest(server.url, path + videoId + '/rate', server.accessToken, data, done, 204) | |
520 | }) | |
521 | }) | |
522 | ||
efe923bc C |
523 | describe('When removing a video', function () { |
524 | it('Should have 404 with nothing', function (done) { | |
525 | request(server.url) | |
526 | .delete(path) | |
527 | .set('Authorization', 'Bearer ' + server.accessToken) | |
528 | .expect(400, done) | |
529 | }) | |
530 | ||
531 | it('Should fail without a correct uuid', function (done) { | |
532 | request(server.url) | |
533 | .delete(path + 'hello') | |
534 | .set('Authorization', 'Bearer ' + server.accessToken) | |
535 | .expect(400, done) | |
536 | }) | |
537 | ||
538 | it('Should fail with a video which does not exist', function (done) { | |
539 | request(server.url) | |
540 | .delete(path + '4da6fde3-88f7-4d16-b119-108df5630b06') | |
541 | .set('Authorization', 'Bearer ' + server.accessToken) | |
542 | .expect(404, done) | |
543 | }) | |
544 | ||
545 | it('Should fail with a video of another user') | |
546 | ||
547 | it('Should fail with a video of another pod') | |
548 | ||
549 | it('Should succeed with the correct parameters') | |
550 | }) | |
551 | ||
552 | after(function (done) { | |
553 | process.kill(-server.app.pid) | |
554 | ||
555 | // Keep the logs if the test failed | |
556 | if (this.ok) { | |
557 | serversUtils.flushTests(done) | |
558 | } else { | |
559 | done() | |
560 | } | |
561 | }) | |
562 | }) |