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 { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination, checkUploadVideoParam } from '@server/tests/shared'
8 import { randomInt, root } from '@shared/core-utils'
9 import { HttpStatusCode, PeerTubeProblemDocument, VideoCreateResult, VideoPrivacy } from '@shared/models'
18 setAccessTokensToServers
19 } from '@shared/server-commands'
21 const expect = chai.expect
23 describe('Test videos API validator', function () {
24 const path = '/api/v1/videos/'
25 let server: PeerTubeServer
26 let userAccessToken = ''
27 let accountName: string
29 let channelName: string
30 let video: VideoCreateResult
31 let privateVideo: VideoCreateResult
33 // ---------------------------------------------------------------
35 before(async function () {
38 server = await createSingleServer(1)
40 await setAccessTokensToServers([ server ])
42 const username = 'user1'
43 const password = 'my super password'
44 await server.users.create({ username: username, password: password })
45 userAccessToken = await server.login.getAccessToken({ username, password })
48 const body = await server.users.getMyInfo()
49 channelId = body.videoChannels[0].id
50 channelName = body.videoChannels[0].name
51 accountName = body.account.name + '@' + body.account.host
55 privateVideo = await server.videos.quickUpload({ name: 'private video', privacy: VideoPrivacy.PRIVATE })
59 describe('When listing videos', function () {
60 it('Should fail with a bad start pagination', async function () {
61 await checkBadStartPagination(server.url, path)
64 it('Should fail with a bad count pagination', async function () {
65 await checkBadCountPagination(server.url, path)
68 it('Should fail with an incorrect sort', async function () {
69 await checkBadSortPagination(server.url, path)
72 it('Should fail with a bad skipVideos query', async function () {
73 await makeGetRequest({ url: server.url, path, expectedStatus: HttpStatusCode.OK_200, query: { skipCount: 'toto' } })
76 it('Should success with the correct parameters', async function () {
77 await makeGetRequest({ url: server.url, path, expectedStatus: HttpStatusCode.OK_200, query: { skipCount: false } })
81 describe('When searching a video', function () {
83 it('Should fail with nothing', async function () {
84 await makeGetRequest({
86 path: join(path, 'search'),
87 expectedStatus: HttpStatusCode.BAD_REQUEST_400
91 it('Should fail with a bad start pagination', async function () {
92 await checkBadStartPagination(server.url, join(path, 'search', 'test'))
95 it('Should fail with a bad count pagination', async function () {
96 await checkBadCountPagination(server.url, join(path, 'search', 'test'))
99 it('Should fail with an incorrect sort', async function () {
100 await checkBadSortPagination(server.url, join(path, 'search', 'test'))
103 it('Should success with the correct parameters', async function () {
104 await makeGetRequest({ url: server.url, path, expectedStatus: HttpStatusCode.OK_200 })
108 describe('When listing my videos', function () {
109 const path = '/api/v1/users/me/videos'
111 it('Should fail with a bad start pagination', async function () {
112 await checkBadStartPagination(server.url, path, server.accessToken)
115 it('Should fail with a bad count pagination', async function () {
116 await checkBadCountPagination(server.url, path, server.accessToken)
119 it('Should fail with an incorrect sort', async function () {
120 await checkBadSortPagination(server.url, path, server.accessToken)
123 it('Should fail with an invalid channel', async function () {
124 await makeGetRequest({ url: server.url, token: server.accessToken, path, query: { channelId: 'toto' } })
127 it('Should fail with an unknown channel', async function () {
128 await makeGetRequest({
130 token: server.accessToken,
132 query: { channelId: 89898 },
133 expectedStatus: HttpStatusCode.NOT_FOUND_404
137 it('Should success with the correct parameters', async function () {
138 await makeGetRequest({ url: server.url, token: server.accessToken, path, expectedStatus: HttpStatusCode.OK_200 })
142 describe('When listing account videos', function () {
145 before(async function () {
146 path = '/api/v1/accounts/' + accountName + '/videos'
149 it('Should fail with a bad start pagination', async function () {
150 await checkBadStartPagination(server.url, path, server.accessToken)
153 it('Should fail with a bad count pagination', async function () {
154 await checkBadCountPagination(server.url, path, server.accessToken)
157 it('Should fail with an incorrect sort', async function () {
158 await checkBadSortPagination(server.url, path, server.accessToken)
161 it('Should success with the correct parameters', async function () {
162 await makeGetRequest({ url: server.url, path, expectedStatus: HttpStatusCode.OK_200 })
166 describe('When listing video channel videos', function () {
169 before(async function () {
170 path = '/api/v1/video-channels/' + channelName + '/videos'
173 it('Should fail with a bad start pagination', async function () {
174 await checkBadStartPagination(server.url, path, server.accessToken)
177 it('Should fail with a bad count pagination', async function () {
178 await checkBadCountPagination(server.url, path, server.accessToken)
181 it('Should fail with an incorrect sort', async function () {
182 await checkBadSortPagination(server.url, path, server.accessToken)
185 it('Should success with the correct parameters', async function () {
186 await makeGetRequest({ url: server.url, path, expectedStatus: HttpStatusCode.OK_200 })
190 describe('When adding a video', function () {
191 let baseCorrectParams
192 const baseCorrectAttaches = {
193 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.webm')
197 // Put in before to have channelId
198 baseCorrectParams = {
199 name: 'my super name',
204 commentsEnabled: true,
205 downloadEnabled: true,
206 waitTranscoding: true,
207 description: 'my super description',
208 support: 'my super support text',
209 tags: [ 'tag1', 'tag2' ],
210 privacy: VideoPrivacy.PUBLIC,
211 channelId: channelId,
212 originallyPublishedAt: new Date().toISOString()
216 function runSuite (mode: 'legacy' | 'resumable') {
218 it('Should fail with nothing', async function () {
221 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
224 it('Should fail without name', async function () {
225 const fields = omit(baseCorrectParams, 'name')
226 const attaches = baseCorrectAttaches
228 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
231 it('Should fail with a long name', async function () {
232 const fields = { ...baseCorrectParams, name: 'super'.repeat(65) }
233 const attaches = baseCorrectAttaches
235 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
238 it('Should fail with a bad category', async function () {
239 const fields = { ...baseCorrectParams, category: 125 }
240 const attaches = baseCorrectAttaches
242 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
245 it('Should fail with a bad licence', async function () {
246 const fields = { ...baseCorrectParams, licence: 125 }
247 const attaches = baseCorrectAttaches
249 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
252 it('Should fail with a bad language', async function () {
253 const fields = { ...baseCorrectParams, language: 'a'.repeat(15) }
254 const attaches = baseCorrectAttaches
256 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
259 it('Should fail with a long description', async function () {
260 const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) }
261 const attaches = baseCorrectAttaches
263 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
266 it('Should fail with a long support text', async function () {
267 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
268 const attaches = baseCorrectAttaches
270 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
273 it('Should fail without a channel', async function () {
274 const fields = omit(baseCorrectParams, 'channelId')
275 const attaches = baseCorrectAttaches
277 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
280 it('Should fail with a bad channel', async function () {
281 const fields = { ...baseCorrectParams, channelId: 545454 }
282 const attaches = baseCorrectAttaches
284 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
287 it('Should fail with another user channel', async function () {
289 username: 'fake' + randomInt(0, 1500),
290 password: 'fake_password'
292 await server.users.create({ username: user.username, password: user.password })
294 const accessTokenUser = await server.login.getAccessToken(user)
295 const { videoChannels } = await server.users.getMyInfo({ token: accessTokenUser })
296 const customChannelId = videoChannels[0].id
298 const fields = { ...baseCorrectParams, channelId: customChannelId }
299 const attaches = baseCorrectAttaches
301 await checkUploadVideoParam(server, userAccessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
304 it('Should fail with too many tags', async function () {
305 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }
306 const attaches = baseCorrectAttaches
308 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
311 it('Should fail with a tag length too low', async function () {
312 const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] }
313 const attaches = baseCorrectAttaches
315 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
318 it('Should fail with a tag length too big', async function () {
319 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }
320 const attaches = baseCorrectAttaches
322 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
325 it('Should fail with a bad schedule update (miss updateAt)', async function () {
326 const fields = { ...baseCorrectParams, scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } }
327 const attaches = baseCorrectAttaches
329 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
332 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
334 ...baseCorrectParams,
337 privacy: VideoPrivacy.PUBLIC,
341 const attaches = baseCorrectAttaches
343 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
346 it('Should fail with a bad originally published at attribute', async function () {
347 const fields = { ...baseCorrectParams, originallyPublishedAt: 'toto' }
348 const attaches = baseCorrectAttaches
350 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
353 it('Should fail without an input file', async function () {
354 const fields = baseCorrectParams
356 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
359 it('Should fail with an incorrect input file', async function () {
360 const fields = baseCorrectParams
361 let attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short_fake.webm') }
363 await checkUploadVideoParam(
366 { ...fields, ...attaches },
367 HttpStatusCode.UNPROCESSABLE_ENTITY_422,
371 attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mkv') }
372 await checkUploadVideoParam(
375 { ...fields, ...attaches },
376 HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415,
381 it('Should fail with an incorrect thumbnail file', async function () {
382 const fields = baseCorrectParams
384 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4'),
385 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
388 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
391 it('Should fail with a big thumbnail file', async function () {
392 const fields = baseCorrectParams
394 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png'),
395 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
398 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
401 it('Should fail with an incorrect preview file', async function () {
402 const fields = baseCorrectParams
404 previewfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4'),
405 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
408 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
411 it('Should fail with a big preview file', async function () {
412 const fields = baseCorrectParams
414 previewfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png'),
415 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
418 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
421 it('Should report the appropriate error', async function () {
422 const fields = { ...baseCorrectParams, language: 'a'.repeat(15) }
423 const attaches = baseCorrectAttaches
425 const attributes = { ...fields, ...attaches }
426 const body = await checkUploadVideoParam(server, server.accessToken, attributes, HttpStatusCode.BAD_REQUEST_400, mode)
428 const error = body as unknown as PeerTubeProblemDocument
430 if (mode === 'legacy') {
431 expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/uploadLegacy')
433 expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/uploadResumableInit')
436 expect(error.type).to.equal('about:blank')
437 expect(error.title).to.equal('Bad Request')
439 expect(error.detail).to.equal('Incorrect request parameters: language')
440 expect(error.error).to.equal('Incorrect request parameters: language')
442 expect(error.status).to.equal(HttpStatusCode.BAD_REQUEST_400)
443 expect(error['invalid-params'].language).to.exist
446 it('Should succeed with the correct parameters', async function () {
449 const fields = baseCorrectParams
452 const attaches = baseCorrectAttaches
453 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode)
458 ...baseCorrectAttaches,
460 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
463 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode)
468 ...baseCorrectAttaches,
470 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.ogv')
473 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode)
478 describe('Resumable upload', function () {
479 runSuite('resumable')
482 describe('Legacy upload', function () {
487 describe('When updating a video', function () {
488 const baseCorrectParams = {
489 name: 'my super name',
494 commentsEnabled: false,
495 downloadEnabled: false,
496 description: 'my super description',
497 privacy: VideoPrivacy.PUBLIC,
498 tags: [ 'tag1', 'tag2' ]
501 before(async function () {
502 const { data } = await server.videos.list()
506 it('Should fail with nothing', async function () {
508 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
511 it('Should fail without a valid uuid', async function () {
512 const fields = baseCorrectParams
513 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
516 it('Should fail with an unknown id', async function () {
517 const fields = baseCorrectParams
519 await makePutBodyRequest({
521 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
522 token: server.accessToken,
524 expectedStatus: HttpStatusCode.NOT_FOUND_404
528 it('Should fail with a long name', async function () {
529 const fields = { ...baseCorrectParams, name: 'super'.repeat(65) }
531 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
534 it('Should fail with a bad category', async function () {
535 const fields = { ...baseCorrectParams, category: 125 }
537 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
540 it('Should fail with a bad licence', async function () {
541 const fields = { ...baseCorrectParams, licence: 125 }
543 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
546 it('Should fail with a bad language', async function () {
547 const fields = { ...baseCorrectParams, language: 'a'.repeat(15) }
549 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
552 it('Should fail with a long description', async function () {
553 const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) }
555 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
558 it('Should fail with a long support text', async function () {
559 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
561 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
564 it('Should fail with a bad channel', async function () {
565 const fields = { ...baseCorrectParams, channelId: 545454 }
567 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
570 it('Should fail with too many tags', async function () {
571 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }
573 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
576 it('Should fail with a tag length too low', async function () {
577 const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] }
579 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
582 it('Should fail with a tag length too big', async function () {
583 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }
585 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
588 it('Should fail with a bad schedule update (miss updateAt)', async function () {
589 const fields = { ...baseCorrectParams, scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } }
591 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
594 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
595 const fields = { ...baseCorrectParams, scheduleUpdate: { updateAt: 'toto', privacy: VideoPrivacy.PUBLIC } }
597 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
600 it('Should fail with a bad originally published at param', async function () {
601 const fields = { ...baseCorrectParams, originallyPublishedAt: 'toto' }
603 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
606 it('Should fail with an incorrect thumbnail file', async function () {
607 const fields = baseCorrectParams
609 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
612 await makeUploadRequest({
615 path: path + video.shortUUID,
616 token: server.accessToken,
622 it('Should fail with a big thumbnail file', async function () {
623 const fields = baseCorrectParams
625 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png')
628 await makeUploadRequest({
631 path: path + video.shortUUID,
632 token: server.accessToken,
638 it('Should fail with an incorrect preview file', async function () {
639 const fields = baseCorrectParams
641 previewfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
644 await makeUploadRequest({
647 path: path + video.shortUUID,
648 token: server.accessToken,
654 it('Should fail with a big preview file', async function () {
655 const fields = baseCorrectParams
657 previewfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png')
660 await makeUploadRequest({
663 path: path + video.shortUUID,
664 token: server.accessToken,
670 it('Should fail with a video of another user without the appropriate right', async function () {
671 const fields = baseCorrectParams
673 await makePutBodyRequest({
675 path: path + video.shortUUID,
676 token: userAccessToken,
678 expectedStatus: HttpStatusCode.FORBIDDEN_403
682 it('Should fail with a video of another server')
684 it('Shoud report the appropriate error', async function () {
685 const fields = { ...baseCorrectParams, licence: 125 }
687 const res = await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
688 const error = res.body as PeerTubeProblemDocument
690 expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/putVideo')
692 expect(error.type).to.equal('about:blank')
693 expect(error.title).to.equal('Bad Request')
695 expect(error.detail).to.equal('Incorrect request parameters: licence')
696 expect(error.error).to.equal('Incorrect request parameters: licence')
698 expect(error.status).to.equal(HttpStatusCode.BAD_REQUEST_400)
699 expect(error['invalid-params'].licence).to.exist
702 it('Should succeed with the correct parameters', async function () {
703 const fields = baseCorrectParams
705 await makePutBodyRequest({
707 path: path + video.shortUUID,
708 token: server.accessToken,
710 expectedStatus: HttpStatusCode.NO_CONTENT_204
715 describe('When getting a video', function () {
716 it('Should return the list of the videos with nothing', async function () {
717 const res = await makeGetRequest({
720 expectedStatus: HttpStatusCode.OK_200
723 expect(res.body.data).to.be.an('array')
724 expect(res.body.data.length).to.equal(6)
727 it('Should fail without a correct uuid', async function () {
728 await server.videos.get({ id: 'coucou', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
731 it('Should return 404 with an incorrect video', async function () {
732 await server.videos.get({ id: '4da6fde3-88f7-4d16-b119-108df5630b06', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
735 it('Shoud report the appropriate error', async function () {
736 const body = await server.videos.get({ id: 'hi', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
737 const error = body as unknown as PeerTubeProblemDocument
739 expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/getVideo')
741 expect(error.type).to.equal('about:blank')
742 expect(error.title).to.equal('Bad Request')
744 expect(error.detail).to.equal('Incorrect request parameters: id')
745 expect(error.error).to.equal('Incorrect request parameters: id')
747 expect(error.status).to.equal(HttpStatusCode.BAD_REQUEST_400)
748 expect(error['invalid-params'].id).to.exist
751 it('Should succeed with the correct parameters', async function () {
752 await server.videos.get({ id: video.shortUUID })
756 describe('When rating a video', function () {
759 before(async function () {
760 const { data } = await server.videos.list()
764 it('Should fail without a valid uuid', async function () {
768 await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields })
771 it('Should fail with an unknown id', async function () {
775 await makePutBodyRequest({
777 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
778 token: server.accessToken,
780 expectedStatus: HttpStatusCode.NOT_FOUND_404
784 it('Should fail with a wrong rating', async function () {
788 await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields })
791 it('Should fail with a private video of another user', async function () {
795 await makePutBodyRequest({
797 path: path + privateVideo.uuid + '/rate',
798 token: userAccessToken,
800 expectedStatus: HttpStatusCode.FORBIDDEN_403
804 it('Should succeed with the correct parameters', async function () {
808 await makePutBodyRequest({
810 path: path + videoId + '/rate',
811 token: server.accessToken,
813 expectedStatus: HttpStatusCode.NO_CONTENT_204
818 describe('When removing a video', function () {
819 it('Should have 404 with nothing', async function () {
820 await makeDeleteRequest({
823 expectedStatus: HttpStatusCode.BAD_REQUEST_400
827 it('Should fail without a correct uuid', async function () {
828 await server.videos.remove({ id: 'hello', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
831 it('Should fail with a video which does not exist', async function () {
832 await server.videos.remove({ id: '4da6fde3-88f7-4d16-b119-108df5630b06', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
835 it('Should fail with a video of another user without the appropriate right', async function () {
836 await server.videos.remove({ token: userAccessToken, id: video.uuid, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
839 it('Should fail with a video of another server')
841 it('Shoud report the appropriate error', async function () {
842 const body = await server.videos.remove({ id: 'hello', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
843 const error = body as PeerTubeProblemDocument
845 expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/delVideo')
847 expect(error.type).to.equal('about:blank')
848 expect(error.title).to.equal('Bad Request')
850 expect(error.detail).to.equal('Incorrect request parameters: id')
851 expect(error.error).to.equal('Incorrect request parameters: id')
853 expect(error.status).to.equal(HttpStatusCode.BAD_REQUEST_400)
854 expect(error['invalid-params'].id).to.exist
857 it('Should succeed with the correct parameters', async function () {
858 await server.videos.remove({ id: video.uuid })
862 after(async function () {
863 await cleanupTests([ server ])