]>
Commit | Line | Data |
---|---|---|
1 | /* tslint:disable:no-unused-expression */ | |
2 | ||
3 | import * as request from 'supertest' | |
4 | import { join } from 'path' | |
5 | import 'mocha' | |
6 | import * as chai from 'chai' | |
7 | const expect = chai.expect | |
8 | ||
9 | import { | |
10 | ServerInfo, | |
11 | flushTests, | |
12 | runServer, | |
13 | getVideosList, | |
14 | makePutBodyRequest, | |
15 | setAccessTokensToServers, | |
16 | killallServers, | |
17 | makePostUploadRequest, | |
18 | getMyUserInformation, | |
19 | createUser, | |
20 | getUserAccessToken | |
21 | } from '../../utils' | |
22 | ||
23 | describe('Test videos API validator', function () { | |
24 | const path = '/api/v1/videos/' | |
25 | let server: ServerInfo | |
26 | let channelId: number | |
27 | ||
28 | // --------------------------------------------------------------- | |
29 | ||
30 | before(async function () { | |
31 | this.timeout(20000) | |
32 | ||
33 | await flushTests() | |
34 | ||
35 | server = await runServer(1) | |
36 | ||
37 | await setAccessTokensToServers([ server ]) | |
38 | ||
39 | const res = await getMyUserInformation(server.url, server.accessToken) | |
40 | channelId = res.body.videoChannels[0].id | |
41 | }) | |
42 | ||
43 | describe('When listing a video', function () { | |
44 | it('Should fail with a bad start pagination', async function () { | |
45 | await request(server.url) | |
46 | .get(path) | |
47 | .query({ start: 'hello' }) | |
48 | .set('Accept', 'application/json') | |
49 | .expect(400) | |
50 | }) | |
51 | ||
52 | it('Should fail with a bad count pagination', async function () { | |
53 | await request(server.url) | |
54 | .get(path) | |
55 | .query({ count: 'hello' }) | |
56 | .set('Accept', 'application/json') | |
57 | .expect(400) | |
58 | }) | |
59 | ||
60 | it('Should fail with an incorrect sort', async function () { | |
61 | await request(server.url) | |
62 | .get(path) | |
63 | .query({ sort: 'hello' }) | |
64 | .set('Accept', 'application/json') | |
65 | .expect(400) | |
66 | }) | |
67 | }) | |
68 | ||
69 | describe('When searching a video', function () { | |
70 | it('Should fail with nothing', async function () { | |
71 | await request(server.url) | |
72 | .get(join(path, 'search')) | |
73 | .set('Accept', 'application/json') | |
74 | .expect(400) | |
75 | }) | |
76 | ||
77 | it('Should fail with a bad start pagination', async function () { | |
78 | await request(server.url) | |
79 | .get(join(path, 'search', 'test')) | |
80 | .query({ start: 'hello' }) | |
81 | .set('Accept', 'application/json') | |
82 | .expect(400) | |
83 | }) | |
84 | ||
85 | it('Should fail with a bad count pagination', async function () { | |
86 | await request(server.url) | |
87 | .get(join(path, 'search', 'test')) | |
88 | .query({ count: 'hello' }) | |
89 | .set('Accept', 'application/json') | |
90 | .expect(400) | |
91 | }) | |
92 | ||
93 | it('Should fail with an incorrect sort', async function () { | |
94 | await request(server.url) | |
95 | .get(join(path, 'search', 'test')) | |
96 | .query({ sort: 'hello' }) | |
97 | .set('Accept', 'application/json') | |
98 | .expect(400) | |
99 | }) | |
100 | }) | |
101 | ||
102 | describe('When adding a video', function () { | |
103 | it('Should fail with nothing', async function () { | |
104 | const fields = {} | |
105 | const attaches = {} | |
106 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | |
107 | }) | |
108 | ||
109 | it('Should fail without name', async function () { | |
110 | const fields = { | |
111 | category: 5, | |
112 | licence: 1, | |
113 | language: 6, | |
114 | nsfw: false, | |
115 | description: 'my super description', | |
116 | tags: [ 'tag1', 'tag2' ], | |
117 | channelId | |
118 | } | |
119 | const attaches = { | |
120 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | |
121 | } | |
122 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | |
123 | }) | |
124 | ||
125 | it('Should fail with a long name', async function () { | |
126 | const fields = { | |
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 | licence: 1, | |
130 | language: 6, | |
131 | nsfw: false, | |
132 | description: 'my super description', | |
133 | tags: [ 'tag1', 'tag2' ], | |
134 | channelId | |
135 | } | |
136 | const attaches = { | |
137 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | |
138 | } | |
139 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | |
140 | }) | |
141 | ||
142 | it('Should fail without a category', async function () { | |
143 | const fields = { | |
144 | name: 'my super name', | |
145 | licence: 1, | |
146 | language: 6, | |
147 | nsfw: false, | |
148 | description: 'my super description', | |
149 | tags: [ 'tag1', 'tag2' ], | |
150 | channelId | |
151 | } | |
152 | const attaches = { | |
153 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | |
154 | } | |
155 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | |
156 | }) | |
157 | ||
158 | it('Should fail with a bad category', async function () { | |
159 | const fields = { | |
160 | name: 'my super name', | |
161 | category: 125, | |
162 | licence: 1, | |
163 | language: 6, | |
164 | nsfw: false, | |
165 | description: 'my super description', | |
166 | tags: [ 'tag1', 'tag2' ], | |
167 | channelId | |
168 | } | |
169 | const attaches = { | |
170 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | |
171 | } | |
172 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | |
173 | }) | |
174 | ||
175 | it('Should fail without a licence', async function () { | |
176 | const fields = { | |
177 | name: 'my super name', | |
178 | category: 5, | |
179 | language: 6, | |
180 | nsfw: false, | |
181 | description: 'my super description', | |
182 | tags: [ 'tag1', 'tag2' ], | |
183 | channelId | |
184 | } | |
185 | const attaches = { | |
186 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | |
187 | } | |
188 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | |
189 | }) | |
190 | ||
191 | it('Should fail with a bad licence', async function () { | |
192 | const fields = { | |
193 | name: 'my super name', | |
194 | category: 5, | |
195 | licence: 125, | |
196 | language: 6, | |
197 | nsfw: false, | |
198 | description: 'my super description', | |
199 | tags: [ 'tag1', 'tag2' ], | |
200 | channelId | |
201 | } | |
202 | const attaches = { | |
203 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | |
204 | } | |
205 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | |
206 | }) | |
207 | ||
208 | it('Should fail with a bad language', async function () { | |
209 | const fields = { | |
210 | name: 'my super name', | |
211 | category: 5, | |
212 | licence: 4, | |
213 | language: 563, | |
214 | nsfw: false, | |
215 | description: 'my super description', | |
216 | tags: [ 'tag1', 'tag2' ], | |
217 | channelId | |
218 | } | |
219 | const attaches = { | |
220 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | |
221 | } | |
222 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | |
223 | }) | |
224 | ||
225 | it('Should fail without nsfw attribute', async function () { | |
226 | const fields = { | |
227 | name: 'my super name', | |
228 | category: 5, | |
229 | licence: 4, | |
230 | language: 6, | |
231 | description: 'my super description', | |
232 | tags: [ 'tag1', 'tag2' ], | |
233 | channelId | |
234 | } | |
235 | const attaches = { | |
236 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | |
237 | } | |
238 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | |
239 | }) | |
240 | ||
241 | it('Should fail with a bad nsfw attribute', async function () { | |
242 | const fields = { | |
243 | name: 'my super name', | |
244 | category: 5, | |
245 | licence: 4, | |
246 | language: 6, | |
247 | nsfw: 2, | |
248 | description: 'my super description', | |
249 | tags: [ 'tag1', 'tag2' ], | |
250 | channelId | |
251 | } | |
252 | const attaches = { | |
253 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | |
254 | } | |
255 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | |
256 | }) | |
257 | ||
258 | it('Should fail without description', async function () { | |
259 | const fields = { | |
260 | name: 'my super name', | |
261 | category: 5, | |
262 | licence: 1, | |
263 | language: 6, | |
264 | nsfw: false, | |
265 | tags: [ 'tag1', 'tag2' ], | |
266 | channelId | |
267 | } | |
268 | const attaches = { | |
269 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | |
270 | } | |
271 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | |
272 | }) | |
273 | ||
274 | it('Should fail with a long description', async function () { | |
275 | const fields = { | |
276 | name: 'my super name', | |
277 | category: 5, | |
278 | licence: 1, | |
279 | language: 6, | |
280 | nsfw: false, | |
281 | description: 'my super description which is very very very very very very very very very very very very very very' + | |
282 | 'very very very very very very very very very very very very very very very very very very very very very' + | |
283 | 'very very very very very very very very very very very very very very very long', | |
284 | tags: [ 'tag1', 'tag2' ], | |
285 | channelId | |
286 | } | |
287 | const attaches = { | |
288 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | |
289 | } | |
290 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | |
291 | }) | |
292 | ||
293 | it('Should fail without a channel', async function () { | |
294 | const fields = { | |
295 | name: 'my super name', | |
296 | category: 5, | |
297 | licence: 1, | |
298 | language: 6, | |
299 | nsfw: false, | |
300 | description: 'my super description', | |
301 | tags: [ 'tag1', 'tag2' ] | |
302 | } | |
303 | const attaches = { | |
304 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | |
305 | } | |
306 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | |
307 | }) | |
308 | ||
309 | it('Should fail with a bad channel', async function () { | |
310 | const fields = { | |
311 | name: 'my super name', | |
312 | category: 5, | |
313 | licence: 1, | |
314 | language: 6, | |
315 | nsfw: false, | |
316 | description: 'my super description', | |
317 | tags: [ 'tag1', 'tag2' ], | |
318 | channelId: 545454 | |
319 | } | |
320 | const attaches = { | |
321 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | |
322 | } | |
323 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | |
324 | }) | |
325 | ||
326 | it('Should fail with another user channel', async function () { | |
327 | const user = { | |
328 | username: 'fake', | |
329 | password: 'fake_password' | |
330 | } | |
331 | await createUser(server.url, server.accessToken, user.username, user.password) | |
332 | ||
333 | const accessTokenUser = await getUserAccessToken(server, user) | |
334 | const res = await getMyUserInformation(server.url, accessTokenUser) | |
335 | const channelId = res.body.videoChannels[0].id | |
336 | ||
337 | const fields = { | |
338 | name: 'my super name', | |
339 | category: 5, | |
340 | licence: 1, | |
341 | language: 6, | |
342 | nsfw: false, | |
343 | description: 'my super description', | |
344 | tags: [ 'tag1', 'tag2' ], | |
345 | channelId | |
346 | } | |
347 | const attaches = { | |
348 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | |
349 | } | |
350 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | |
351 | }) | |
352 | ||
353 | it('Should fail with too many tags', async function () { | |
354 | const fields = { | |
355 | name: 'my super name', | |
356 | category: 5, | |
357 | licence: 1, | |
358 | language: 6, | |
359 | nsfw: false, | |
360 | description: 'my super description', | |
361 | tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ], | |
362 | channelId | |
363 | } | |
364 | const attaches = { | |
365 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | |
366 | } | |
367 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | |
368 | }) | |
369 | ||
370 | it('Should fail with a tag length too low', async function () { | |
371 | const fields = { | |
372 | name: 'my super name', | |
373 | category: 5, | |
374 | licence: 1, | |
375 | language: 6, | |
376 | nsfw: false, | |
377 | description: 'my super description', | |
378 | tags: [ 'tag1', 't' ], | |
379 | channelId | |
380 | } | |
381 | const attaches = { | |
382 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | |
383 | } | |
384 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | |
385 | }) | |
386 | ||
387 | it('Should fail with a tag length too big', async function () { | |
388 | const fields = { | |
389 | name: 'my super name', | |
390 | category: 5, | |
391 | licence: 1, | |
392 | language: 6, | |
393 | nsfw: false, | |
394 | description: 'my super description', | |
395 | tags: [ 'my_super_tag_too_long', 'tag1' ], | |
396 | channelId | |
397 | } | |
398 | const attaches = { | |
399 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | |
400 | } | |
401 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | |
402 | }) | |
403 | ||
404 | it('Should fail without an input file', async function () { | |
405 | const fields = { | |
406 | name: 'my super name', | |
407 | category: 5, | |
408 | licence: 1, | |
409 | language: 6, | |
410 | nsfw: false, | |
411 | description: 'my super description', | |
412 | tags: [ 'tag1', 'tag2' ], | |
413 | channelId | |
414 | } | |
415 | const attaches = {} | |
416 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | |
417 | }) | |
418 | ||
419 | it('Should fail without an incorrect input file', async function () { | |
420 | const fields = { | |
421 | name: 'my super name', | |
422 | category: 5, | |
423 | licence: 1, | |
424 | language: 6, | |
425 | nsfw: false, | |
426 | description: 'my super description', | |
427 | tags: [ 'tag1', 'tag2' ], | |
428 | channelId | |
429 | } | |
430 | const attaches = { | |
431 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm') | |
432 | } | |
433 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | |
434 | }) | |
435 | ||
436 | it('Should fail with a too big duration', async function () { | |
437 | const fields = { | |
438 | name: 'my super name', | |
439 | category: 5, | |
440 | licence: 1, | |
441 | language: 6, | |
442 | nsfw: false, | |
443 | description: 'my super description', | |
444 | tags: [ 'tag1', 'tag2' ], | |
445 | channelId | |
446 | } | |
447 | const attaches = { | |
448 | 'videofile': join(__dirname, '..', 'fixtures', 'video_too_long.webm') | |
449 | } | |
450 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | |
451 | }) | |
452 | ||
453 | it('Should succeed with the correct parameters', async function () { | |
454 | this.timeout(10000) | |
455 | ||
456 | const fields = { | |
457 | name: 'my super name', | |
458 | category: 5, | |
459 | licence: 1, | |
460 | language: 6, | |
461 | nsfw: false, | |
462 | description: 'my super description', | |
463 | tags: [ 'tag1', 'tag2' ], | |
464 | channelId | |
465 | } | |
466 | const attaches = { | |
467 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | |
468 | } | |
469 | ||
470 | await makePostUploadRequest({ | |
471 | url: server.url, | |
472 | path: path + '/upload', | |
473 | token: server.accessToken, | |
474 | fields, | |
475 | attaches, | |
476 | statusCodeExpected: 204 | |
477 | }) | |
478 | ||
479 | attaches.videofile = join(__dirname, '..', 'fixtures', 'video_short.mp4') | |
480 | await makePostUploadRequest({ | |
481 | url: server.url, | |
482 | path: path + '/upload', | |
483 | token: server.accessToken, | |
484 | fields, | |
485 | attaches, | |
486 | statusCodeExpected: 204 | |
487 | }) | |
488 | ||
489 | attaches.videofile = join(__dirname, '..', 'fixtures', 'video_short.ogv') | |
490 | await makePostUploadRequest({ | |
491 | url: server.url, | |
492 | path: path + '/upload', | |
493 | token: server.accessToken, | |
494 | fields, | |
495 | attaches, | |
496 | statusCodeExpected: 204 | |
497 | }) | |
498 | }) | |
499 | }) | |
500 | ||
501 | describe('When updating a video', function () { | |
502 | let videoId | |
503 | ||
504 | before(async function () { | |
505 | const res = await getVideosList(server.url) | |
506 | videoId = res.body.data[0].id | |
507 | }) | |
508 | ||
509 | it('Should fail with nothing', async function () { | |
510 | const fields = {} | |
511 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
512 | }) | |
513 | ||
514 | it('Should fail without a valid uuid', async function () { | |
515 | const fields = { | |
516 | category: 5, | |
517 | licence: 2, | |
518 | language: 6, | |
519 | nsfw: false, | |
520 | description: 'my super description', | |
521 | tags: [ 'tag1', 'tag2' ] | |
522 | } | |
523 | await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields }) | |
524 | }) | |
525 | ||
526 | it('Should fail with an unknown id', async function () { | |
527 | const fields = { | |
528 | category: 5, | |
529 | licence: 2, | |
530 | language: 6, | |
531 | nsfw: false, | |
532 | description: 'my super description', | |
533 | tags: [ 'tag1', 'tag2' ] | |
534 | } | |
535 | await makePutBodyRequest({ | |
536 | url: server.url, | |
537 | path: path + '4da6fde3-88f7-4d16-b119-108df5630b06', | |
538 | token: server.accessToken, | |
539 | fields, | |
540 | statusCodeExpected: 404 | |
541 | }) | |
542 | }) | |
543 | ||
544 | it('Should fail with a long name', async function () { | |
545 | const fields = { | |
546 | name: 'My very very very very very very very very very very very very very very very very long name', | |
547 | category: 5, | |
548 | licence: 2, | |
549 | language: 6, | |
550 | nsfw: false, | |
551 | description: 'my super description', | |
552 | tags: [ 'tag1', 'tag2' ] | |
553 | } | |
554 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | |
555 | }) | |
556 | ||
557 | it('Should fail with a bad category', async function () { | |
558 | const fields = { | |
559 | name: 'my super name', | |
560 | category: 128, | |
561 | licence: 2, | |
562 | language: 6, | |
563 | nsfw: false, | |
564 | description: 'my super description', | |
565 | tags: [ 'tag1', 'tag2' ] | |
566 | } | |
567 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | |
568 | }) | |
569 | ||
570 | it('Should fail with a bad licence', async function () { | |
571 | const fields = { | |
572 | name: 'my super name', | |
573 | category: 5, | |
574 | licence: 128, | |
575 | language: 6, | |
576 | nsfw: false, | |
577 | description: 'my super description', | |
578 | tags: [ 'tag1', 'tag2' ] | |
579 | } | |
580 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | |
581 | }) | |
582 | ||
583 | it('Should fail with a bad language', async function () { | |
584 | const fields = { | |
585 | name: 'my super name', | |
586 | category: 5, | |
587 | licence: 3, | |
588 | language: 896, | |
589 | nsfw: false, | |
590 | description: 'my super description', | |
591 | tags: [ 'tag1', 'tag2' ] | |
592 | } | |
593 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | |
594 | }) | |
595 | ||
596 | it('Should fail with a bad nsfw attribute', async function () { | |
597 | const fields = { | |
598 | name: 'my super name', | |
599 | category: 5, | |
600 | licence: 5, | |
601 | language: 6, | |
602 | nsfw: -4, | |
603 | description: 'my super description', | |
604 | tags: [ 'tag1', 'tag2' ] | |
605 | } | |
606 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | |
607 | }) | |
608 | ||
609 | it('Should fail with a long description', async function () { | |
610 | const fields = { | |
611 | name: 'my super name', | |
612 | category: 5, | |
613 | licence: 2, | |
614 | language: 6, | |
615 | nsfw: false, | |
616 | description: 'my super description which is very very very very very very very very very very very very very very' + | |
617 | 'very very very very very very very very very very very very very very very very very very very very very' + | |
618 | 'very very very very very very very very very very very very very very very long', | |
619 | tags: [ 'tag1', 'tag2' ] | |
620 | } | |
621 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | |
622 | }) | |
623 | ||
624 | it('Should fail with too many tags', async function () { | |
625 | const fields = { | |
626 | name: 'my super name', | |
627 | category: 5, | |
628 | licence: 2, | |
629 | language: 6, | |
630 | nsfw: false, | |
631 | description: 'my super description', | |
632 | tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] | |
633 | } | |
634 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | |
635 | }) | |
636 | ||
637 | it('Should fail with a tag length too low', async function () { | |
638 | const fields = { | |
639 | name: 'my super name', | |
640 | category: 5, | |
641 | licence: 2, | |
642 | language: 6, | |
643 | nsfw: false, | |
644 | description: 'my super description', | |
645 | tags: [ 'tag1', 't' ] | |
646 | } | |
647 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | |
648 | }) | |
649 | ||
650 | it('Should fail with a tag length too big', async function () { | |
651 | const fields = { | |
652 | name: 'my super name', | |
653 | category: 5, | |
654 | licence: 2, | |
655 | language: 6, | |
656 | nsfw: false, | |
657 | description: 'my super description', | |
658 | tags: [ 'my_super_tag_too_long', 'tag1' ] | |
659 | } | |
660 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | |
661 | }) | |
662 | ||
663 | it('Should fail with a video of another user') | |
664 | ||
665 | it('Should fail with a video of another pod') | |
666 | }) | |
667 | ||
668 | describe('When getting a video', function () { | |
669 | it('Should return the list of the videos with nothing', async function () { | |
670 | const res = await request(server.url) | |
671 | .get(path) | |
672 | .set('Accept', 'application/json') | |
673 | .expect(200) | |
674 | .expect('Content-Type', /json/) | |
675 | ||
676 | expect(res.body.data).to.be.an('array') | |
677 | expect(res.body.data.length).to.equal(3) | |
678 | }) | |
679 | ||
680 | it('Should fail without a correct uuid', async function () { | |
681 | await request(server.url) | |
682 | .get(path + 'coucou') | |
683 | .set('Accept', 'application/json') | |
684 | .expect(400) | |
685 | }) | |
686 | ||
687 | it('Should return 404 with an incorrect video', async function () { | |
688 | await request(server.url) | |
689 | .get(path + '4da6fde3-88f7-4d16-b119-108df5630b06') | |
690 | .set('Accept', 'application/json') | |
691 | .expect(404) | |
692 | }) | |
693 | ||
694 | it('Should succeed with the correct parameters') | |
695 | }) | |
696 | ||
697 | describe('When rating a video', function () { | |
698 | let videoId | |
699 | ||
700 | before(async function () { | |
701 | const res = await getVideosList(server.url) | |
702 | videoId = res.body.data[0].id | |
703 | }) | |
704 | ||
705 | it('Should fail without a valid uuid', async function () { | |
706 | const fields = { | |
707 | rating: 'like' | |
708 | } | |
709 | await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields }) | |
710 | }) | |
711 | ||
712 | it('Should fail with an unknown id', async function () { | |
713 | const fields = { | |
714 | rating: 'like' | |
715 | } | |
716 | await makePutBodyRequest({ | |
717 | url: server.url, | |
718 | path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate', | |
719 | token: server.accessToken, | |
720 | fields, | |
721 | statusCodeExpected: 404 | |
722 | }) | |
723 | }) | |
724 | ||
725 | it('Should fail with a wrong rating', async function () { | |
726 | const fields = { | |
727 | rating: 'likes' | |
728 | } | |
729 | await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields }) | |
730 | }) | |
731 | ||
732 | it('Should succeed with the correct parameters', async function () { | |
733 | const fields = { | |
734 | rating: 'like' | |
735 | } | |
736 | await makePutBodyRequest({ | |
737 | url: server.url, | |
738 | path: path + videoId + '/rate', | |
739 | token: server.accessToken, | |
740 | fields, | |
741 | statusCodeExpected: 204 | |
742 | }) | |
743 | }) | |
744 | }) | |
745 | ||
746 | describe('When removing a video', function () { | |
747 | it('Should have 404 with nothing', async function () { | |
748 | await request(server.url) | |
749 | .delete(path) | |
750 | .set('Authorization', 'Bearer ' + server.accessToken) | |
751 | .expect(400) | |
752 | }) | |
753 | ||
754 | it('Should fail without a correct uuid', async function () { | |
755 | await request(server.url) | |
756 | .delete(path + 'hello') | |
757 | .set('Authorization', 'Bearer ' + server.accessToken) | |
758 | .expect(400) | |
759 | }) | |
760 | ||
761 | it('Should fail with a video which does not exist', async function () { | |
762 | await request(server.url) | |
763 | .delete(path + '4da6fde3-88f7-4d16-b119-108df5630b06') | |
764 | .set('Authorization', 'Bearer ' + server.accessToken) | |
765 | .expect(404) | |
766 | }) | |
767 | ||
768 | it('Should fail with a video of another user') | |
769 | ||
770 | it('Should fail with a video of another pod') | |
771 | ||
772 | it('Should succeed with the correct parameters') | |
773 | }) | |
774 | ||
775 | after(async function () { | |
776 | killallServers([ server ]) | |
777 | ||
778 | // Keep the logs if the test failed | |
779 | if (this['ok']) { | |
780 | await flushTests() | |
781 | } | |
782 | }) | |
783 | }) |