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