aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-06-02 18:15:41 +0200
committerChocobozzz <me@florianbigard.com>2021-06-02 18:15:41 +0200
commite030bfb59dd5ee65f20a64686ec9b22ca39f70ae (patch)
treec9a439159ef540291e3c030bcaf958b953442147 /server/tests
parent463206948d6a9d46e7e68d55c7b763e601ecc870 (diff)
downloadPeerTube-e030bfb59dd5ee65f20a64686ec9b22ca39f70ae.tar.gz
PeerTube-e030bfb59dd5ee65f20a64686ec9b22ca39f70ae.tar.zst
PeerTube-e030bfb59dd5ee65f20a64686ec9b22ca39f70ae.zip
Refactor server errors handler
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/check-params/videos.ts78
-rw-r--r--server/tests/api/server/follow-constraints.ts16
2 files changed, 92 insertions, 2 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 })
diff --git a/server/tests/api/server/follow-constraints.ts b/server/tests/api/server/follow-constraints.ts
index 8a91fbba3..3f2f71f46 100644
--- a/server/tests/api/server/follow-constraints.ts
+++ b/server/tests/api/server/follow-constraints.ts
@@ -18,6 +18,7 @@ import { unfollow } from '../../../../shared/extra-utils/server/follows'
18import { userLogin } from '../../../../shared/extra-utils/users/login' 18import { userLogin } from '../../../../shared/extra-utils/users/login'
19import { createUser } from '../../../../shared/extra-utils/users/users' 19import { createUser } from '../../../../shared/extra-utils/users/users'
20import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 20import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
21import { PeerTubeProblemDocument, ServerErrorCode } from '@shared/models'
21 22
22const expect = chai.expect 23const expect = chai.expect
23 24
@@ -153,7 +154,20 @@ describe('Test follow constraints', function () {
153 }) 154 })
154 155
155 it('Should not get the remote video', async function () { 156 it('Should not get the remote video', async function () {
156 await getVideo(servers[0].url, video2UUID, HttpStatusCode.FORBIDDEN_403) 157 const res = await getVideo(servers[0].url, video2UUID, HttpStatusCode.FORBIDDEN_403)
158
159 const error = res.body as PeerTubeProblemDocument
160
161 const doc = 'https://docs.joinpeertube.org/api-rest-reference.html#section/Errors/does_not_respect_follow_constraints'
162 expect(error.type).to.equal(doc)
163 expect(error.code).to.equal(ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS)
164
165 expect(error.detail).to.equal('Cannot get this video regarding follow constraints')
166 expect(error.error).to.equal(error.detail)
167
168 expect(error.status).to.equal(HttpStatusCode.FORBIDDEN_403)
169
170 expect(error.originUrl).to.contains(servers[1].url)
157 }) 171 })
158 172
159 it('Should list local account videos', async function () { 173 it('Should list local account videos', async function () {