]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/videos.ts
d605469174cc0339690bb9814fdd139858281af8
[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({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
352
353 attaches = {
354 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mkv')
355 }
356 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
357 })
358
359 it('Should fail with an incorrect thumbnail file', async function () {
360 const fields = baseCorrectParams
361 const attaches = {
362 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'avatar.png'),
363 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
364 }
365
366 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
367 })
368
369 it('Should fail with a big thumbnail file', async function () {
370 const fields = baseCorrectParams
371 const attaches = {
372 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png'),
373 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
374 }
375
376 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
377 })
378
379 it('Should fail with an incorrect preview file', async function () {
380 const fields = baseCorrectParams
381 const attaches = {
382 previewfile: join(root(), 'server', 'tests', 'fixtures', 'avatar.png'),
383 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
384 }
385
386 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
387 })
388
389 it('Should fail with a big preview file', async function () {
390 const fields = baseCorrectParams
391 const attaches = {
392 previewfile: join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png'),
393 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
394 }
395
396 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
397 })
398
399 it('Should succeed with the correct parameters', async function () {
400 this.timeout(10000)
401
402 const fields = baseCorrectParams
403
404 {
405 const attaches = baseCorrectAttaches
406 await makeUploadRequest({
407 url: server.url,
408 path: path + '/upload',
409 token: server.accessToken,
410 fields,
411 attaches,
412 statusCodeExpected: HttpStatusCode.OK_200
413 })
414 }
415
416 {
417 const attaches = immutableAssign(baseCorrectAttaches, {
418 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
419 })
420
421 await makeUploadRequest({
422 url: server.url,
423 path: path + '/upload',
424 token: server.accessToken,
425 fields,
426 attaches,
427 statusCodeExpected: HttpStatusCode.OK_200
428 })
429 }
430
431 {
432 const attaches = immutableAssign(baseCorrectAttaches, {
433 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.ogv')
434 })
435
436 await makeUploadRequest({
437 url: server.url,
438 path: path + '/upload',
439 token: server.accessToken,
440 fields,
441 attaches,
442 statusCodeExpected: HttpStatusCode.OK_200
443 })
444 }
445 })
446 })
447
448 describe('When updating a video', function () {
449 const baseCorrectParams = {
450 name: 'my super name',
451 category: 5,
452 licence: 2,
453 language: 'pt',
454 nsfw: false,
455 commentsEnabled: false,
456 downloadEnabled: false,
457 description: 'my super description',
458 privacy: VideoPrivacy.PUBLIC,
459 tags: [ 'tag1', 'tag2' ]
460 }
461
462 before(async function () {
463 const res = await getVideosList(server.url)
464 videoId = res.body.data[0].uuid
465 })
466
467 it('Should fail with nothing', async function () {
468 const fields = {}
469 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
470 })
471
472 it('Should fail without a valid uuid', async function () {
473 const fields = baseCorrectParams
474 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
475 })
476
477 it('Should fail with an unknown id', async function () {
478 const fields = baseCorrectParams
479
480 await makePutBodyRequest({
481 url: server.url,
482 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
483 token: server.accessToken,
484 fields,
485 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
486 })
487 })
488
489 it('Should fail with a long name', async function () {
490 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
491
492 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
493 })
494
495 it('Should fail with a bad category', async function () {
496 const fields = immutableAssign(baseCorrectParams, { category: 125 })
497
498 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
499 })
500
501 it('Should fail with a bad licence', async function () {
502 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
503
504 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
505 })
506
507 it('Should fail with a bad language', async function () {
508 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
509
510 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
511 })
512
513 it('Should fail with a long description', async function () {
514 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
515
516 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
517 })
518
519 it('Should fail with a long support text', async function () {
520 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
521
522 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
523 })
524
525 it('Should fail with a bad channel', async function () {
526 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
527
528 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
529 })
530
531 it('Should fail with too many tags', async function () {
532 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
533
534 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
535 })
536
537 it('Should fail with a tag length too low', async function () {
538 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
539
540 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
541 })
542
543 it('Should fail with a tag length too big', async function () {
544 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
545
546 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
547 })
548
549 it('Should fail with a bad schedule update (miss updateAt)', async function () {
550 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } })
551
552 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
553 })
554
555 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
556 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { updateAt: 'toto', privacy: VideoPrivacy.PUBLIC } })
557
558 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
559 })
560
561 it('Should fail with a bad originally published at param', async function () {
562 const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' })
563
564 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
565 })
566
567 it('Should fail with an incorrect thumbnail file', async function () {
568 const fields = baseCorrectParams
569 const attaches = {
570 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'avatar.png')
571 }
572
573 await makeUploadRequest({
574 url: server.url,
575 method: 'PUT',
576 path: path + videoId,
577 token: server.accessToken,
578 fields,
579 attaches
580 })
581 })
582
583 it('Should fail with a big thumbnail file', async function () {
584 const fields = baseCorrectParams
585 const attaches = {
586 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png')
587 }
588
589 await makeUploadRequest({
590 url: server.url,
591 method: 'PUT',
592 path: path + videoId,
593 token: server.accessToken,
594 fields,
595 attaches
596 })
597 })
598
599 it('Should fail with an incorrect preview file', async function () {
600 const fields = baseCorrectParams
601 const attaches = {
602 previewfile: join(root(), 'server', 'tests', 'fixtures', 'avatar.png')
603 }
604
605 await makeUploadRequest({
606 url: server.url,
607 method: 'PUT',
608 path: path + videoId,
609 token: server.accessToken,
610 fields,
611 attaches
612 })
613 })
614
615 it('Should fail with a big preview file', async function () {
616 const fields = baseCorrectParams
617 const attaches = {
618 previewfile: join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png')
619 }
620
621 await makeUploadRequest({
622 url: server.url,
623 method: 'PUT',
624 path: path + videoId,
625 token: server.accessToken,
626 fields,
627 attaches
628 })
629 })
630
631 it('Should fail with a video of another user without the appropriate right', async function () {
632 const fields = baseCorrectParams
633
634 await makePutBodyRequest({
635 url: server.url,
636 path: path + videoId,
637 token: userAccessToken,
638 fields,
639 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
640 })
641 })
642
643 it('Should fail with a video of another server')
644
645 it('Should succeed with the correct parameters', async function () {
646 const fields = baseCorrectParams
647
648 await makePutBodyRequest({
649 url: server.url,
650 path: path + videoId,
651 token: server.accessToken,
652 fields,
653 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
654 })
655 })
656 })
657
658 describe('When getting a video', function () {
659 it('Should return the list of the videos with nothing', async function () {
660 const res = await makeGetRequest({
661 url: server.url,
662 path,
663 statusCodeExpected: HttpStatusCode.OK_200
664 })
665
666 expect(res.body.data).to.be.an('array')
667 expect(res.body.data.length).to.equal(3)
668 })
669
670 it('Should fail without a correct uuid', async function () {
671 await getVideo(server.url, 'coucou', HttpStatusCode.BAD_REQUEST_400)
672 })
673
674 it('Should return 404 with an incorrect video', async function () {
675 await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404)
676 })
677
678 it('Should succeed with the correct parameters', async function () {
679 await getVideo(server.url, videoId)
680 })
681 })
682
683 describe('When rating a video', function () {
684 let videoId
685
686 before(async function () {
687 const res = await getVideosList(server.url)
688 videoId = res.body.data[0].id
689 })
690
691 it('Should fail without a valid uuid', async function () {
692 const fields = {
693 rating: 'like'
694 }
695 await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields })
696 })
697
698 it('Should fail with an unknown id', async function () {
699 const fields = {
700 rating: 'like'
701 }
702 await makePutBodyRequest({
703 url: server.url,
704 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
705 token: server.accessToken,
706 fields,
707 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
708 })
709 })
710
711 it('Should fail with a wrong rating', async function () {
712 const fields = {
713 rating: 'likes'
714 }
715 await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields })
716 })
717
718 it('Should succeed with the correct parameters', async function () {
719 const fields = {
720 rating: 'like'
721 }
722 await makePutBodyRequest({
723 url: server.url,
724 path: path + videoId + '/rate',
725 token: server.accessToken,
726 fields,
727 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
728 })
729 })
730 })
731
732 describe('When removing a video', function () {
733 it('Should have 404 with nothing', async function () {
734 await makeDeleteRequest({
735 url: server.url,
736 path,
737 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
738 })
739 })
740
741 it('Should fail without a correct uuid', async function () {
742 await removeVideo(server.url, server.accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400)
743 })
744
745 it('Should fail with a video which does not exist', async function () {
746 await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404)
747 })
748
749 it('Should fail with a video of another user without the appropriate right', async function () {
750 await removeVideo(server.url, userAccessToken, videoId, HttpStatusCode.FORBIDDEN_403)
751 })
752
753 it('Should fail with a video of another server')
754
755 it('Should succeed with the correct parameters', async function () {
756 await removeVideo(server.url, server.accessToken, videoId)
757 })
758 })
759
760 after(async function () {
761 await cleanupTests([ server ])
762 })
763 })