]>
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, |
6f0c39e2 | 116 | licence: 1, |
3092476e | 117 | language: 6, |
31b59b47 | 118 | nsfw: false, |
efe923bc C |
119 | description: 'my super description', |
120 | tags: [ 'tag1', 'tag2' ] | |
121 | } | |
122 | const attach = { | |
123 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | |
124 | } | |
125 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | |
126 | }) | |
127 | ||
128 | it('Should fail with a long name', function (done) { | |
129 | const data = { | |
130 | name: 'My very very very very very very very very very very very very very very very very long name', | |
6e07c3de | 131 | category: 5, |
6f0c39e2 | 132 | licence: 1, |
3092476e | 133 | language: 6, |
31b59b47 | 134 | nsfw: false, |
6e07c3de C |
135 | description: 'my super description', |
136 | tags: [ 'tag1', 'tag2' ] | |
137 | } | |
138 | const attach = { | |
139 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | |
140 | } | |
141 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | |
142 | }) | |
143 | ||
144 | it('Should fail without a category', function (done) { | |
145 | const data = { | |
146 | name: 'my super name', | |
6f0c39e2 | 147 | licence: 1, |
3092476e | 148 | language: 6, |
31b59b47 | 149 | nsfw: false, |
6e07c3de C |
150 | description: 'my super description', |
151 | tags: [ 'tag1', 'tag2' ] | |
152 | } | |
153 | const attach = { | |
154 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | |
155 | } | |
156 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | |
157 | }) | |
158 | ||
159 | it('Should fail with a bad category', function (done) { | |
160 | const data = { | |
161 | name: 'my super name', | |
162 | category: 125, | |
6f0c39e2 | 163 | licence: 1, |
3092476e | 164 | language: 6, |
31b59b47 | 165 | nsfw: false, |
6f0c39e2 C |
166 | description: 'my super description', |
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 without a licence', function (done) { | |
176 | const data = { | |
177 | name: 'my super name', | |
178 | category: 5, | |
3092476e | 179 | language: 6, |
31b59b47 | 180 | nsfw: false, |
6f0c39e2 C |
181 | description: 'my super description', |
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 with a bad licence', function (done) { | |
191 | const data = { | |
192 | name: 'my super name', | |
193 | category: 5, | |
194 | licence: 125, | |
3092476e C |
195 | language: 6, |
196 | nsfw: false, | |
197 | description: 'my super description', | |
198 | tags: [ 'tag1', 'tag2' ] | |
199 | } | |
200 | const attach = { | |
201 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | |
202 | } | |
203 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | |
204 | }) | |
205 | ||
206 | it('Should fail with a bad language', function (done) { | |
207 | const data = { | |
208 | name: 'my super name', | |
209 | category: 5, | |
210 | licence: 4, | |
211 | language: 563, | |
31b59b47 C |
212 | nsfw: false, |
213 | description: 'my super description', | |
214 | tags: [ 'tag1', 'tag2' ] | |
215 | } | |
216 | const attach = { | |
217 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | |
218 | } | |
219 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | |
220 | }) | |
221 | ||
222 | it('Should fail without nsfw attribute', function (done) { | |
223 | const data = { | |
224 | name: 'my super name', | |
225 | category: 5, | |
226 | licence: 4, | |
3092476e | 227 | language: 6, |
31b59b47 C |
228 | description: 'my super description', |
229 | tags: [ 'tag1', 'tag2' ] | |
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 bad nsfw attribue', function (done) { | |
238 | const data = { | |
239 | name: 'my super name', | |
240 | category: 5, | |
241 | licence: 4, | |
3092476e | 242 | language: 6, |
31b59b47 | 243 | nsfw: 2, |
efe923bc C |
244 | description: 'my super description', |
245 | tags: [ 'tag1', 'tag2' ] | |
246 | } | |
247 | const attach = { | |
248 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | |
249 | } | |
250 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | |
251 | }) | |
252 | ||
253 | it('Should fail without description', function (done) { | |
254 | const data = { | |
255 | name: 'my super name', | |
6e07c3de | 256 | category: 5, |
6f0c39e2 | 257 | licence: 1, |
3092476e | 258 | language: 6, |
31b59b47 | 259 | nsfw: false, |
efe923bc C |
260 | tags: [ 'tag1', 'tag2' ] |
261 | } | |
262 | const attach = { | |
263 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | |
264 | } | |
265 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | |
266 | }) | |
267 | ||
268 | it('Should fail with a long description', function (done) { | |
269 | const data = { | |
270 | name: 'my super name', | |
6e07c3de | 271 | category: 5, |
6f0c39e2 | 272 | licence: 1, |
3092476e | 273 | language: 6, |
31b59b47 | 274 | nsfw: false, |
efe923bc C |
275 | description: 'my super description which is very very very very very very very very very very very very very very' + |
276 | 'very very very very very very very very very very very very very very very very very very very very very' + | |
277 | 'very very very very very very very very very very very very very very very long', | |
278 | tags: [ 'tag1', 'tag2' ] | |
279 | } | |
280 | const attach = { | |
281 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | |
282 | } | |
283 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | |
284 | }) | |
285 | ||
efe923bc C |
286 | it('Should fail with too many tags', function (done) { |
287 | const data = { | |
288 | name: 'my super name', | |
6e07c3de | 289 | category: 5, |
6f0c39e2 | 290 | licence: 1, |
3092476e | 291 | language: 6, |
31b59b47 | 292 | nsfw: false, |
efe923bc C |
293 | description: 'my super description', |
294 | tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] | |
295 | } | |
296 | const attach = { | |
297 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | |
298 | } | |
299 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | |
300 | }) | |
301 | ||
efe923bc C |
302 | it('Should fail with a tag length too low', function (done) { |
303 | const data = { | |
304 | name: 'my super name', | |
6e07c3de | 305 | category: 5, |
6f0c39e2 | 306 | licence: 1, |
3092476e | 307 | language: 6, |
31b59b47 | 308 | nsfw: false, |
efe923bc C |
309 | description: 'my super description', |
310 | tags: [ 'tag1', 't' ] | |
311 | } | |
312 | const attach = { | |
313 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | |
314 | } | |
315 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | |
316 | }) | |
317 | ||
318 | it('Should fail with a tag length too big', function (done) { | |
319 | const data = { | |
320 | name: 'my super name', | |
6e07c3de | 321 | category: 5, |
6f0c39e2 | 322 | licence: 1, |
3092476e | 323 | language: 6, |
31b59b47 | 324 | nsfw: false, |
efe923bc C |
325 | description: 'my super description', |
326 | tags: [ 'mysupertagtoolong', 'tag1' ] | |
327 | } | |
328 | const attach = { | |
329 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | |
330 | } | |
331 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | |
332 | }) | |
333 | ||
efe923bc C |
334 | it('Should fail without an input file', function (done) { |
335 | const data = { | |
336 | name: 'my super name', | |
6e07c3de | 337 | category: 5, |
6f0c39e2 | 338 | licence: 1, |
3092476e | 339 | language: 6, |
31b59b47 | 340 | nsfw: false, |
efe923bc C |
341 | description: 'my super description', |
342 | tags: [ 'tag1', 'tag2' ] | |
343 | } | |
344 | const attach = {} | |
345 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | |
346 | }) | |
347 | ||
348 | it('Should fail without an incorrect input file', function (done) { | |
349 | const data = { | |
350 | name: 'my super name', | |
6e07c3de | 351 | category: 5, |
6f0c39e2 | 352 | licence: 1, |
3092476e | 353 | language: 6, |
31b59b47 | 354 | nsfw: false, |
efe923bc C |
355 | description: 'my super description', |
356 | tags: [ 'tag1', 'tag2' ] | |
357 | } | |
358 | const attach = { | |
359 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short_fake.webm') | |
360 | } | |
361 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | |
362 | }) | |
363 | ||
364 | it('Should fail with a too big duration', function (done) { | |
365 | const data = { | |
366 | name: 'my super name', | |
6e07c3de | 367 | category: 5, |
6f0c39e2 | 368 | licence: 1, |
3092476e | 369 | language: 6, |
31b59b47 | 370 | nsfw: false, |
efe923bc C |
371 | description: 'my super description', |
372 | tags: [ 'tag1', 'tag2' ] | |
373 | } | |
374 | const attach = { | |
375 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_too_long.webm') | |
376 | } | |
377 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done) | |
378 | }) | |
379 | ||
380 | it('Should succeed with the correct parameters', function (done) { | |
381 | const data = { | |
382 | name: 'my super name', | |
6e07c3de | 383 | category: 5, |
6f0c39e2 | 384 | licence: 1, |
3092476e | 385 | language: 6, |
31b59b47 | 386 | nsfw: false, |
efe923bc C |
387 | description: 'my super description', |
388 | tags: [ 'tag1', 'tag2' ] | |
389 | } | |
390 | const attach = { | |
391 | 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm') | |
392 | } | |
393 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () { | |
394 | attach.videofile = pathUtils.join(__dirname, '..', 'fixtures', 'video_short.mp4') | |
395 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () { | |
396 | attach.videofile = pathUtils.join(__dirname, '..', 'fixtures', 'video_short.ogv') | |
397 | requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done, 204) | |
398 | }, false) | |
399 | }, false) | |
400 | }) | |
401 | }) | |
402 | ||
403 | describe('When updating a video', function () { | |
404 | let videoId | |
405 | ||
406 | before(function (done) { | |
407 | videosUtils.getVideosList(server.url, function (err, res) { | |
408 | if (err) throw err | |
409 | ||
410 | videoId = res.body.data[0].id | |
411 | ||
412 | return done() | |
413 | }) | |
414 | }) | |
415 | ||
416 | it('Should fail with nothing', function (done) { | |
417 | const data = {} | |
418 | requestsUtils.makePutBodyRequest(server.url, path, server.accessToken, data, done) | |
419 | }) | |
420 | ||
421 | it('Should fail without a valid uuid', function (done) { | |
422 | const data = { | |
6e07c3de | 423 | category: 5, |
6f0c39e2 | 424 | licence: 2, |
3092476e | 425 | language: 6, |
31b59b47 | 426 | nsfw: false, |
efe923bc C |
427 | description: 'my super description', |
428 | tags: [ 'tag1', 'tag2' ] | |
429 | } | |
430 | requestsUtils.makePutBodyRequest(server.url, path + 'blabla', server.accessToken, data, done) | |
431 | }) | |
432 | ||
433 | it('Should fail with an unknown id', function (done) { | |
434 | const data = { | |
6e07c3de | 435 | category: 5, |
6f0c39e2 | 436 | licence: 2, |
3092476e | 437 | language: 6, |
31b59b47 | 438 | nsfw: false, |
efe923bc C |
439 | description: 'my super description', |
440 | tags: [ 'tag1', 'tag2' ] | |
441 | } | |
442 | requestsUtils.makePutBodyRequest(server.url, path + '4da6fde3-88f7-4d16-b119-108df5630b06', server.accessToken, data, done, 404) | |
443 | }) | |
444 | ||
445 | it('Should fail with a long name', function (done) { | |
446 | const data = { | |
447 | name: 'My very very very very very very very very very very very very very very very very long name', | |
6e07c3de | 448 | category: 5, |
6f0c39e2 | 449 | licence: 2, |
3092476e | 450 | language: 6, |
31b59b47 | 451 | nsfw: false, |
6e07c3de C |
452 | description: 'my super description', |
453 | tags: [ 'tag1', 'tag2' ] | |
454 | } | |
455 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | |
456 | }) | |
457 | ||
458 | it('Should fail with a bad category', function (done) { | |
459 | const data = { | |
460 | name: 'my super name', | |
461 | category: 128, | |
6f0c39e2 | 462 | licence: 2, |
3092476e | 463 | language: 6, |
31b59b47 | 464 | nsfw: false, |
6f0c39e2 C |
465 | description: 'my super description', |
466 | tags: [ 'tag1', 'tag2' ] | |
467 | } | |
468 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | |
469 | }) | |
470 | ||
471 | it('Should fail with a bad licence', function (done) { | |
472 | const data = { | |
473 | name: 'my super name', | |
474 | category: 5, | |
475 | licence: 128, | |
3092476e C |
476 | language: 6, |
477 | nsfw: false, | |
478 | description: 'my super description', | |
479 | tags: [ 'tag1', 'tag2' ] | |
480 | } | |
481 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | |
482 | }) | |
483 | ||
484 | it('Should fail with a bad language', function (done) { | |
485 | const data = { | |
486 | name: 'my super name', | |
487 | category: 5, | |
488 | licence: 3, | |
489 | language: 896, | |
31b59b47 C |
490 | nsfw: false, |
491 | description: 'my super description', | |
492 | tags: [ 'tag1', 'tag2' ] | |
493 | } | |
494 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | |
495 | }) | |
496 | ||
497 | it('Should fail with a bad nsfw attribute', function (done) { | |
498 | const data = { | |
499 | name: 'my super name', | |
500 | category: 5, | |
501 | licence: 5, | |
3092476e | 502 | language: 6, |
31b59b47 | 503 | nsfw: -4, |
efe923bc C |
504 | description: 'my super description', |
505 | tags: [ 'tag1', 'tag2' ] | |
506 | } | |
507 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | |
508 | }) | |
509 | ||
510 | it('Should fail with a long description', function (done) { | |
511 | const data = { | |
512 | name: 'my super name', | |
6e07c3de | 513 | category: 5, |
6f0c39e2 | 514 | licence: 2, |
3092476e | 515 | language: 6, |
31b59b47 | 516 | nsfw: false, |
efe923bc C |
517 | description: 'my super description which is very very very very very very very very very very very very very very' + |
518 | 'very very very very very very very very very very very very very very very very very very very very very' + | |
519 | 'very very very very very very very very very very very very very very very long', | |
520 | tags: [ 'tag1', 'tag2' ] | |
521 | } | |
522 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | |
523 | }) | |
524 | ||
525 | it('Should fail with too many tags', function (done) { | |
526 | const data = { | |
527 | name: 'my super name', | |
6e07c3de | 528 | category: 5, |
6f0c39e2 | 529 | licence: 2, |
3092476e | 530 | language: 6, |
31b59b47 | 531 | nsfw: false, |
efe923bc C |
532 | description: 'my super description', |
533 | tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] | |
534 | } | |
535 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | |
536 | }) | |
537 | ||
efe923bc C |
538 | it('Should fail with a tag length too low', function (done) { |
539 | const data = { | |
540 | name: 'my super name', | |
6e07c3de | 541 | category: 5, |
6f0c39e2 | 542 | licence: 2, |
3092476e | 543 | language: 6, |
31b59b47 | 544 | nsfw: false, |
efe923bc C |
545 | description: 'my super description', |
546 | tags: [ 'tag1', 't' ] | |
547 | } | |
548 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | |
549 | }) | |
550 | ||
551 | it('Should fail with a tag length too big', function (done) { | |
552 | const data = { | |
553 | name: 'my super name', | |
6e07c3de | 554 | category: 5, |
6f0c39e2 | 555 | licence: 2, |
3092476e | 556 | language: 6, |
31b59b47 | 557 | nsfw: false, |
efe923bc C |
558 | description: 'my super description', |
559 | tags: [ 'mysupertagtoolong', 'tag1' ] | |
560 | } | |
561 | requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done) | |
562 | }) | |
563 | ||
45abb8b9 C |
564 | it('Should fail with a video of another user') |
565 | ||
566 | it('Should fail with a video of another pod') | |
efe923bc C |
567 | }) |
568 | ||
569 | describe('When getting a video', function () { | |
570 | it('Should return the list of the videos with nothing', function (done) { | |
571 | request(server.url) | |
572 | .get(path) | |
573 | .set('Accept', 'application/json') | |
574 | .expect(200) | |
575 | .expect('Content-Type', /json/) | |
576 | .end(function (err, res) { | |
577 | if (err) throw err | |
578 | ||
579 | expect(res.body.data).to.be.an('array') | |
580 | expect(res.body.data.length).to.equal(3) | |
581 | ||
582 | done() | |
583 | }) | |
584 | }) | |
585 | ||
586 | it('Should fail without a correct uuid', function (done) { | |
587 | request(server.url) | |
588 | .get(path + 'coucou') | |
589 | .set('Accept', 'application/json') | |
590 | .expect(400, done) | |
591 | }) | |
592 | ||
593 | it('Should return 404 with an incorrect video', function (done) { | |
594 | request(server.url) | |
595 | .get(path + '4da6fde3-88f7-4d16-b119-108df5630b06') | |
596 | .set('Accept', 'application/json') | |
597 | .expect(404, done) | |
598 | }) | |
599 | ||
600 | it('Should succeed with the correct parameters') | |
601 | }) | |
602 | ||
d38b8281 C |
603 | describe('When rating a video', function () { |
604 | let videoId | |
605 | ||
606 | before(function (done) { | |
607 | videosUtils.getVideosList(server.url, function (err, res) { | |
608 | if (err) throw err | |
609 | ||
610 | videoId = res.body.data[0].id | |
611 | ||
612 | return done() | |
613 | }) | |
614 | }) | |
615 | ||
616 | it('Should fail without a valid uuid', function (done) { | |
617 | const data = { | |
618 | rating: 'like' | |
619 | } | |
620 | requestsUtils.makePutBodyRequest(server.url, path + 'blabla/rate', server.accessToken, data, done) | |
621 | }) | |
622 | ||
623 | it('Should fail with an unknown id', function (done) { | |
624 | const data = { | |
625 | rating: 'like' | |
626 | } | |
627 | requestsUtils.makePutBodyRequest(server.url, path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate', server.accessToken, data, done, 404) | |
628 | }) | |
629 | ||
630 | it('Should fail with a wrong rating', function (done) { | |
631 | const data = { | |
632 | rating: 'likes' | |
633 | } | |
634 | requestsUtils.makePutBodyRequest(server.url, path + videoId + '/rate', server.accessToken, data, done) | |
635 | }) | |
636 | ||
637 | it('Should succeed with the correct parameters', function (done) { | |
638 | const data = { | |
639 | rating: 'like' | |
640 | } | |
641 | requestsUtils.makePutBodyRequest(server.url, path + videoId + '/rate', server.accessToken, data, done, 204) | |
642 | }) | |
643 | }) | |
644 | ||
efe923bc C |
645 | describe('When removing a video', function () { |
646 | it('Should have 404 with nothing', function (done) { | |
647 | request(server.url) | |
648 | .delete(path) | |
649 | .set('Authorization', 'Bearer ' + server.accessToken) | |
650 | .expect(400, done) | |
651 | }) | |
652 | ||
653 | it('Should fail without a correct uuid', function (done) { | |
654 | request(server.url) | |
655 | .delete(path + 'hello') | |
656 | .set('Authorization', 'Bearer ' + server.accessToken) | |
657 | .expect(400, done) | |
658 | }) | |
659 | ||
660 | it('Should fail with a video which does not exist', function (done) { | |
661 | request(server.url) | |
662 | .delete(path + '4da6fde3-88f7-4d16-b119-108df5630b06') | |
663 | .set('Authorization', 'Bearer ' + server.accessToken) | |
664 | .expect(404, done) | |
665 | }) | |
666 | ||
667 | it('Should fail with a video of another user') | |
668 | ||
669 | it('Should fail with a video of another pod') | |
670 | ||
671 | it('Should succeed with the correct parameters') | |
672 | }) | |
673 | ||
674 | after(function (done) { | |
675 | process.kill(-server.app.pid) | |
676 | ||
677 | // Keep the logs if the test failed | |
678 | if (this.ok) { | |
679 | serversUtils.flushTests(done) | |
680 | } else { | |
681 | done() | |
682 | } | |
683 | }) | |
684 | }) |