aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/videos.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params/videos.ts')
-rw-r--r--server/tests/api/check-params/videos.ts78
1 files changed, 77 insertions, 1 deletions
diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts
index c970c4a15..a6eecb13a 100644
--- a/server/tests/api/check-params/videos.ts
+++ b/server/tests/api/check-params/videos.ts
@@ -4,6 +4,8 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { omit } from 'lodash' 5import { omit } from 'lodash'
6import { join } from 'path' 6import { join } from 'path'
7import { randomInt } from '@shared/core-utils'
8import { PeerTubeProblemDocument } from '@shared/models'
7import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 9import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
8import { 10import {
9 checkUploadVideoParam, 11 checkUploadVideoParam,
@@ -30,7 +32,6 @@ import {
30 checkBadStartPagination 32 checkBadStartPagination
31} from '../../../../shared/extra-utils/requests/check-api-params' 33} from '../../../../shared/extra-utils/requests/check-api-params'
32import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' 34import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
33import { randomInt } from '@shared/core-utils'
34 35
35const expect = chai.expect 36const expect = chai.expect
36 37
@@ -411,6 +412,31 @@ describe('Test videos API validator', function () {
411 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 412 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
412 }) 413 })
413 414
415 it('Should report the appropriate error', async function () {
416 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
417 const attaches = baseCorrectAttaches
418
419 const attributes = { ...fields, ...attaches }
420 const res = await checkUploadVideoParam(server.url, server.accessToken, attributes, HttpStatusCode.BAD_REQUEST_400, mode)
421
422 const error = res.body as PeerTubeProblemDocument
423
424 if (mode === 'legacy') {
425 expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/uploadLegacy')
426 } else {
427 expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/uploadResumableInit')
428 }
429
430 expect(error.type).to.equal('about:blank')
431 expect(error.title).to.equal('Bad Request')
432
433 expect(error.detail).to.equal('Incorrect request parameters: language')
434 expect(error.error).to.equal('Incorrect request parameters: language')
435
436 expect(error.status).to.equal(HttpStatusCode.BAD_REQUEST_400)
437 expect(error['invalid-params'].language).to.exist
438 })
439
414 it('Should succeed with the correct parameters', async function () { 440 it('Should succeed with the correct parameters', async function () {
415 this.timeout(10000) 441 this.timeout(10000)
416 442
@@ -645,6 +671,24 @@ describe('Test videos API validator', function () {
645 671
646 it('Should fail with a video of another server') 672 it('Should fail with a video of another server')
647 673
674 it('Shoud report the appropriate error', async function () {
675 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
676
677 const res = await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
678 const error = res.body as PeerTubeProblemDocument
679
680 expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/putVideo')
681
682 expect(error.type).to.equal('about:blank')
683 expect(error.title).to.equal('Bad Request')
684
685 expect(error.detail).to.equal('Incorrect request parameters: licence')
686 expect(error.error).to.equal('Incorrect request parameters: licence')
687
688 expect(error.status).to.equal(HttpStatusCode.BAD_REQUEST_400)
689 expect(error['invalid-params'].licence).to.exist
690 })
691
648 it('Should succeed with the correct parameters', async function () { 692 it('Should succeed with the correct parameters', async function () {
649 const fields = baseCorrectParams 693 const fields = baseCorrectParams
650 694
@@ -678,6 +722,22 @@ describe('Test videos API validator', function () {
678 await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404) 722 await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404)
679 }) 723 })
680 724
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
728
729 expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/getVideo')
730
731 expect(error.type).to.equal('about:blank')
732 expect(error.title).to.equal('Bad Request')
733
734 expect(error.detail).to.equal('Incorrect request parameters: id')
735 expect(error.error).to.equal('Incorrect request parameters: id')
736
737 expect(error.status).to.equal(HttpStatusCode.BAD_REQUEST_400)
738 expect(error['invalid-params'].id).to.exist
739 })
740
681 it('Should succeed with the correct parameters', async function () { 741 it('Should succeed with the correct parameters', async function () {
682 await getVideo(server.url, videoId) 742 await getVideo(server.url, videoId)
683 }) 743 })
@@ -755,6 +815,22 @@ describe('Test videos API validator', function () {
755 815
756 it('Should fail with a video of another server') 816 it('Should fail with a video of another server')
757 817
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
821
822 expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/delVideo')
823
824 expect(error.type).to.equal('about:blank')
825 expect(error.title).to.equal('Bad Request')
826
827 expect(error.detail).to.equal('Incorrect request parameters: id')
828 expect(error.error).to.equal('Incorrect request parameters: id')
829
830 expect(error.status).to.equal(HttpStatusCode.BAD_REQUEST_400)
831 expect(error['invalid-params'].id).to.exist
832 })
833
758 it('Should succeed with the correct parameters', async function () { 834 it('Should succeed with the correct parameters', async function () {
759 await removeVideo(server.url, server.accessToken, videoId) 835 await removeVideo(server.url, server.accessToken, videoId)
760 }) 836 })