1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { omit } from 'lodash'
6 import { join } from 'path'
7 import { randomInt } from '@shared/core-utils'
8 import { PeerTubeProblemDocument, VideoCreateResult } from '@shared/models'
9 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
11 checkUploadVideoParam,
26 setAccessTokensToServers,
28 } from '../../../../shared/extra-utils'
30 checkBadCountPagination,
31 checkBadSortPagination,
32 checkBadStartPagination
33 } from '../../../../shared/extra-utils/requests/check-api-params'
34 import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
36 const expect = chai.expect
38 describe('Test videos API validator', function () {
39 const path = '/api/v1/videos/'
40 let server: ServerInfo
41 let userAccessToken = ''
42 let accountName: string
44 let channelName: string
45 let video: VideoCreateResult
47 // ---------------------------------------------------------------
49 before(async function () {
52 server = await flushAndRunServer(1)
54 await setAccessTokensToServers([ server ])
56 const username = 'user1'
57 const password = 'my super password'
58 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
59 userAccessToken = await userLogin(server, { username, password })
62 const res = await getMyUserInformation(server.url, server.accessToken)
63 channelId = res.body.videoChannels[0].id
64 channelName = res.body.videoChannels[0].name
65 accountName = res.body.account.name + '@' + res.body.account.host
69 describe('When listing videos', function () {
70 it('Should fail with a bad start pagination', async function () {
71 await checkBadStartPagination(server.url, path)
74 it('Should fail with a bad count pagination', async function () {
75 await checkBadCountPagination(server.url, path)
78 it('Should fail with an incorrect sort', async function () {
79 await checkBadSortPagination(server.url, path)
82 it('Should fail with a bad skipVideos query', async function () {
83 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200, query: { skipCount: 'toto' } })
86 it('Should success with the correct parameters', async function () {
87 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200, query: { skipCount: false } })
91 describe('When searching a video', function () {
93 it('Should fail with nothing', async function () {
94 await makeGetRequest({
96 path: join(path, 'search'),
97 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
101 it('Should fail with a bad start pagination', async function () {
102 await checkBadStartPagination(server.url, join(path, 'search', 'test'))
105 it('Should fail with a bad count pagination', async function () {
106 await checkBadCountPagination(server.url, join(path, 'search', 'test'))
109 it('Should fail with an incorrect sort', async function () {
110 await checkBadSortPagination(server.url, join(path, 'search', 'test'))
113 it('Should success with the correct parameters', async function () {
114 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 })
118 describe('When listing my videos', function () {
119 const path = '/api/v1/users/me/videos'
121 it('Should fail with a bad start pagination', async function () {
122 await checkBadStartPagination(server.url, path, server.accessToken)
125 it('Should fail with a bad count pagination', async function () {
126 await checkBadCountPagination(server.url, path, server.accessToken)
129 it('Should fail with an incorrect sort', async function () {
130 await checkBadSortPagination(server.url, path, server.accessToken)
133 it('Should success with the correct parameters', async function () {
134 await makeGetRequest({ url: server.url, token: server.accessToken, path, statusCodeExpected: HttpStatusCode.OK_200 })
138 describe('When listing account videos', function () {
141 before(async function () {
142 path = '/api/v1/accounts/' + accountName + '/videos'
145 it('Should fail with a bad start pagination', async function () {
146 await checkBadStartPagination(server.url, path, server.accessToken)
149 it('Should fail with a bad count pagination', async function () {
150 await checkBadCountPagination(server.url, path, server.accessToken)
153 it('Should fail with an incorrect sort', async function () {
154 await checkBadSortPagination(server.url, path, server.accessToken)
157 it('Should success with the correct parameters', async function () {
158 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 })
162 describe('When listing video channel videos', function () {
165 before(async function () {
166 path = '/api/v1/video-channels/' + channelName + '/videos'
169 it('Should fail with a bad start pagination', async function () {
170 await checkBadStartPagination(server.url, path, server.accessToken)
173 it('Should fail with a bad count pagination', async function () {
174 await checkBadCountPagination(server.url, path, server.accessToken)
177 it('Should fail with an incorrect sort', async function () {
178 await checkBadSortPagination(server.url, path, server.accessToken)
181 it('Should success with the correct parameters', async function () {
182 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 })
186 describe('When adding a video', function () {
187 let baseCorrectParams
188 const baseCorrectAttaches = {
189 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.webm')
193 // Put in before to have channelId
194 baseCorrectParams = {
195 name: 'my super name',
200 commentsEnabled: true,
201 downloadEnabled: true,
202 waitTranscoding: true,
203 description: 'my super description',
204 support: 'my super support text',
205 tags: [ 'tag1', 'tag2' ],
206 privacy: VideoPrivacy.PUBLIC,
207 channelId: channelId,
208 originallyPublishedAt: new Date().toISOString()
212 function runSuite (mode: 'legacy' | 'resumable') {
214 it('Should fail with nothing', async function () {
217 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
220 it('Should fail without name', async function () {
221 const fields = omit(baseCorrectParams, 'name')
222 const attaches = baseCorrectAttaches
224 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
227 it('Should fail with a long name', async function () {
228 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
229 const attaches = baseCorrectAttaches
231 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
234 it('Should fail with a bad category', async function () {
235 const fields = immutableAssign(baseCorrectParams, { category: 125 })
236 const attaches = baseCorrectAttaches
238 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
241 it('Should fail with a bad licence', async function () {
242 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
243 const attaches = baseCorrectAttaches
245 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
248 it('Should fail with a bad language', async function () {
249 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
250 const attaches = baseCorrectAttaches
252 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
255 it('Should fail with a long description', async function () {
256 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
257 const attaches = baseCorrectAttaches
259 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
262 it('Should fail with a long support text', async function () {
263 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
264 const attaches = baseCorrectAttaches
266 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
269 it('Should fail without a channel', async function () {
270 const fields = omit(baseCorrectParams, 'channelId')
271 const attaches = baseCorrectAttaches
273 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
276 it('Should fail with a bad channel', async function () {
277 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
278 const attaches = baseCorrectAttaches
280 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
283 it('Should fail with another user channel', async function () {
285 username: 'fake' + randomInt(0, 1500),
286 password: 'fake_password'
288 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
290 const accessTokenUser = await userLogin(server, user)
291 const res = await getMyUserInformation(server.url, accessTokenUser)
292 const customChannelId = res.body.videoChannels[0].id
294 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
295 const attaches = baseCorrectAttaches
297 await checkUploadVideoParam(server.url, userAccessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
300 it('Should fail with too many tags', async function () {
301 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
302 const attaches = baseCorrectAttaches
304 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
307 it('Should fail with a tag length too low', async function () {
308 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
309 const attaches = baseCorrectAttaches
311 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
314 it('Should fail with a tag length too big', async function () {
315 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
316 const attaches = baseCorrectAttaches
318 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
321 it('Should fail with a bad schedule update (miss updateAt)', async function () {
322 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } })
323 const attaches = baseCorrectAttaches
325 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
328 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
329 const fields = immutableAssign(baseCorrectParams, {
331 privacy: VideoPrivacy.PUBLIC,
335 const attaches = baseCorrectAttaches
337 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
340 it('Should fail with a bad originally published at attribute', async function () {
341 const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' })
342 const attaches = baseCorrectAttaches
344 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
347 it('Should fail without an input file', async function () {
348 const fields = baseCorrectParams
350 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
353 it('Should fail with an incorrect input file', async function () {
354 const fields = baseCorrectParams
355 let attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short_fake.webm') }
357 await checkUploadVideoParam(
360 { ...fields, ...attaches },
361 HttpStatusCode.UNPROCESSABLE_ENTITY_422,
365 attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mkv') }
366 await checkUploadVideoParam(
369 { ...fields, ...attaches },
370 HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415,
375 it('Should fail with an incorrect thumbnail file', async function () {
376 const fields = baseCorrectParams
378 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4'),
379 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
382 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
385 it('Should fail with a big thumbnail file', async function () {
386 const fields = baseCorrectParams
388 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png'),
389 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
392 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
395 it('Should fail with an incorrect preview file', async function () {
396 const fields = baseCorrectParams
398 previewfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4'),
399 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
402 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
405 it('Should fail with a big preview file', async function () {
406 const fields = baseCorrectParams
408 previewfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png'),
409 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
412 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
415 it('Should report the appropriate error', async function () {
416 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
417 const attaches = baseCorrectAttaches
419 const attributes = { ...fields, ...attaches }
420 const res = await checkUploadVideoParam(server.url, server.accessToken, attributes, HttpStatusCode.BAD_REQUEST_400, mode)
422 const error = res.body as PeerTubeProblemDocument
424 if (mode === 'legacy') {
425 expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/uploadLegacy')
427 expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/uploadResumableInit')
430 expect(error.type).to.equal('about:blank')
431 expect(error.title).to.equal('Bad Request')
433 expect(error.detail).to.equal('Incorrect request parameters: language')
434 expect(error.error).to.equal('Incorrect request parameters: language')
436 expect(error.status).to.equal(HttpStatusCode.BAD_REQUEST_400)
437 expect(error['invalid-params'].language).to.exist
440 it('Should succeed with the correct parameters', async function () {
443 const fields = baseCorrectParams
446 const attaches = baseCorrectAttaches
447 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode)
451 const attaches = immutableAssign(baseCorrectAttaches, {
452 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
455 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode)
459 const attaches = immutableAssign(baseCorrectAttaches, {
460 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.ogv')
463 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode)
468 describe('Resumable upload', function () {
469 runSuite('resumable')
472 describe('Legacy upload', function () {
477 describe('When updating a video', function () {
478 const baseCorrectParams = {
479 name: 'my super name',
484 commentsEnabled: false,
485 downloadEnabled: false,
486 description: 'my super description',
487 privacy: VideoPrivacy.PUBLIC,
488 tags: [ 'tag1', 'tag2' ]
491 before(async function () {
492 const res = await getVideosList(server.url)
493 video = res.body.data[0]
496 it('Should fail with nothing', async function () {
498 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
501 it('Should fail without a valid uuid', async function () {
502 const fields = baseCorrectParams
503 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
506 it('Should fail with an unknown id', async function () {
507 const fields = baseCorrectParams
509 await makePutBodyRequest({
511 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
512 token: server.accessToken,
514 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
518 it('Should fail with a long name', async function () {
519 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
521 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
524 it('Should fail with a bad category', async function () {
525 const fields = immutableAssign(baseCorrectParams, { category: 125 })
527 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
530 it('Should fail with a bad licence', async function () {
531 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
533 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
536 it('Should fail with a bad language', async function () {
537 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
539 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
542 it('Should fail with a long description', async function () {
543 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
545 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
548 it('Should fail with a long support text', async function () {
549 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
551 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
554 it('Should fail with a bad channel', async function () {
555 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
557 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
560 it('Should fail with too many tags', async function () {
561 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
563 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
566 it('Should fail with a tag length too low', async function () {
567 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
569 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
572 it('Should fail with a tag length too big', async function () {
573 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
575 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
578 it('Should fail with a bad schedule update (miss updateAt)', async function () {
579 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } })
581 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
584 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
585 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { updateAt: 'toto', privacy: VideoPrivacy.PUBLIC } })
587 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
590 it('Should fail with a bad originally published at param', async function () {
591 const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' })
593 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
596 it('Should fail with an incorrect thumbnail file', async function () {
597 const fields = baseCorrectParams
599 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
602 await makeUploadRequest({
605 path: path + video.shortUUID,
606 token: server.accessToken,
612 it('Should fail with a big thumbnail file', async function () {
613 const fields = baseCorrectParams
615 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png')
618 await makeUploadRequest({
621 path: path + video.shortUUID,
622 token: server.accessToken,
628 it('Should fail with an incorrect preview file', async function () {
629 const fields = baseCorrectParams
631 previewfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
634 await makeUploadRequest({
637 path: path + video.shortUUID,
638 token: server.accessToken,
644 it('Should fail with a big preview file', async function () {
645 const fields = baseCorrectParams
647 previewfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png')
650 await makeUploadRequest({
653 path: path + video.shortUUID,
654 token: server.accessToken,
660 it('Should fail with a video of another user without the appropriate right', async function () {
661 const fields = baseCorrectParams
663 await makePutBodyRequest({
665 path: path + video.shortUUID,
666 token: userAccessToken,
668 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
672 it('Should fail with a video of another server')
674 it('Shoud report the appropriate error', async function () {
675 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
677 const res = await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
678 const error = res.body as PeerTubeProblemDocument
680 expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/putVideo')
682 expect(error.type).to.equal('about:blank')
683 expect(error.title).to.equal('Bad Request')
685 expect(error.detail).to.equal('Incorrect request parameters: licence')
686 expect(error.error).to.equal('Incorrect request parameters: licence')
688 expect(error.status).to.equal(HttpStatusCode.BAD_REQUEST_400)
689 expect(error['invalid-params'].licence).to.exist
692 it('Should succeed with the correct parameters', async function () {
693 const fields = baseCorrectParams
695 await makePutBodyRequest({
697 path: path + video.shortUUID,
698 token: server.accessToken,
700 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
705 describe('When getting a video', function () {
706 it('Should return the list of the videos with nothing', async function () {
707 const res = await makeGetRequest({
710 statusCodeExpected: HttpStatusCode.OK_200
713 expect(res.body.data).to.be.an('array')
714 expect(res.body.data.length).to.equal(6)
717 it('Should fail without a correct uuid', async function () {
718 await getVideo(server.url, 'coucou', HttpStatusCode.BAD_REQUEST_400)
721 it('Should return 404 with an incorrect video', async function () {
722 await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404)
725 it('Shoud report the appropriate error', async function () {
726 const res = await getVideo(server.url, 'hi', HttpStatusCode.BAD_REQUEST_400)
727 const error = res.body as PeerTubeProblemDocument
729 expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/getVideo')
731 expect(error.type).to.equal('about:blank')
732 expect(error.title).to.equal('Bad Request')
734 expect(error.detail).to.equal('Incorrect request parameters: id')
735 expect(error.error).to.equal('Incorrect request parameters: id')
737 expect(error.status).to.equal(HttpStatusCode.BAD_REQUEST_400)
738 expect(error['invalid-params'].id).to.exist
741 it('Should succeed with the correct parameters', async function () {
742 await getVideo(server.url, video.shortUUID)
746 describe('When rating a video', function () {
749 before(async function () {
750 const res = await getVideosList(server.url)
751 videoId = res.body.data[0].id
754 it('Should fail without a valid uuid', async function () {
758 await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields })
761 it('Should fail with an unknown id', async function () {
765 await makePutBodyRequest({
767 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
768 token: server.accessToken,
770 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
774 it('Should fail with a wrong rating', async function () {
778 await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields })
781 it('Should succeed with the correct parameters', async function () {
785 await makePutBodyRequest({
787 path: path + videoId + '/rate',
788 token: server.accessToken,
790 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
795 describe('When removing a video', function () {
796 it('Should have 404 with nothing', async function () {
797 await makeDeleteRequest({
800 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
804 it('Should fail without a correct uuid', async function () {
805 await removeVideo(server.url, server.accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400)
808 it('Should fail with a video which does not exist', async function () {
809 await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404)
812 it('Should fail with a video of another user without the appropriate right', async function () {
813 await removeVideo(server.url, userAccessToken, video.uuid, HttpStatusCode.FORBIDDEN_403)
816 it('Should fail with a video of another server')
818 it('Shoud report the appropriate error', async function () {
819 const res = await removeVideo(server.url, server.accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400)
820 const error = res.body as PeerTubeProblemDocument
822 expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/delVideo')
824 expect(error.type).to.equal('about:blank')
825 expect(error.title).to.equal('Bad Request')
827 expect(error.detail).to.equal('Incorrect request parameters: id')
828 expect(error.error).to.equal('Incorrect request parameters: id')
830 expect(error.status).to.equal(HttpStatusCode.BAD_REQUEST_400)
831 expect(error['invalid-params'].id).to.exist
834 it('Should succeed with the correct parameters', async function () {
835 await removeVideo(server.url, server.accessToken, video.uuid)
839 after(async function () {
840 await cleanupTests([ server ])