From 2d53be0267acc49cda46707b885096193a1f4e9c Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Mon, 7 Dec 2020 14:32:36 +0100 Subject: replace numbers with typed http status codes (#3409) --- server/tests/api/activitypub/security.ts | 17 +- server/tests/api/check-params/abuses.ts | 97 ++++++---- server/tests/api/check-params/blocklist.ts | 77 ++++---- server/tests/api/check-params/bulk.ts | 11 +- server/tests/api/check-params/config.ts | 23 +-- server/tests/api/check-params/debug.ts | 7 +- server/tests/api/check-params/follows.ts | 49 ++--- server/tests/api/check-params/jobs.ts | 5 +- server/tests/api/check-params/live.ts | 43 ++--- server/tests/api/check-params/logs.ts | 15 +- server/tests/api/check-params/plugins.ts | 69 +++---- server/tests/api/check-params/redundancy.ts | 33 ++-- server/tests/api/check-params/search.ts | 59 +++--- server/tests/api/check-params/services.ts | 17 +- .../tests/api/check-params/user-notifications.ts | 31 +-- .../tests/api/check-params/user-subscriptions.ts | 51 ++--- server/tests/api/check-params/users.ts | 210 ++++++++++++++------- server/tests/api/check-params/video-blacklist.ts | 82 ++++++-- server/tests/api/check-params/video-captions.ts | 41 ++-- server/tests/api/check-params/video-channels.ts | 35 ++-- server/tests/api/check-params/video-comments.ts | 109 ++++++++--- server/tests/api/check-params/video-imports.ts | 32 +++- server/tests/api/check-params/video-playlists.ts | 114 ++++++----- server/tests/api/check-params/videos-filter.ts | 23 +-- server/tests/api/check-params/videos-history.ts | 47 +++-- server/tests/api/check-params/videos.ts | 57 +++--- server/tests/api/redundancy/redundancy.ts | 5 +- server/tests/api/users/users.ts | 49 ++--- server/tests/api/videos/video-transcoder.ts | 11 +- server/tests/api/videos/videos-filter.ts | 3 +- 30 files changed, 871 insertions(+), 551 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/activitypub/security.ts b/server/tests/api/activitypub/security.ts index e6002b661..55dcced15 100644 --- a/server/tests/api/activitypub/security.ts +++ b/server/tests/api/activitypub/security.ts @@ -9,6 +9,7 @@ import * as chai from 'chai' import { activityPubContextify, buildSignedActivity } from '../../../helpers/activitypub' import { makeFollowRequest, makePOSTAPRequest } from '../../../../shared/extra-utils/requests/activitypub' import { buildDigest } from '@server/helpers/peertube-crypto' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' const expect = chai.expect @@ -74,7 +75,7 @@ describe('Test ActivityPub security', function () { const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers) - expect(response.statusCode).to.equal(403) + expect(response.statusCode).to.equal(HttpStatusCode.FORBIDDEN_403) }) it('Should fail with an invalid date', async function () { @@ -84,7 +85,7 @@ describe('Test ActivityPub security', function () { const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers) - expect(response.statusCode).to.equal(403) + expect(response.statusCode).to.equal(HttpStatusCode.FORBIDDEN_403) }) it('Should fail with bad keys', async function () { @@ -96,7 +97,7 @@ describe('Test ActivityPub security', function () { const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers) - expect(response.statusCode).to.equal(403) + expect(response.statusCode).to.equal(HttpStatusCode.FORBIDDEN_403) }) it('Should reject requests without appropriate signed headers', async function () { @@ -117,7 +118,7 @@ describe('Test ActivityPub security', function () { signatureOptions.headers = badHeaders const { response } = await makePOSTAPRequest(url, body, signatureOptions, headers) - expect(response.statusCode).to.equal(403) + expect(response.statusCode).to.equal(HttpStatusCode.FORBIDDEN_403) } }) @@ -127,7 +128,7 @@ describe('Test ActivityPub security', function () { const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers) - expect(response.statusCode).to.equal(204) + expect(response.statusCode).to.equal(HttpStatusCode.NO_CONTENT_204) }) }) @@ -156,7 +157,7 @@ describe('Test ActivityPub security', function () { const { response } = await makePOSTAPRequest(url, signedBody, baseHttpSignature(), headers) - expect(response.statusCode).to.equal(403) + expect(response.statusCode).to.equal(HttpStatusCode.FORBIDDEN_403) }) it('Should fail with an altered body', async function () { @@ -177,7 +178,7 @@ describe('Test ActivityPub security', function () { const { response } = await makePOSTAPRequest(url, signedBody, baseHttpSignature(), headers) - expect(response.statusCode).to.equal(403) + expect(response.statusCode).to.equal(HttpStatusCode.FORBIDDEN_403) }) it('Should succeed with a valid signature', async function () { @@ -193,7 +194,7 @@ describe('Test ActivityPub security', function () { const { response } = await makePOSTAPRequest(url, signedBody, baseHttpSignature(), headers) - expect(response.statusCode).to.equal(204) + expect(response.statusCode).to.equal(HttpStatusCode.NO_CONTENT_204) }) }) diff --git a/server/tests/api/check-params/abuses.ts b/server/tests/api/check-params/abuses.ts index 8dadd9922..ef6c66b72 100644 --- a/server/tests/api/check-params/abuses.ts +++ b/server/tests/api/check-params/abuses.ts @@ -29,6 +29,7 @@ import { checkBadSortPagination, checkBadStartPagination } from '../../../../shared/extra-utils/requests/check-api-params' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' describe('Test abuses API validators', function () { const basePath = '/api/v1/abuses/' @@ -81,7 +82,7 @@ describe('Test abuses API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -90,7 +91,7 @@ describe('Test abuses API validators', function () { url: server.url, path, token: userAccessToken, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) @@ -125,7 +126,7 @@ describe('Test abuses API validators', function () { videoIs: 'deleted' } - await makeGetRequest({ url: server.url, path, token: server.accessToken, query, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path, token: server.accessToken, query, statusCodeExpected: HttpStatusCode.OK_200 }) }) }) @@ -148,7 +149,7 @@ describe('Test abuses API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -167,7 +168,7 @@ describe('Test abuses API validators', function () { state: 2 } - await makeGetRequest({ url: server.url, path, token: userAccessToken, query, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path, token: userAccessToken, query, statusCodeExpected: HttpStatusCode.OK_200 }) }) }) @@ -186,7 +187,13 @@ describe('Test abuses API validators', function () { it('Should fail with an unknown video', async function () { const fields = { video: { id: 42 }, reason: 'my super reason' } - await makePostBodyRequest({ url: server.url, path: path, token: userAccessToken, fields, statusCodeExpected: 404 }) + await makePostBodyRequest({ + url: server.url, + path, + token: userAccessToken, + fields, + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + }) }) it('Should fail with a wrong comment', async function () { @@ -196,7 +203,13 @@ describe('Test abuses API validators', function () { it('Should fail with an unknown comment', async function () { const fields = { comment: { id: 42 }, reason: 'my super reason' } - await makePostBodyRequest({ url: server.url, path: path, token: userAccessToken, fields, statusCodeExpected: 404 }) + await makePostBodyRequest({ + url: server.url, + path, + token: userAccessToken, + fields, + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + }) }) it('Should fail with a wrong account', async function () { @@ -206,18 +219,30 @@ describe('Test abuses API validators', function () { it('Should fail with an unknown account', async function () { const fields = { account: { id: 42 }, reason: 'my super reason' } - await makePostBodyRequest({ url: server.url, path: path, token: userAccessToken, fields, statusCodeExpected: 404 }) + await makePostBodyRequest({ + url: server.url, + path, + token: userAccessToken, + fields, + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + }) }) it('Should fail with not account, comment or video', async function () { const fields = { reason: 'my super reason' } - await makePostBodyRequest({ url: server.url, path: path, token: userAccessToken, fields, statusCodeExpected: 400 }) + await makePostBodyRequest({ + url: server.url, + path, + token: userAccessToken, + fields, + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + }) }) it('Should fail with a non authenticated user', async function () { const fields = { video: { id: server.video.id }, reason: 'my super reason' } - await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 }) + await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with a reason too short', async function () { @@ -235,7 +260,13 @@ describe('Test abuses API validators', function () { it('Should succeed with the correct parameters (basic)', async function () { const fields: AbuseCreate = { video: { id: server.video.id }, reason: 'my super reason' } - const res = await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 200 }) + const res = await makePostBodyRequest({ + url: server.url, + path, + token: userAccessToken, + fields, + statusCodeExpected: HttpStatusCode.OK_200 + }) abuseId = res.body.abuse.id }) @@ -268,32 +299,32 @@ describe('Test abuses API validators', function () { predefinedReasons: [ 'serverRules' ] } - await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 200 }) + await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: HttpStatusCode.OK_200 }) }) }) describe('When updating an abuse', function () { it('Should fail with a non authenticated user', async function () { - await updateAbuse(server.url, 'blabla', abuseId, {}, 401) + await updateAbuse(server.url, 'blabla', abuseId, {}, HttpStatusCode.UNAUTHORIZED_401) }) it('Should fail with a non admin user', async function () { - await updateAbuse(server.url, userAccessToken, abuseId, {}, 403) + await updateAbuse(server.url, userAccessToken, abuseId, {}, HttpStatusCode.FORBIDDEN_403) }) it('Should fail with a bad abuse id', async function () { - await updateAbuse(server.url, server.accessToken, 45, {}, 404) + await updateAbuse(server.url, server.accessToken, 45, {}, HttpStatusCode.NOT_FOUND_404) }) it('Should fail with a bad state', async function () { const body = { state: 5 } - await updateAbuse(server.url, server.accessToken, abuseId, body, 400) + await updateAbuse(server.url, server.accessToken, abuseId, body, HttpStatusCode.BAD_REQUEST_400) }) it('Should fail with a bad moderation comment', async function () { const body = { moderationComment: 'b'.repeat(3001) } - await updateAbuse(server.url, server.accessToken, abuseId, body, 400) + await updateAbuse(server.url, server.accessToken, abuseId, body, HttpStatusCode.BAD_REQUEST_400) }) it('Should succeed with the correct params', async function () { @@ -306,19 +337,19 @@ describe('Test abuses API validators', function () { const message = 'my super message' it('Should fail with an invalid abuse id', async function () { - await addAbuseMessage(server.url, userAccessToken2, 888, message, 404) + await addAbuseMessage(server.url, userAccessToken2, 888, message, HttpStatusCode.NOT_FOUND_404) }) it('Should fail with a non authenticated user', async function () { - await addAbuseMessage(server.url, 'fake_token', abuseId, message, 401) + await addAbuseMessage(server.url, 'fake_token', abuseId, message, HttpStatusCode.UNAUTHORIZED_401) }) it('Should fail with an invalid logged in user', async function () { - await addAbuseMessage(server.url, userAccessToken2, abuseId, message, 403) + await addAbuseMessage(server.url, userAccessToken2, abuseId, message, HttpStatusCode.FORBIDDEN_403) }) it('Should fail with an invalid message', async function () { - await addAbuseMessage(server.url, userAccessToken, abuseId, 'a'.repeat(5000), 400) + await addAbuseMessage(server.url, userAccessToken, abuseId, 'a'.repeat(5000), HttpStatusCode.BAD_REQUEST_400) }) it('Should suceed with the correct params', async function () { @@ -330,15 +361,15 @@ describe('Test abuses API validators', function () { describe('When listing abuse messages', function () { it('Should fail with an invalid abuse id', async function () { - await listAbuseMessages(server.url, userAccessToken, 888, 404) + await listAbuseMessages(server.url, userAccessToken, 888, HttpStatusCode.NOT_FOUND_404) }) it('Should fail with a non authenticated user', async function () { - await listAbuseMessages(server.url, 'fake_token', abuseId, 401) + await listAbuseMessages(server.url, 'fake_token', abuseId, HttpStatusCode.UNAUTHORIZED_401) }) it('Should fail with an invalid logged in user', async function () { - await listAbuseMessages(server.url, userAccessToken2, abuseId, 403) + await listAbuseMessages(server.url, userAccessToken2, abuseId, HttpStatusCode.FORBIDDEN_403) }) it('Should succeed with the correct params', async function () { @@ -349,19 +380,19 @@ describe('Test abuses API validators', function () { describe('When deleting an abuse message', function () { it('Should fail with an invalid abuse id', async function () { - await deleteAbuseMessage(server.url, userAccessToken, 888, messageId, 404) + await deleteAbuseMessage(server.url, userAccessToken, 888, messageId, HttpStatusCode.NOT_FOUND_404) }) it('Should fail with an invalid message id', async function () { - await deleteAbuseMessage(server.url, userAccessToken, abuseId, 888, 404) + await deleteAbuseMessage(server.url, userAccessToken, abuseId, 888, HttpStatusCode.NOT_FOUND_404) }) it('Should fail with a non authenticated user', async function () { - await deleteAbuseMessage(server.url, 'fake_token', abuseId, messageId, 401) + await deleteAbuseMessage(server.url, 'fake_token', abuseId, messageId, HttpStatusCode.UNAUTHORIZED_401) }) it('Should fail with an invalid logged in user', async function () { - await deleteAbuseMessage(server.url, userAccessToken2, abuseId, messageId, 403) + await deleteAbuseMessage(server.url, userAccessToken2, abuseId, messageId, HttpStatusCode.FORBIDDEN_403) }) it('Should succeed with the correct params', async function () { @@ -372,15 +403,15 @@ describe('Test abuses API validators', function () { describe('When deleting a video abuse', function () { it('Should fail with a non authenticated user', async function () { - await deleteAbuse(server.url, 'blabla', abuseId, 401) + await deleteAbuse(server.url, 'blabla', abuseId, HttpStatusCode.UNAUTHORIZED_401) }) it('Should fail with a non admin user', async function () { - await deleteAbuse(server.url, userAccessToken, abuseId, 403) + await deleteAbuse(server.url, userAccessToken, abuseId, HttpStatusCode.FORBIDDEN_403) }) it('Should fail with a bad abuse id', async function () { - await deleteAbuse(server.url, server.accessToken, 45, 404) + await deleteAbuse(server.url, server.accessToken, 45, HttpStatusCode.NOT_FOUND_404) }) it('Should succeed with the correct params', async function () { @@ -415,11 +446,11 @@ describe('Test abuses API validators', function () { }) it('Should fail when listing abuse messages of a remote abuse', async function () { - await listAbuseMessages(server.url, server.accessToken, remoteAbuseId, 400) + await listAbuseMessages(server.url, server.accessToken, remoteAbuseId, HttpStatusCode.BAD_REQUEST_400) }) it('Should fail when creating abuse message of a remote abuse', async function () { - await addAbuseMessage(server.url, server.accessToken, remoteAbuseId, 'message', 400) + await addAbuseMessage(server.url, server.accessToken, remoteAbuseId, 'message', HttpStatusCode.BAD_REQUEST_400) }) after(async function () { diff --git a/server/tests/api/check-params/blocklist.ts b/server/tests/api/check-params/blocklist.ts index 1219ec9bd..5ed8810ce 100644 --- a/server/tests/api/check-params/blocklist.ts +++ b/server/tests/api/check-params/blocklist.ts @@ -19,6 +19,7 @@ import { checkBadSortPagination, checkBadStartPagination } from '../../../../shared/extra-utils/requests/check-api-params' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' describe('Test blocklist API validators', function () { let servers: ServerInfo[] @@ -53,7 +54,7 @@ describe('Test blocklist API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -76,7 +77,7 @@ describe('Test blocklist API validators', function () { url: server.url, path, fields: { accountName: 'user1' }, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -86,7 +87,7 @@ describe('Test blocklist API validators', function () { token: server.accessToken, path, fields: { accountName: 'user2' }, - statusCodeExpected: 404 + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) @@ -96,7 +97,7 @@ describe('Test blocklist API validators', function () { token: server.accessToken, path, fields: { accountName: 'root' }, - statusCodeExpected: 409 + statusCodeExpected: HttpStatusCode.CONFLICT_409 }) }) @@ -106,7 +107,7 @@ describe('Test blocklist API validators', function () { token: server.accessToken, path, fields: { accountName: 'user1' }, - statusCodeExpected: 204 + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -116,7 +117,7 @@ describe('Test blocklist API validators', function () { await makeDeleteRequest({ url: server.url, path: path + '/user1', - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -125,7 +126,7 @@ describe('Test blocklist API validators', function () { url: server.url, path: path + '/user2', token: server.accessToken, - statusCodeExpected: 404 + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) @@ -134,7 +135,7 @@ describe('Test blocklist API validators', function () { url: server.url, path: path + '/user1', token: server.accessToken, - statusCodeExpected: 204 + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -148,7 +149,7 @@ describe('Test blocklist API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -171,7 +172,7 @@ describe('Test blocklist API validators', function () { url: server.url, path, fields: { host: 'localhost:9002' }, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -181,7 +182,7 @@ describe('Test blocklist API validators', function () { token: server.accessToken, path, fields: { host: 'localhost:9003' }, - statusCodeExpected: 204 + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) }) @@ -191,7 +192,7 @@ describe('Test blocklist API validators', function () { token: server.accessToken, path, fields: { host: 'localhost:' + server.port }, - statusCodeExpected: 409 + statusCodeExpected: HttpStatusCode.CONFLICT_409 }) }) @@ -201,7 +202,7 @@ describe('Test blocklist API validators', function () { token: server.accessToken, path, fields: { host: 'localhost:' + servers[1].port }, - statusCodeExpected: 204 + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -211,7 +212,7 @@ describe('Test blocklist API validators', function () { await makeDeleteRequest({ url: server.url, path: path + '/localhost:' + servers[1].port, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -220,7 +221,7 @@ describe('Test blocklist API validators', function () { url: server.url, path: path + '/localhost:9004', token: server.accessToken, - statusCodeExpected: 404 + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) @@ -229,7 +230,7 @@ describe('Test blocklist API validators', function () { url: server.url, path: path + '/localhost:' + servers[1].port, token: server.accessToken, - statusCodeExpected: 204 + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -246,7 +247,7 @@ describe('Test blocklist API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -255,7 +256,7 @@ describe('Test blocklist API validators', function () { url: server.url, token: userAccessToken, path, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) @@ -278,7 +279,7 @@ describe('Test blocklist API validators', function () { url: server.url, path, fields: { accountName: 'user1' }, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -288,7 +289,7 @@ describe('Test blocklist API validators', function () { token: userAccessToken, path, fields: { accountName: 'user1' }, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) @@ -298,7 +299,7 @@ describe('Test blocklist API validators', function () { token: server.accessToken, path, fields: { accountName: 'user2' }, - statusCodeExpected: 404 + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) @@ -308,7 +309,7 @@ describe('Test blocklist API validators', function () { token: server.accessToken, path, fields: { accountName: 'root' }, - statusCodeExpected: 409 + statusCodeExpected: HttpStatusCode.CONFLICT_409 }) }) @@ -318,7 +319,7 @@ describe('Test blocklist API validators', function () { token: server.accessToken, path, fields: { accountName: 'user1' }, - statusCodeExpected: 204 + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -328,7 +329,7 @@ describe('Test blocklist API validators', function () { await makeDeleteRequest({ url: server.url, path: path + '/user1', - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -337,7 +338,7 @@ describe('Test blocklist API validators', function () { url: server.url, path: path + '/user1', token: userAccessToken, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) @@ -346,7 +347,7 @@ describe('Test blocklist API validators', function () { url: server.url, path: path + '/user2', token: server.accessToken, - statusCodeExpected: 404 + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) @@ -355,7 +356,7 @@ describe('Test blocklist API validators', function () { url: server.url, path: path + '/user1', token: server.accessToken, - statusCodeExpected: 204 + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -369,7 +370,7 @@ describe('Test blocklist API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -378,7 +379,7 @@ describe('Test blocklist API validators', function () { url: server.url, token: userAccessToken, path, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) @@ -401,7 +402,7 @@ describe('Test blocklist API validators', function () { url: server.url, path, fields: { host: 'localhost:' + servers[1].port }, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -411,7 +412,7 @@ describe('Test blocklist API validators', function () { token: userAccessToken, path, fields: { host: 'localhost:' + servers[1].port }, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) @@ -421,7 +422,7 @@ describe('Test blocklist API validators', function () { token: server.accessToken, path, fields: { host: 'localhost:9003' }, - statusCodeExpected: 204 + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) }) @@ -431,7 +432,7 @@ describe('Test blocklist API validators', function () { token: server.accessToken, path, fields: { host: 'localhost:' + server.port }, - statusCodeExpected: 409 + statusCodeExpected: HttpStatusCode.CONFLICT_409 }) }) @@ -441,7 +442,7 @@ describe('Test blocklist API validators', function () { token: server.accessToken, path, fields: { host: 'localhost:' + servers[1].port }, - statusCodeExpected: 204 + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -451,7 +452,7 @@ describe('Test blocklist API validators', function () { await makeDeleteRequest({ url: server.url, path: path + '/localhost:' + servers[1].port, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -460,7 +461,7 @@ describe('Test blocklist API validators', function () { url: server.url, path: path + '/localhost:' + servers[1].port, token: userAccessToken, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) @@ -469,7 +470,7 @@ describe('Test blocklist API validators', function () { url: server.url, path: path + '/localhost:9004', token: server.accessToken, - statusCodeExpected: 404 + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) @@ -478,7 +479,7 @@ describe('Test blocklist API validators', function () { url: server.url, path: path + '/localhost:' + servers[1].port, token: server.accessToken, - statusCodeExpected: 204 + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) }) }) diff --git a/server/tests/api/check-params/bulk.ts b/server/tests/api/check-params/bulk.ts index 432858b33..07b920ba7 100644 --- a/server/tests/api/check-params/bulk.ts +++ b/server/tests/api/check-params/bulk.ts @@ -10,6 +10,7 @@ import { userLogin } from '../../../../shared/extra-utils' import { makePostBodyRequest } from '../../../../shared/extra-utils/requests/requests' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' describe('Test bulk API validators', function () { let server: ServerInfo @@ -37,7 +38,7 @@ describe('Test bulk API validators', function () { url: server.url, path, fields: { accountName: 'user1', scope: 'my-videos' }, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -47,7 +48,7 @@ describe('Test bulk API validators', function () { token: server.accessToken, path, fields: { accountName: 'user2', scope: 'my-videos' }, - statusCodeExpected: 404 + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) @@ -57,7 +58,7 @@ describe('Test bulk API validators', function () { token: server.accessToken, path, fields: { accountName: 'user1', scope: 'my-videoss' }, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -67,7 +68,7 @@ describe('Test bulk API validators', function () { token: userAccessToken, path, fields: { accountName: 'user1', scope: 'instance' }, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) @@ -77,7 +78,7 @@ describe('Test bulk API validators', function () { token: server.accessToken, path, fields: { accountName: 'user1', scope: 'instance' }, - statusCodeExpected: 204 + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) }) }) diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts index 42ac5e1f9..08576c3ae 100644 --- a/server/tests/api/check-params/config.ts +++ b/server/tests/api/check-params/config.ts @@ -16,6 +16,7 @@ import { setAccessTokensToServers, userLogin } from '../../../../shared/extra-utils' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' describe('Test config API validators', function () { const path = '/api/v1/config/custom' @@ -197,7 +198,7 @@ describe('Test config API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -206,7 +207,7 @@ describe('Test config API validators', function () { url: server.url, path, token: userAccessToken, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) }) @@ -217,7 +218,7 @@ describe('Test config API validators', function () { url: server.url, path, fields: updateParams, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -227,7 +228,7 @@ describe('Test config API validators', function () { path, fields: updateParams, token: userAccessToken, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) @@ -239,7 +240,7 @@ describe('Test config API validators', function () { path, fields: newUpdateParams, token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -255,7 +256,7 @@ describe('Test config API validators', function () { path, fields: newUpdateParams, token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -274,7 +275,7 @@ describe('Test config API validators', function () { path, fields: newUpdateParams, token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -295,7 +296,7 @@ describe('Test config API validators', function () { path, fields: newUpdateParams, token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -305,7 +306,7 @@ describe('Test config API validators', function () { path, fields: updateParams, token: server.accessToken, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) }) }) @@ -315,7 +316,7 @@ describe('Test config API validators', function () { await makeDeleteRequest({ url: server.url, path, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -324,7 +325,7 @@ describe('Test config API validators', function () { url: server.url, path, token: userAccessToken, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) }) diff --git a/server/tests/api/check-params/debug.ts b/server/tests/api/check-params/debug.ts index 5fac73485..37bf0f99b 100644 --- a/server/tests/api/check-params/debug.ts +++ b/server/tests/api/check-params/debug.ts @@ -11,6 +11,7 @@ import { userLogin } from '../../../../shared/extra-utils' import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' describe('Test debug API validators', function () { const path = '/api/v1/server/debug' @@ -40,7 +41,7 @@ describe('Test debug API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -49,7 +50,7 @@ describe('Test debug API validators', function () { url: server.url, path, token: userAccessToken, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) @@ -59,7 +60,7 @@ describe('Test debug API validators', function () { path, token: server.accessToken, query: { startDate: new Date().toISOString() }, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) }) }) diff --git a/server/tests/api/check-params/follows.ts b/server/tests/api/check-params/follows.ts index 2c2224a45..c03dd5c9c 100644 --- a/server/tests/api/check-params/follows.ts +++ b/server/tests/api/check-params/follows.ts @@ -17,6 +17,7 @@ import { checkBadSortPagination, checkBadStartPagination } from '../../../../shared/extra-utils/requests/check-api-params' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' describe('Test server follows API validators', function () { let server: ServerInfo @@ -52,7 +53,7 @@ describe('Test server follows API validators', function () { url: server.url, path, token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -62,7 +63,7 @@ describe('Test server follows API validators', function () { path, token: server.accessToken, fields: { hosts: 'localhost:9002' }, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -72,7 +73,7 @@ describe('Test server follows API validators', function () { path, fields: { hosts: [ 'localhost:9002', 'localhost:coucou' ] }, token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -82,7 +83,7 @@ describe('Test server follows API validators', function () { path, fields: { hosts: [ 'localhost:9002', 'http://localhost:9003' ] }, token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -92,7 +93,7 @@ describe('Test server follows API validators', function () { path, fields: { urls: [ 'localhost:9002', 'localhost:9002' ] }, token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -102,7 +103,7 @@ describe('Test server follows API validators', function () { path, fields: { hosts: [ 'localhost:9002' ] }, token: 'fake_token', - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -112,7 +113,7 @@ describe('Test server follows API validators', function () { path, fields: { hosts: [ 'localhost:9002' ] }, token: userAccessToken, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) }) @@ -156,7 +157,7 @@ describe('Test server follows API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: 200, + statusCodeExpected: HttpStatusCode.OK_200, query: { state: 'accepted', actorType: 'Application' @@ -205,7 +206,7 @@ describe('Test server follows API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: 200, + statusCodeExpected: HttpStatusCode.OK_200, query: { state: 'accepted' } @@ -221,7 +222,7 @@ describe('Test server follows API validators', function () { url: server.url, path: path + '/toto@localhost:9002', token: 'fake_token', - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -230,7 +231,7 @@ describe('Test server follows API validators', function () { url: server.url, path: path + '/toto@localhost:9002', token: userAccessToken, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) @@ -239,7 +240,7 @@ describe('Test server follows API validators', function () { url: server.url, path: path + '/toto', token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -248,7 +249,7 @@ describe('Test server follows API validators', function () { url: server.url, path: path + '/toto@localhost:9003', token: server.accessToken, - statusCodeExpected: 404 + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) }) @@ -261,7 +262,7 @@ describe('Test server follows API validators', function () { url: server.url, path: path + '/toto@localhost:9002/accept', token: 'fake_token', - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -270,7 +271,7 @@ describe('Test server follows API validators', function () { url: server.url, path: path + '/toto@localhost:9002/accept', token: userAccessToken, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) @@ -279,7 +280,7 @@ describe('Test server follows API validators', function () { url: server.url, path: path + '/toto/accept', token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -288,7 +289,7 @@ describe('Test server follows API validators', function () { url: server.url, path: path + '/toto@localhost:9003/accept', token: server.accessToken, - statusCodeExpected: 404 + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) }) @@ -301,7 +302,7 @@ describe('Test server follows API validators', function () { url: server.url, path: path + '/toto@localhost:9002/reject', token: 'fake_token', - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -310,7 +311,7 @@ describe('Test server follows API validators', function () { url: server.url, path: path + '/toto@localhost:9002/reject', token: userAccessToken, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) @@ -319,7 +320,7 @@ describe('Test server follows API validators', function () { url: server.url, path: path + '/toto/reject', token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -328,7 +329,7 @@ describe('Test server follows API validators', function () { url: server.url, path: path + '/toto@localhost:9003/reject', token: server.accessToken, - statusCodeExpected: 404 + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) }) @@ -341,7 +342,7 @@ describe('Test server follows API validators', function () { url: server.url, path: path + '/localhost:9002', token: 'fake_token', - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -350,7 +351,7 @@ describe('Test server follows API validators', function () { url: server.url, path: path + '/localhost:9002', token: userAccessToken, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) @@ -359,7 +360,7 @@ describe('Test server follows API validators', function () { url: server.url, path: path + '/example.com', token: server.accessToken, - statusCodeExpected: 404 + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) }) diff --git a/server/tests/api/check-params/jobs.ts b/server/tests/api/check-params/jobs.ts index 8f4af8d16..3c1d2049b 100644 --- a/server/tests/api/check-params/jobs.ts +++ b/server/tests/api/check-params/jobs.ts @@ -16,6 +16,7 @@ import { checkBadStartPagination } from '../../../../shared/extra-utils/requests/check-api-params' import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' describe('Test jobs API validators', function () { const path = '/api/v1/jobs/failed' @@ -76,7 +77,7 @@ describe('Test jobs API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -85,7 +86,7 @@ describe('Test jobs API validators', function () { url: server.url, path, token: userAccessToken, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) diff --git a/server/tests/api/check-params/live.ts b/server/tests/api/check-params/live.ts index 055f2f295..40dca908b 100644 --- a/server/tests/api/check-params/live.ts +++ b/server/tests/api/check-params/live.ts @@ -24,6 +24,7 @@ import { userLogin, waitUntilLiveStarts } from '../../../../shared/extra-utils' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' describe('Test video lives API validator', function () { const path = '/api/v1/videos/live' @@ -226,7 +227,7 @@ describe('Test video lives API validator', function () { path, token: server.accessToken, fields: baseCorrectParams, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) videoId = res.body.video.id @@ -244,7 +245,7 @@ describe('Test video lives API validator', function () { path, token: server.accessToken, fields: baseCorrectParams, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) @@ -263,7 +264,7 @@ describe('Test video lives API validator', function () { path, token: server.accessToken, fields, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) @@ -282,7 +283,7 @@ describe('Test video lives API validator', function () { path, token: server.accessToken, fields, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) }) @@ -299,7 +300,7 @@ describe('Test video lives API validator', function () { path, token: server.accessToken, fields: baseCorrectParams, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) @@ -317,7 +318,7 @@ describe('Test video lives API validator', function () { path, token: server.accessToken, fields: baseCorrectParams, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) }) @@ -325,27 +326,27 @@ describe('Test video lives API validator', function () { describe('When getting live information', function () { it('Should fail without access token', async function () { - await getLive(server.url, '', videoId, 401) + await getLive(server.url, '', videoId, HttpStatusCode.UNAUTHORIZED_401) }) it('Should fail with a bad access token', async function () { - await getLive(server.url, 'toto', videoId, 401) + await getLive(server.url, 'toto', videoId, HttpStatusCode.UNAUTHORIZED_401) }) it('Should fail with access token of another user', async function () { - await getLive(server.url, userAccessToken, videoId, 403) + await getLive(server.url, userAccessToken, videoId, HttpStatusCode.FORBIDDEN_403) }) it('Should fail with a bad video id', async function () { - await getLive(server.url, server.accessToken, 'toto', 400) + await getLive(server.url, server.accessToken, 'toto', HttpStatusCode.BAD_REQUEST_400) }) it('Should fail with an unknown video id', async function () { - await getLive(server.url, server.accessToken, 454555, 404) + await getLive(server.url, server.accessToken, 454555, HttpStatusCode.NOT_FOUND_404) }) it('Should fail with a non live video', async function () { - await getLive(server.url, server.accessToken, videoIdNotLive, 404) + await getLive(server.url, server.accessToken, videoIdNotLive, HttpStatusCode.NOT_FOUND_404) }) it('Should succeed with the correct params', async function () { @@ -356,33 +357,33 @@ describe('Test video lives API validator', function () { describe('When updating live information', async function () { it('Should fail without access token', async function () { - await updateLive(server.url, '', videoId, {}, 401) + await updateLive(server.url, '', videoId, {}, HttpStatusCode.UNAUTHORIZED_401) }) it('Should fail with a bad access token', async function () { - await updateLive(server.url, 'toto', videoId, {}, 401) + await updateLive(server.url, 'toto', videoId, {}, HttpStatusCode.UNAUTHORIZED_401) }) it('Should fail with access token of another user', async function () { - await updateLive(server.url, userAccessToken, videoId, {}, 403) + await updateLive(server.url, userAccessToken, videoId, {}, HttpStatusCode.FORBIDDEN_403) }) it('Should fail with a bad video id', async function () { - await updateLive(server.url, server.accessToken, 'toto', {}, 400) + await updateLive(server.url, server.accessToken, 'toto', {}, HttpStatusCode.BAD_REQUEST_400) }) it('Should fail with an unknown video id', async function () { - await updateLive(server.url, server.accessToken, 454555, {}, 404) + await updateLive(server.url, server.accessToken, 454555, {}, HttpStatusCode.NOT_FOUND_404) }) it('Should fail with a non live video', async function () { - await updateLive(server.url, server.accessToken, videoIdNotLive, {}, 404) + await updateLive(server.url, server.accessToken, videoIdNotLive, {}, HttpStatusCode.NOT_FOUND_404) }) it('Should fail with save replay and permanent live set to true', async function () { const fields = { saveReplay: true, permanentLive: true } - await updateLive(server.url, server.accessToken, videoId, fields, 400) + await updateLive(server.url, server.accessToken, videoId, fields, HttpStatusCode.BAD_REQUEST_400) }) it('Should succeed with the correct params', async function () { @@ -397,7 +398,7 @@ describe('Test video lives API validator', function () { } }) - await updateLive(server.url, server.accessToken, videoId, { saveReplay: true }, 403) + await updateLive(server.url, server.accessToken, videoId, { saveReplay: true }, HttpStatusCode.FORBIDDEN_403) }) it('Should fail to update a live if it has already started', async function () { @@ -409,7 +410,7 @@ describe('Test video lives API validator', function () { const command = sendRTMPStream(live.rtmpUrl, live.streamKey) await waitUntilLiveStarts(server.url, server.accessToken, videoId) - await updateLive(server.url, server.accessToken, videoId, {}, 400) + await updateLive(server.url, server.accessToken, videoId, {}, HttpStatusCode.BAD_REQUEST_400) await stopFfmpeg(command) }) diff --git a/server/tests/api/check-params/logs.ts b/server/tests/api/check-params/logs.ts index 719da54e6..dac1e6b98 100644 --- a/server/tests/api/check-params/logs.ts +++ b/server/tests/api/check-params/logs.ts @@ -11,6 +11,7 @@ import { userLogin } from '../../../../shared/extra-utils' import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' describe('Test logs API validators', function () { const path = '/api/v1/server/logs' @@ -40,7 +41,7 @@ describe('Test logs API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -49,7 +50,7 @@ describe('Test logs API validators', function () { url: server.url, path, token: userAccessToken, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) @@ -58,7 +59,7 @@ describe('Test logs API validators', function () { url: server.url, path, token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -68,7 +69,7 @@ describe('Test logs API validators', function () { path, token: server.accessToken, query: { startDate: 'toto' }, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -78,7 +79,7 @@ describe('Test logs API validators', function () { path, token: server.accessToken, query: { startDate: new Date().toISOString(), endDate: 'toto' }, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -88,7 +89,7 @@ describe('Test logs API validators', function () { path, token: server.accessToken, query: { startDate: new Date().toISOString(), level: 'toto' }, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -98,7 +99,7 @@ describe('Test logs API validators', function () { path, token: server.accessToken, query: { startDate: new Date().toISOString() }, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) }) }) diff --git a/server/tests/api/check-params/plugins.ts b/server/tests/api/check-params/plugins.ts index 07ded26ee..6e540bcbb 100644 --- a/server/tests/api/check-params/plugins.ts +++ b/server/tests/api/check-params/plugins.ts @@ -18,6 +18,7 @@ import { } from '../../../../shared/extra-utils' import { PluginType } from '../../../../shared/models/plugins/plugin.type' import { PeerTubePlugin } from '../../../../shared/models/plugins/peertube-plugin.model' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' describe('Test server plugins API validators', function () { let server: ServerInfo @@ -73,7 +74,7 @@ describe('Test server plugins API validators', function () { ] for (const p of paths) { - await makeGetRequest({ url: server.url, path: p, statusCodeExpected: 404 }) + await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) } }) @@ -81,7 +82,7 @@ describe('Test server plugins API validators', function () { await makeGetRequest({ url: server.url, path: '/themes/' + pluginName + '/' + npmVersion + '/static/images/chocobo.png', - statusCodeExpected: 404 + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) @@ -96,7 +97,7 @@ describe('Test server plugins API validators', function () { ] for (const p of paths) { - await makeGetRequest({ url: server.url, path: p, statusCodeExpected: 400 }) + await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) } }) @@ -110,14 +111,14 @@ describe('Test server plugins API validators', function () { ] for (const p of paths) { - await makeGetRequest({ url: server.url, path: p, statusCodeExpected: 400 }) + await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) } }) it('Should fail with an unknown auth name', async function () { const path = '/plugins/' + pluginName + '/' + npmVersion + '/auth/bad-auth' - await makeGetRequest({ url: server.url, path, statusCodeExpected: 404 }) + await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) it('Should fail with an unknown static file', async function () { @@ -129,7 +130,7 @@ describe('Test server plugins API validators', function () { ] for (const p of paths) { - await makeGetRequest({ url: server.url, path: p, statusCodeExpected: 404 }) + await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) } }) @@ -137,7 +138,7 @@ describe('Test server plugins API validators', function () { await makeGetRequest({ url: server.url, path: '/themes/' + themeName + '/' + themeVersion + '/css/assets/fake.css', - statusCodeExpected: 404 + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) @@ -151,11 +152,11 @@ describe('Test server plugins API validators', function () { ] for (const p of paths) { - await makeGetRequest({ url: server.url, path: p, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.OK_200 }) } const authPath = '/plugins/' + pluginName + '/' + npmVersion + '/auth/fake-auth' - await makeGetRequest({ url: server.url, path: authPath, statusCodeExpected: 302 }) + await makeGetRequest({ url: server.url, path: authPath, statusCodeExpected: HttpStatusCode.FOUND_302 }) }) }) @@ -173,7 +174,7 @@ describe('Test server plugins API validators', function () { path, token: 'fake_token', query: baseQuery, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -183,7 +184,7 @@ describe('Test server plugins API validators', function () { path, token: userAccessToken, query: baseQuery, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) @@ -227,7 +228,7 @@ describe('Test server plugins API validators', function () { path, token: server.accessToken, query: baseQuery, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) }) }) @@ -244,7 +245,7 @@ describe('Test server plugins API validators', function () { path, token: 'fake_token', query: baseQuery, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -254,7 +255,7 @@ describe('Test server plugins API validators', function () { path, token: userAccessToken, query: baseQuery, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) @@ -287,7 +288,7 @@ describe('Test server plugins API validators', function () { path, token: server.accessToken, query: baseQuery, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) }) }) @@ -301,7 +302,7 @@ describe('Test server plugins API validators', function () { url: server.url, path: path + suffix, token: 'fake_token', - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) } }) @@ -312,7 +313,7 @@ describe('Test server plugins API validators', function () { url: server.url, path: path + suffix, token: userAccessToken, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) } }) @@ -323,7 +324,7 @@ describe('Test server plugins API validators', function () { url: server.url, path: path + suffix, token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) } @@ -332,7 +333,7 @@ describe('Test server plugins API validators', function () { url: server.url, path: path + suffix, token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) } }) @@ -343,7 +344,7 @@ describe('Test server plugins API validators', function () { url: server.url, path: path + suffix, token: server.accessToken, - statusCodeExpected: 404 + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) } }) @@ -354,7 +355,7 @@ describe('Test server plugins API validators', function () { url: server.url, path: path + suffix, token: server.accessToken, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) } }) @@ -370,7 +371,7 @@ describe('Test server plugins API validators', function () { path: path + npmPlugin + '/settings', fields: { settings }, token: 'fake_token', - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -380,7 +381,7 @@ describe('Test server plugins API validators', function () { path: path + npmPlugin + '/settings', fields: { settings }, token: userAccessToken, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) @@ -390,7 +391,7 @@ describe('Test server plugins API validators', function () { path: path + 'toto/settings', fields: { settings }, token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) await makePutBodyRequest({ @@ -398,7 +399,7 @@ describe('Test server plugins API validators', function () { path: path + 'peertube-plugin-TOTO/settings', fields: { settings }, token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -408,7 +409,7 @@ describe('Test server plugins API validators', function () { path: path + 'peertube-plugin-toto/settings', fields: { settings }, token: server.accessToken, - statusCodeExpected: 404 + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) @@ -418,7 +419,7 @@ describe('Test server plugins API validators', function () { path: path + npmPlugin + '/settings', fields: { settings }, token: server.accessToken, - statusCodeExpected: 204 + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -433,7 +434,7 @@ describe('Test server plugins API validators', function () { path: path + suffix, fields: { npmName: npmPlugin }, token: 'fake_token', - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) } }) @@ -445,7 +446,7 @@ describe('Test server plugins API validators', function () { path: path + suffix, fields: { npmName: npmPlugin }, token: userAccessToken, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) } }) @@ -457,7 +458,7 @@ describe('Test server plugins API validators', function () { path: path + suffix, fields: { npmName: 'toto' }, token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) } @@ -467,7 +468,7 @@ describe('Test server plugins API validators', function () { path: path + suffix, fields: { npmName: 'peertube-plugin-TOTO' }, token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) } }) @@ -476,9 +477,9 @@ describe('Test server plugins API validators', function () { this.timeout(10000) const it = [ - { suffix: 'install', status: 200 }, - { suffix: 'update', status: 200 }, - { suffix: 'uninstall', status: 204 } + { suffix: 'install', status: HttpStatusCode.OK_200 }, + { suffix: 'update', status: HttpStatusCode.OK_200 }, + { suffix: 'uninstall', status: HttpStatusCode.NO_CONTENT_204 } ] for (const obj of it) { diff --git a/server/tests/api/check-params/redundancy.ts b/server/tests/api/check-params/redundancy.ts index cb0cc0854..3e04865ee 100644 --- a/server/tests/api/check-params/redundancy.ts +++ b/server/tests/api/check-params/redundancy.ts @@ -16,6 +16,7 @@ import { setAccessTokensToServers, uploadVideoAndGetId, userLogin, waitJobs, getVideoIdFromUUID } from '../../../../shared/extra-utils' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' describe('Test server redundancy API validators', function () { let servers: ServerInfo[] @@ -62,11 +63,11 @@ describe('Test server redundancy API validators', function () { }) it('Should fail with an invalid token', async function () { - await makeGetRequest({ url, path, token: 'fake_token', statusCodeExpected: 401 }) + await makeGetRequest({ url, path, token: 'fake_token', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail if the user is not an administrator', async function () { - await makeGetRequest({ url, path, token: userAccessToken, statusCodeExpected: 403 }) + await makeGetRequest({ url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) it('Should fail with a bad start pagination', async function () { @@ -90,7 +91,7 @@ describe('Test server redundancy API validators', function () { }) it('Should succeed with the correct params', async function () { - await makeGetRequest({ url, path, token, query: { target: 'my-videos' }, statusCodeExpected: 200 }) + await makeGetRequest({ url, path, token, query: { target: 'my-videos' }, statusCodeExpected: HttpStatusCode.OK_200 }) }) }) @@ -106,11 +107,11 @@ describe('Test server redundancy API validators', function () { }) it('Should fail with an invalid token', async function () { - await makePostBodyRequest({ url, path, token: 'fake_token', statusCodeExpected: 401 }) + await makePostBodyRequest({ url, path, token: 'fake_token', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail if the user is not an administrator', async function () { - await makePostBodyRequest({ url, path, token: userAccessToken, statusCodeExpected: 403 }) + await makePostBodyRequest({ url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) it('Should fail without a video id', async function () { @@ -122,7 +123,7 @@ describe('Test server redundancy API validators', function () { }) it('Should fail with a not found video id', async function () { - await makePostBodyRequest({ url, path, token, fields: { videoId: 6565 }, statusCodeExpected: 404 }) + await makePostBodyRequest({ url, path, token, fields: { videoId: 6565 }, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) it('Should fail with a local a video id', async function () { @@ -130,7 +131,7 @@ describe('Test server redundancy API validators', function () { }) it('Should succeed with the correct params', async function () { - await makePostBodyRequest({ url, path, token, fields: { videoId: videoIdRemote }, statusCodeExpected: 204 }) + await makePostBodyRequest({ url, path, token, fields: { videoId: videoIdRemote }, statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) }) it('Should fail if the video is already duplicated', async function () { @@ -138,7 +139,7 @@ describe('Test server redundancy API validators', function () { await waitJobs(servers) - await makePostBodyRequest({ url, path, token, fields: { videoId: videoIdRemote }, statusCodeExpected: 409 }) + await makePostBodyRequest({ url, path, token, fields: { videoId: videoIdRemote }, statusCodeExpected: HttpStatusCode.CONFLICT_409 }) }) }) @@ -154,11 +155,11 @@ describe('Test server redundancy API validators', function () { }) it('Should fail with an invalid token', async function () { - await makeDeleteRequest({ url, path: path + '1', token: 'fake_token', statusCodeExpected: 401 }) + await makeDeleteRequest({ url, path: path + '1', token: 'fake_token', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail if the user is not an administrator', async function () { - await makeDeleteRequest({ url, path: path + '1', token: userAccessToken, statusCodeExpected: 403 }) + await makeDeleteRequest({ url, path: path + '1', token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) it('Should fail with an incorrect video id', async function () { @@ -166,7 +167,7 @@ describe('Test server redundancy API validators', function () { }) it('Should fail with a not found video redundancy', async function () { - await makeDeleteRequest({ url, path: path + '454545', token, statusCodeExpected: 404 }) + await makeDeleteRequest({ url, path: path + '454545', token, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) }) @@ -179,7 +180,7 @@ describe('Test server redundancy API validators', function () { path: path + '/localhost:' + servers[1].port, fields: { redundancyAllowed: true }, token: 'fake_token', - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -189,7 +190,7 @@ describe('Test server redundancy API validators', function () { path: path + '/localhost:' + servers[1].port, fields: { redundancyAllowed: true }, token: userAccessToken, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) @@ -199,7 +200,7 @@ describe('Test server redundancy API validators', function () { path: path + '/example.com', fields: { redundancyAllowed: true }, token: servers[0].accessToken, - statusCodeExpected: 404 + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) @@ -209,7 +210,7 @@ describe('Test server redundancy API validators', function () { path: path + '/localhost:' + servers[1].port, fields: { blabla: true }, token: servers[0].accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -219,7 +220,7 @@ describe('Test server redundancy API validators', function () { path: path + '/localhost:' + servers[1].port, fields: { redundancyAllowed: true }, token: servers[0].accessToken, - statusCodeExpected: 204 + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) }) }) diff --git a/server/tests/api/check-params/search.ts b/server/tests/api/check-params/search.ts index 1a8a7235e..8378c3a89 100644 --- a/server/tests/api/check-params/search.ts +++ b/server/tests/api/check-params/search.ts @@ -15,6 +15,7 @@ import { checkBadSortPagination, checkBadStartPagination } from '../../../../shared/extra-utils/requests/check-api-params' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' function updateSearchIndex (server: ServerInfo, enabled: boolean, disableLocalSearch = false) { return updateCustomSubConfig(server.url, server.accessToken, { @@ -59,83 +60,83 @@ describe('Test videos API validator', function () { }) it('Should success with the correct parameters', async function () { - await makeGetRequest({ url: server.url, path, query, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 }) }) it('Should fail with an invalid category', async function () { const customQuery1 = immutableAssign(query, { categoryOneOf: [ 'aa', 'b' ] }) - await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 }) + await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) const customQuery2 = immutableAssign(query, { categoryOneOf: 'a' }) - await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 }) + await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should succeed with a valid category', async function () { const customQuery1 = immutableAssign(query, { categoryOneOf: [ 1, 7 ] }) - await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) const customQuery2 = immutableAssign(query, { categoryOneOf: 1 }) - await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) }) it('Should fail with an invalid licence', async function () { const customQuery1 = immutableAssign(query, { licenceOneOf: [ 'aa', 'b' ] }) - await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 }) + await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) const customQuery2 = immutableAssign(query, { licenceOneOf: 'a' }) - await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 }) + await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should succeed with a valid licence', async function () { const customQuery1 = immutableAssign(query, { licenceOneOf: [ 1, 2 ] }) - await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) const customQuery2 = immutableAssign(query, { licenceOneOf: 1 }) - await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) }) it('Should succeed with a valid language', async function () { const customQuery1 = immutableAssign(query, { languageOneOf: [ 'fr', 'en' ] }) - await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) const customQuery2 = immutableAssign(query, { languageOneOf: 'fr' }) - await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) }) it('Should succeed with valid tags', async function () { const customQuery1 = immutableAssign(query, { tagsOneOf: [ 'tag1', 'tag2' ] }) - await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) const customQuery2 = immutableAssign(query, { tagsOneOf: 'tag1' }) - await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) const customQuery3 = immutableAssign(query, { tagsAllOf: [ 'tag1', 'tag2' ] }) - await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.OK_200 }) const customQuery4 = immutableAssign(query, { tagsAllOf: 'tag1' }) - await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.OK_200 }) }) it('Should fail with invalid durations', async function () { const customQuery1 = immutableAssign(query, { durationMin: 'hello' }) - await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 }) + await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) const customQuery2 = immutableAssign(query, { durationMax: 'hello' }) - await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 }) + await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should fail with invalid dates', async function () { const customQuery1 = immutableAssign(query, { startDate: 'hello' }) - await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 }) + await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) const customQuery2 = immutableAssign(query, { endDate: 'hello' }) - await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 }) + await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) const customQuery3 = immutableAssign(query, { originallyPublishedStartDate: 'hello' }) - await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: 400 }) + await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) const customQuery4 = immutableAssign(query, { originallyPublishedEndDate: 'hello' }) - await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: 400 }) + await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) }) @@ -159,7 +160,7 @@ describe('Test videos API validator', function () { }) it('Should success with the correct parameters', async function () { - await makeGetRequest({ url: server.url, path, query, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 }) }) }) @@ -177,41 +178,41 @@ describe('Test videos API validator', function () { for (const path of paths) { { const customQuery = immutableAssign(query, { searchTarget: 'hello' }) - await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 400 }) + await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) } { const customQuery = immutableAssign(query, { searchTarget: undefined }) - await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) } { const customQuery = immutableAssign(query, { searchTarget: 'local' }) - await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) } { const customQuery = immutableAssign(query, { searchTarget: 'search-index' }) - await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 400 }) + await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) } await updateSearchIndex(server, true, true) { const customQuery = immutableAssign(query, { searchTarget: 'local' }) - await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 400 }) + await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) } { const customQuery = immutableAssign(query, { searchTarget: 'search-index' }) - await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) } await updateSearchIndex(server, true, false) { const customQuery = immutableAssign(query, { searchTarget: 'local' }) - await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) } await updateSearchIndex(server, false, false) diff --git a/server/tests/api/check-params/services.ts b/server/tests/api/check-params/services.ts index e57edd9e4..514e3da70 100644 --- a/server/tests/api/check-params/services.ts +++ b/server/tests/api/check-params/services.ts @@ -13,6 +13,7 @@ import { setDefaultVideoChannel } from '../../../../shared/extra-utils' import { VideoPlaylistPrivacy } from '@shared/models' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' describe('Test services API validators', function () { let server: ServerInfo @@ -66,7 +67,7 @@ describe('Test services API validators', function () { it('Should fail with an unknown element', async function () { const embedUrl = `http://localhost:${server.port}/videos/watch/88fc0165-d1f0-4a35-a51a-3b47f668689c` - await checkParamEmbed(server, embedUrl, 404) + await checkParamEmbed(server, embedUrl, HttpStatusCode.NOT_FOUND_404) }) it('Should fail with an invalid path', async function () { @@ -78,25 +79,25 @@ describe('Test services API validators', function () { it('Should fail with an invalid max height', async function () { const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` - await checkParamEmbed(server, embedUrl, 400, { maxheight: 'hello' }) + await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxheight: 'hello' }) }) it('Should fail with an invalid max width', async function () { const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` - await checkParamEmbed(server, embedUrl, 400, { maxwidth: 'hello' }) + await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxwidth: 'hello' }) }) it('Should fail with an invalid format', async function () { const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` - await checkParamEmbed(server, embedUrl, 400, { format: 'blabla' }) + await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { format: 'blabla' }) }) it('Should fail with a non supported format', async function () { const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` - await checkParamEmbed(server, embedUrl, 501, { format: 'xml' }) + await checkParamEmbed(server, embedUrl, HttpStatusCode.NOT_IMPLEMENTED_501, { format: 'xml' }) }) it('Should succeed with the correct params with a video', async function () { @@ -107,7 +108,7 @@ describe('Test services API validators', function () { maxwidth: 400 } - await checkParamEmbed(server, embedUrl, 200, query) + await checkParamEmbed(server, embedUrl, HttpStatusCode.OK_200, query) }) it('Should succeed with the correct params with a playlist', async function () { @@ -118,7 +119,7 @@ describe('Test services API validators', function () { maxwidth: 400 } - await checkParamEmbed(server, embedUrl, 200, query) + await checkParamEmbed(server, embedUrl, HttpStatusCode.OK_200, query) }) }) @@ -127,7 +128,7 @@ describe('Test services API validators', function () { }) }) -function checkParamEmbed (server: ServerInfo, embedUrl: string, statusCodeExpected = 400, query = {}) { +function checkParamEmbed (server: ServerInfo, embedUrl: string, statusCodeExpected = HttpStatusCode.BAD_REQUEST_400, query = {}) { const path = '/services/oembed' return makeGetRequest({ diff --git a/server/tests/api/check-params/user-notifications.ts b/server/tests/api/check-params/user-notifications.ts index 6fa0502be..05a78b0ad 100644 --- a/server/tests/api/check-params/user-notifications.ts +++ b/server/tests/api/check-params/user-notifications.ts @@ -20,6 +20,7 @@ import { checkBadStartPagination } from '../../../../shared/extra-utils/requests/check-api-params' import { UserNotificationSetting, UserNotificationSettingValue } from '../../../../shared/models/users' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' describe('Test user notifications API validators', function () { let server: ServerInfo @@ -57,7 +58,7 @@ describe('Test user notifications API validators', function () { unread: 'toto' }, token: server.accessToken, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) }) @@ -65,7 +66,7 @@ describe('Test user notifications API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -74,7 +75,7 @@ describe('Test user notifications API validators', function () { url: server.url, path, token: server.accessToken, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) }) }) @@ -90,7 +91,7 @@ describe('Test user notifications API validators', function () { ids: [ 'hello' ] }, token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) await makePostBodyRequest({ @@ -100,7 +101,7 @@ describe('Test user notifications API validators', function () { ids: [ ] }, token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) await makePostBodyRequest({ @@ -110,7 +111,7 @@ describe('Test user notifications API validators', function () { ids: 5 }, token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -121,7 +122,7 @@ describe('Test user notifications API validators', function () { fields: { ids: [ 5 ] }, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -133,7 +134,7 @@ describe('Test user notifications API validators', function () { ids: [ 5 ] }, token: server.accessToken, - statusCodeExpected: 204 + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -145,7 +146,7 @@ describe('Test user notifications API validators', function () { await makePostBodyRequest({ url: server.url, path, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -154,7 +155,7 @@ describe('Test user notifications API validators', function () { url: server.url, path, token: server.accessToken, - statusCodeExpected: 204 + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -184,7 +185,7 @@ describe('Test user notifications API validators', function () { path, token: server.accessToken, fields: { newVideoFromSubscription: UserNotificationSettingValue.WEB }, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -197,7 +198,7 @@ describe('Test user notifications API validators', function () { path, token: server.accessToken, fields, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) } @@ -209,7 +210,7 @@ describe('Test user notifications API validators', function () { path, fields, token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) } }) @@ -219,7 +220,7 @@ describe('Test user notifications API validators', function () { url: server.url, path, fields: correctFields, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -229,7 +230,7 @@ describe('Test user notifications API validators', function () { path, token: server.accessToken, fields: correctFields, - statusCodeExpected: 204 + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) }) }) diff --git a/server/tests/api/check-params/user-subscriptions.ts b/server/tests/api/check-params/user-subscriptions.ts index 1edba4d64..538201647 100644 --- a/server/tests/api/check-params/user-subscriptions.ts +++ b/server/tests/api/check-params/user-subscriptions.ts @@ -20,6 +20,7 @@ import { checkBadStartPagination } from '../../../../shared/extra-utils/requests/check-api-params' import { waitJobs } from '../../../../shared/extra-utils/server/jobs' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' describe('Test user subscriptions API validators', function () { const path = '/api/v1/users/me/subscriptions' @@ -60,7 +61,7 @@ describe('Test user subscriptions API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -69,7 +70,7 @@ describe('Test user subscriptions API validators', function () { url: server.url, path, token: userAccessToken, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) }) }) @@ -93,7 +94,7 @@ describe('Test user subscriptions API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -102,7 +103,7 @@ describe('Test user subscriptions API validators', function () { url: server.url, path, token: userAccessToken, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) }) }) @@ -113,7 +114,7 @@ describe('Test user subscriptions API validators', function () { url: server.url, path, fields: { uri: 'user1_channel@localhost:' + server.port }, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -123,7 +124,7 @@ describe('Test user subscriptions API validators', function () { path, token: server.accessToken, fields: { uri: 'root' }, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) await makePostBodyRequest({ @@ -131,7 +132,7 @@ describe('Test user subscriptions API validators', function () { path, token: server.accessToken, fields: { uri: 'root@' }, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) await makePostBodyRequest({ @@ -139,7 +140,7 @@ describe('Test user subscriptions API validators', function () { path, token: server.accessToken, fields: { uri: 'root@hello@' }, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -151,7 +152,7 @@ describe('Test user subscriptions API validators', function () { path, token: server.accessToken, fields: { uri: 'user1_channel@localhost:' + server.port }, - statusCodeExpected: 204 + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) await waitJobs([ server ]) @@ -163,7 +164,7 @@ describe('Test user subscriptions API validators', function () { await makeGetRequest({ url: server.url, path: path + '/user1_channel@localhost:' + server.port, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -172,21 +173,21 @@ describe('Test user subscriptions API validators', function () { url: server.url, path: path + '/root', token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) await makeGetRequest({ url: server.url, path: path + '/root@', token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) await makeGetRequest({ url: server.url, path: path + '/root@hello@', token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -195,7 +196,7 @@ describe('Test user subscriptions API validators', function () { url: server.url, path: path + '/root1@localhost:' + server.port, token: server.accessToken, - statusCodeExpected: 404 + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) @@ -204,7 +205,7 @@ describe('Test user subscriptions API validators', function () { url: server.url, path: path + '/user1_channel@localhost:' + server.port, token: server.accessToken, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) }) }) @@ -216,7 +217,7 @@ describe('Test user subscriptions API validators', function () { await makeGetRequest({ url: server.url, path: existPath, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -226,7 +227,7 @@ describe('Test user subscriptions API validators', function () { path: existPath, query: { uris: 'toto' }, token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) await makeGetRequest({ @@ -234,7 +235,7 @@ describe('Test user subscriptions API validators', function () { path: existPath, query: { 'uris[]': 1 }, token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -244,7 +245,7 @@ describe('Test user subscriptions API validators', function () { path: existPath, query: { 'uris[]': 'coucou@localhost:' + server.port }, token: server.accessToken, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) }) }) @@ -254,7 +255,7 @@ describe('Test user subscriptions API validators', function () { await makeDeleteRequest({ url: server.url, path: path + '/user1_channel@localhost:' + server.port, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -263,21 +264,21 @@ describe('Test user subscriptions API validators', function () { url: server.url, path: path + '/root', token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) await makeDeleteRequest({ url: server.url, path: path + '/root@', token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) await makeDeleteRequest({ url: server.url, path: path + '/root@hello@', token: server.accessToken, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -286,7 +287,7 @@ describe('Test user subscriptions API validators', function () { url: server.url, path: path + '/root1@localhost:' + server.port, token: server.accessToken, - statusCodeExpected: 404 + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) @@ -295,7 +296,7 @@ describe('Test user subscriptions API validators', function () { url: server.url, path: path + '/user1_channel@localhost:' + server.port, token: server.accessToken, - statusCodeExpected: 204 + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) }) }) diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index da7dc9704..21ace36aa 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts @@ -43,6 +43,7 @@ import { waitJobs } from '../../../../shared/extra-utils/server/jobs' import { getGoodVideoUrl, getMagnetURI, getMyVideoImports, importVideo } from '../../../../shared/extra-utils/videos/video-imports' import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' import { VideoPrivacy } from '../../../../shared/models/videos' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' describe('Test users API validators', function () { const path = '/api/v1/users/' @@ -160,7 +161,7 @@ describe('Test users API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -169,7 +170,7 @@ describe('Test users API validators', function () { url: server.url, path, token: userAccessToken, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) }) @@ -263,7 +264,7 @@ describe('Test users API validators', function () { path: path, token: server.accessToken, fields, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) }) @@ -279,20 +280,32 @@ describe('Test users API validators', function () { path, token: 'super token', fields: baseCorrectParams, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail if we add a user with the same username', async function () { const fields = immutableAssign(baseCorrectParams, { username: 'user1' }) - await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 }) + await makePostBodyRequest({ + url: server.url, + path, + token: server.accessToken, + fields, + statusCodeExpected: HttpStatusCode.CONFLICT_409 + }) }) it('Should fail if we add a user with the same email', async function () { const fields = immutableAssign(baseCorrectParams, { email: 'user1@example.com' }) - await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 }) + await makePostBodyRequest({ + url: server.url, + path, + token: server.accessToken, + fields, + statusCodeExpected: HttpStatusCode.CONFLICT_409 + }) }) it('Should fail without a videoQuota', async function () { @@ -339,7 +352,7 @@ describe('Test users API validators', function () { path, token: server.accessToken, fields, - statusCodeExpected: 409 + statusCodeExpected: HttpStatusCode.CONFLICT_409 }) }) @@ -352,7 +365,7 @@ describe('Test users API validators', function () { path, token: moderatorAccessToken, fields, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) } }) @@ -365,7 +378,7 @@ describe('Test users API validators', function () { path, token: moderatorAccessToken, fields, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) }) @@ -375,7 +388,7 @@ describe('Test users API validators', function () { path, token: server.accessToken, fields: baseCorrectParams, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) }) @@ -392,7 +405,7 @@ describe('Test users API validators', function () { password: 'my super password', videoQuota: 42000000 } - await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 }) + await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) }) @@ -438,7 +451,13 @@ describe('Test users API validators', function () { password: 'super'.repeat(61) } - await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 401 }) + await makePutBodyRequest({ + url: server.url, + path: path + 'me', + token: userAccessToken, + fields, + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + }) }) it('Should fail with an invalid NSFW policy attribute', async function () { @@ -479,7 +498,13 @@ describe('Test users API validators', function () { password: 'my super password' } - await makePutBodyRequest({ url: server.url, path: path + 'me', token: 'super token', fields, statusCodeExpected: 401 }) + await makePutBodyRequest({ + url: server.url, + path: path + 'me', + token: 'super token', + fields, + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + }) }) it('Should fail with a too long description', async function () { @@ -551,7 +576,13 @@ describe('Test users API validators', function () { noWelcomeModal: true } - await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 }) + await makePutBodyRequest({ + url: server.url, + path: path + 'me', + token: userAccessToken, + fields, + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + }) }) it('Should succeed without password change with the correct params', async function () { @@ -560,7 +591,13 @@ describe('Test users API validators', function () { autoPlayVideo: false } - await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 }) + await makePutBodyRequest({ + url: server.url, + path: path + 'me', + token: userAccessToken, + fields, + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + }) }) }) @@ -591,7 +628,7 @@ describe('Test users API validators', function () { path: path + '/me/avatar/pick', fields, attaches, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -606,7 +643,7 @@ describe('Test users API validators', function () { token: server.accessToken, fields, attaches, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) }) }) @@ -614,11 +651,11 @@ describe('Test users API validators', function () { describe('When managing my scoped tokens', function () { it('Should fail to get my scoped tokens with an non authenticated user', async function () { - await getUserScopedTokens(server.url, null, 401) + await getUserScopedTokens(server.url, null, HttpStatusCode.UNAUTHORIZED_401) }) it('Should fail to get my scoped tokens with a bad token', async function () { - await getUserScopedTokens(server.url, 'bad', 401) + await getUserScopedTokens(server.url, 'bad', HttpStatusCode.UNAUTHORIZED_401) }) @@ -627,11 +664,11 @@ describe('Test users API validators', function () { }) it('Should fail to renew my scoped tokens with an non authenticated user', async function () { - await renewUserScopedTokens(server.url, null, 401) + await renewUserScopedTokens(server.url, null, HttpStatusCode.UNAUTHORIZED_401) }) it('Should fail to renew my scoped tokens with a bad token', async function () { - await renewUserScopedTokens(server.url, 'bad', 401) + await renewUserScopedTokens(server.url, 'bad', HttpStatusCode.UNAUTHORIZED_401) }) it('Should succeed to renew my scoped tokens', async function () { @@ -642,15 +679,20 @@ describe('Test users API validators', function () { describe('When getting a user', function () { it('Should fail with an non authenticated user', async function () { - await makeGetRequest({ url: server.url, path: path + userId, token: 'super token', statusCodeExpected: 401 }) + await makeGetRequest({ + url: server.url, + path: path + userId, + token: 'super token', + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + }) }) it('Should fail with a non admin user', async function () { - await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 403 }) + await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) it('Should succeed with the correct params', async function () { - await makeGetRequest({ url: server.url, path: path + userId, token: server.accessToken, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path: path + userId, token: server.accessToken, statusCodeExpected: HttpStatusCode.OK_200 }) }) }) @@ -711,7 +753,13 @@ describe('Test users API validators', function () { videoQuota: 42 } - await makePutBodyRequest({ url: server.url, path: path + userId, token: 'super token', fields, statusCodeExpected: 401 }) + await makePutBodyRequest({ + url: server.url, + path: path + userId, + token: 'super token', + fields, + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + }) }) it('Should fail when updating root role', async function () { @@ -738,7 +786,7 @@ describe('Test users API validators', function () { path: path + moderatorId, token: moderatorAccessToken, fields, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) @@ -752,7 +800,7 @@ describe('Test users API validators', function () { path: path + userId, token: moderatorAccessToken, fields, - statusCodeExpected: 204 + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) }) @@ -764,13 +812,19 @@ describe('Test users API validators', function () { role: UserRole.USER } - await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields, statusCodeExpected: 204 }) + await makePutBodyRequest({ + url: server.url, + path: path + userId, + token: server.accessToken, + fields, + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + }) }) }) describe('When getting my information', function () { it('Should fail with a non authenticated user', async function () { - await getMyUserInformation(server.url, 'fake_token', 401) + await getMyUserInformation(server.url, 'fake_token', HttpStatusCode.UNAUTHORIZED_401) }) it('Should success with the correct parameters', async function () { @@ -780,15 +834,15 @@ describe('Test users API validators', function () { describe('When getting my video rating', function () { it('Should fail with a non authenticated user', async function () { - await getMyUserVideoRating(server.url, 'fake_token', videoId, 401) + await getMyUserVideoRating(server.url, 'fake_token', videoId, HttpStatusCode.UNAUTHORIZED_401) }) it('Should fail with an incorrect video uuid', async function () { - await getMyUserVideoRating(server.url, server.accessToken, 'blabla', 400) + await getMyUserVideoRating(server.url, server.accessToken, 'blabla', HttpStatusCode.BAD_REQUEST_400) }) it('Should fail with an unknown video', async function () { - await getMyUserVideoRating(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404) + await getMyUserVideoRating(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404) }) it('Should succeed with the correct parameters', async function () { @@ -812,51 +866,57 @@ describe('Test users API validators', function () { }) it('Should fail with a unauthenticated user', async function () { - await makeGetRequest({ url: server.url, path, statusCodeExpected: 401 }) + await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with a another user', async function () { - await makeGetRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 403 }) + await makeGetRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) it('Should fail with a bad type', async function () { - await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { rating: 'toto ' }, statusCodeExpected: 400 }) + await makeGetRequest({ + url: server.url, + path, + token: userAccessToken, + query: { rating: 'toto ' }, + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + }) }) it('Should succeed with the correct params', async function () { - await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.OK_200 }) }) }) describe('When blocking/unblocking/removing user', function () { it('Should fail with an incorrect id', async function () { - await removeUser(server.url, 'blabla', server.accessToken, 400) - await blockUser(server.url, 'blabla', server.accessToken, 400) - await unblockUser(server.url, 'blabla', server.accessToken, 400) + await removeUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400) + await blockUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400) + await unblockUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400) }) it('Should fail with the root user', async function () { - await removeUser(server.url, rootId, server.accessToken, 400) - await blockUser(server.url, rootId, server.accessToken, 400) - await unblockUser(server.url, rootId, server.accessToken, 400) + await removeUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400) + await blockUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400) + await unblockUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400) }) it('Should return 404 with a non existing id', async function () { - await removeUser(server.url, 4545454, server.accessToken, 404) - await blockUser(server.url, 4545454, server.accessToken, 404) - await unblockUser(server.url, 4545454, server.accessToken, 404) + await removeUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404) + await blockUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404) + await unblockUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404) }) it('Should fail with a non admin user', async function () { - await removeUser(server.url, userId, userAccessToken, 403) - await blockUser(server.url, userId, userAccessToken, 403) - await unblockUser(server.url, userId, userAccessToken, 403) + await removeUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403) + await blockUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403) + await unblockUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403) }) it('Should fail on a moderator with a moderator', async function () { - await removeUser(server.url, moderatorId, moderatorAccessToken, 403) - await blockUser(server.url, moderatorId, moderatorAccessToken, 403) - await unblockUser(server.url, moderatorId, moderatorAccessToken, 403) + await removeUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403) + await blockUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403) + await unblockUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403) }) it('Should succeed on a user with a moderator', async function () { @@ -867,7 +927,7 @@ describe('Test users API validators', function () { describe('When deleting our account', function () { it('Should fail with with the root account', async function () { - await deleteMe(server.url, server.accessToken, 400) + await deleteMe(server.url, server.accessToken, HttpStatusCode.BAD_REQUEST_400) }) }) @@ -930,7 +990,7 @@ describe('Test users API validators', function () { path: registrationPath, token: server.accessToken, fields, - statusCodeExpected: 409 + statusCodeExpected: HttpStatusCode.CONFLICT_409 }) }) @@ -942,7 +1002,7 @@ describe('Test users API validators', function () { path: registrationPath, token: server.accessToken, fields, - statusCodeExpected: 409 + statusCodeExpected: HttpStatusCode.CONFLICT_409 }) }) @@ -954,7 +1014,7 @@ describe('Test users API validators', function () { path: registrationPath, token: server.accessToken, fields, - statusCodeExpected: 409 + statusCodeExpected: HttpStatusCode.CONFLICT_409 }) }) @@ -989,7 +1049,13 @@ describe('Test users API validators', function () { const fields = immutableAssign(baseCorrectParams, { channel: { name: 'existing_channel', displayName: 'toto' } }) - await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields, statusCodeExpected: 409 }) + await makePostBodyRequest({ + url: server.url, + path: registrationPath, + token: server.accessToken, + fields, + statusCodeExpected: HttpStatusCode.CONFLICT_409 + }) }) it('Should succeed with the correct params', async function () { @@ -1000,7 +1066,7 @@ describe('Test users API validators', function () { path: registrationPath, token: server.accessToken, fields: fields, - statusCodeExpected: 204 + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) }) @@ -1016,14 +1082,14 @@ describe('Test users API validators', function () { path: registrationPath, token: serverWithRegistrationDisabled.accessToken, fields, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) }) describe('When registering multiple users on a server with users limit', function () { it('Should fail when after 3 registrations', async function () { - await registerUser(server.url, 'user42', 'super password', 403) + await registerUser(server.url, 'user42', 'super password', HttpStatusCode.FORBIDDEN_403) }) }) @@ -1036,7 +1102,7 @@ describe('Test users API validators', function () { videoQuota: 42 }) - await uploadVideo(server.url, server.accessToken, {}, 403) + await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.FORBIDDEN_403) }) it('Should fail with a registered user having too many videos', async function () { @@ -1054,7 +1120,7 @@ describe('Test users API validators', function () { await uploadVideo(server.url, userAccessToken, videoAttributes) await uploadVideo(server.url, userAccessToken, videoAttributes) await uploadVideo(server.url, userAccessToken, videoAttributes) - await uploadVideo(server.url, userAccessToken, videoAttributes, 403) + await uploadVideo(server.url, userAccessToken, videoAttributes, HttpStatusCode.FORBIDDEN_403) }) it('Should fail to import with HTTP/Torrent/magnet', async function () { @@ -1093,7 +1159,7 @@ describe('Test users API validators', function () { videoQuotaDaily: 42 }) - await uploadVideo(server.url, server.accessToken, {}, 403) + await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.FORBIDDEN_403) }) }) @@ -1107,7 +1173,7 @@ describe('Test users API validators', function () { videoQuotaDaily: 1024 * 1024 * 1024 }) - await uploadVideo(server.url, server.accessToken, {}, 403) + await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.FORBIDDEN_403) }) it('Should fail if exceeding daily quota', async function () { @@ -1119,7 +1185,7 @@ describe('Test users API validators', function () { videoQuotaDaily: 42 }) - await uploadVideo(server.url, server.accessToken, {}, 403) + await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.FORBIDDEN_403) }) }) @@ -1141,7 +1207,13 @@ describe('Test users API validators', function () { it('Should success with the correct params', async function () { const fields = { email: 'admin@example.com' } - await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 }) + await makePostBodyRequest({ + url: server.url, + path, + token: server.accessToken, + fields, + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + }) }) }) @@ -1163,7 +1235,13 @@ describe('Test users API validators', function () { it('Should succeed with the correct params', async function () { const fields = { email: 'admin@example.com' } - await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 }) + await makePostBodyRequest({ + url: server.url, + path, + token: server.accessToken, + fields, + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + }) }) }) diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts index 145f43980..3d4837d58 100644 --- a/server/tests/api/check-params/video-blacklist.ts +++ b/server/tests/api/check-params/video-blacklist.ts @@ -26,6 +26,7 @@ import { } from '../../../../shared/extra-utils/requests/check-api-params' import { VideoBlacklistType, VideoDetails } from '../../../../shared/models/videos' import { expect } from 'chai' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' describe('Test video blacklist API validators', function () { let servers: ServerInfo[] @@ -94,13 +95,19 @@ describe('Test video blacklist API validators', function () { it('Should fail with a non authenticated user', async function () { const path = basePath + servers[0].video + '/blacklist' const fields = {} - await makePostBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: 401 }) + await makePostBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with a non admin user', async function () { const path = basePath + servers[0].video + '/blacklist' const fields = {} - await makePostBodyRequest({ url: servers[0].url, path, token: userAccessToken2, fields, statusCodeExpected: 403 }) + await makePostBodyRequest({ + url: servers[0].url, + path, + token: userAccessToken2, + fields, + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + }) }) it('Should fail with an invalid reason', async function () { @@ -114,14 +121,26 @@ describe('Test video blacklist API validators', function () { const path = basePath + remoteVideoUUID + '/blacklist' const fields = { unfederate: true } - await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 409 }) + await makePostBodyRequest({ + url: servers[0].url, + path, + token: servers[0].accessToken, + fields, + statusCodeExpected: HttpStatusCode.CONFLICT_409 + }) }) it('Should succeed with the correct params', async function () { const path = basePath + servers[0].video.uuid + '/blacklist' const fields = {} - await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 204 }) + await makePostBodyRequest({ + url: servers[0].url, + path, + token: servers[0].accessToken, + fields, + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + }) }) }) @@ -137,19 +156,31 @@ describe('Test video blacklist API validators', function () { it('Should fail with a video not blacklisted', async function () { const path = '/api/v1/videos/' + notBlacklistedVideoId + '/blacklist' const fields = {} - await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 404 }) + await makePutBodyRequest({ + url: servers[0].url, + path, + token: servers[0].accessToken, + fields, + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + }) }) it('Should fail with a non authenticated user', async function () { const path = basePath + servers[0].video + '/blacklist' const fields = {} - await makePutBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: 401 }) + await makePutBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with a non admin user', async function () { const path = basePath + servers[0].video + '/blacklist' const fields = {} - await makePutBodyRequest({ url: servers[0].url, path, token: userAccessToken2, fields, statusCodeExpected: 403 }) + await makePutBodyRequest({ + url: servers[0].url, + path, + token: userAccessToken2, + fields, + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + }) }) it('Should fail with an invalid reason', async function () { @@ -163,29 +194,35 @@ describe('Test video blacklist API validators', function () { const path = basePath + servers[0].video.uuid + '/blacklist' const fields = { reason: 'hello' } - await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 204 }) + await makePutBodyRequest({ + url: servers[0].url, + path, + token: servers[0].accessToken, + fields, + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + }) }) }) describe('When getting blacklisted video', function () { it('Should fail with a non authenticated user', async function () { - await getVideo(servers[0].url, servers[0].video.uuid, 401) + await getVideo(servers[0].url, servers[0].video.uuid, HttpStatusCode.UNAUTHORIZED_401) }) it('Should fail with another user', async function () { - await getVideoWithToken(servers[0].url, userAccessToken2, servers[0].video.uuid, 403) + await getVideoWithToken(servers[0].url, userAccessToken2, servers[0].video.uuid, HttpStatusCode.FORBIDDEN_403) }) it('Should succeed with the owner authenticated user', async function () { - const res = await getVideoWithToken(servers[0].url, userAccessToken1, servers[0].video.uuid, 200) + const res = await getVideoWithToken(servers[0].url, userAccessToken1, servers[0].video.uuid, HttpStatusCode.OK_200) const video: VideoDetails = res.body expect(video.blacklisted).to.be.true }) it('Should succeed with an admin', async function () { - const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, servers[0].video.uuid, 200) + const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, servers[0].video.uuid, HttpStatusCode.OK_200) const video: VideoDetails = res.body expect(video.blacklisted).to.be.true @@ -194,24 +231,24 @@ describe('Test video blacklist API validators', function () { describe('When removing a video in blacklist', function () { it('Should fail with a non authenticated user', async function () { - await removeVideoFromBlacklist(servers[0].url, 'fake token', servers[0].video.uuid, 401) + await removeVideoFromBlacklist(servers[0].url, 'fake token', servers[0].video.uuid, HttpStatusCode.UNAUTHORIZED_401) }) it('Should fail with a non admin user', async function () { - await removeVideoFromBlacklist(servers[0].url, userAccessToken2, servers[0].video.uuid, 403) + await removeVideoFromBlacklist(servers[0].url, userAccessToken2, servers[0].video.uuid, HttpStatusCode.FORBIDDEN_403) }) it('Should fail with an incorrect id', async function () { - await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, 'hello', 400) + await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400) }) it('Should fail with a not blacklisted video', async function () { // The video was not added to the blacklist so it should fail - await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, notBlacklistedVideoId, 404) + await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, notBlacklistedVideoId, HttpStatusCode.NOT_FOUND_404) }) it('Should succeed with the correct params', async function () { - await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, servers[0].video.uuid, 204) + await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, servers[0].video.uuid, HttpStatusCode.NO_CONTENT_204) }) }) @@ -219,11 +256,11 @@ describe('Test video blacklist API validators', function () { const basePath = '/api/v1/videos/blacklist/' it('Should fail with a non authenticated user', async function () { - await getBlacklistedVideosList({ url: servers[0].url, token: 'fake token', specialStatus: 401 }) + await getBlacklistedVideosList({ url: servers[0].url, token: 'fake token', specialStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with a non admin user', async function () { - await getBlacklistedVideosList({ url: servers[0].url, token: userAccessToken2, specialStatus: 403 }) + await getBlacklistedVideosList({ url: servers[0].url, token: userAccessToken2, specialStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should fail with a bad start pagination', async function () { @@ -239,7 +276,12 @@ describe('Test video blacklist API validators', function () { }) it('Should fail with an invalid type', async function () { - await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, type: 0, specialStatus: 400 }) + await getBlacklistedVideosList({ + url: servers[0].url, + token: servers[0].accessToken, + type: 0, + specialStatus: HttpStatusCode.BAD_REQUEST_400 + }) }) it('Should succeed with the correct parameters', async function () { diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts index a5f5c3322..e42e8db81 100644 --- a/server/tests/api/check-params/video-captions.ts +++ b/server/tests/api/check-params/video-captions.ts @@ -15,6 +15,7 @@ import { } from '../../../../shared/extra-utils' import { join } from 'path' import { createVideoCaption } from '../../../../shared/extra-utils/videos/video-captions' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' describe('Test video captions API validator', function () { const path = '/api/v1/videos/' @@ -107,7 +108,7 @@ describe('Test video captions API validator', function () { path: captionPath, fields, attaches, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -120,7 +121,7 @@ describe('Test video captions API validator', function () { token: 'blabla', fields, attaches, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -138,7 +139,7 @@ describe('Test video captions API validator', function () { // token: server.accessToken, // fields, // attaches, - // statusCodeExpected: 400 + // statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 // }) // }) @@ -151,7 +152,7 @@ describe('Test video captions API validator', function () { // videoId: videoUUID, // fixture: 'subtitle-bad.txt', // mimeType: 'application/octet-stream', - // statusCodeExpected: 400 + // statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 // }) // }) @@ -180,7 +181,7 @@ describe('Test video captions API validator', function () { // token: server.accessToken, // fields, // attaches, - // statusCodeExpected: 500 + // statusCodeExpected: HttpStatusCode.INTERNAL_SERVER_ERROR_500 // }) // }) @@ -193,7 +194,7 @@ describe('Test video captions API validator', function () { token: server.accessToken, fields, attaches, - statusCodeExpected: 204 + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -204,11 +205,15 @@ describe('Test video captions API validator', function () { }) it('Should fail with an unknown id', async function () { - await makeGetRequest({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions', statusCodeExpected: 404 }) + await makeGetRequest({ + url: server.url, + path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions', + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + }) }) it('Should success with the correct parameters', async function () { - await makeGetRequest({ url: server.url, path: path + videoUUID + '/captions', statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path: path + videoUUID + '/captions', statusCodeExpected: HttpStatusCode.OK_200 }) }) }) @@ -226,7 +231,7 @@ describe('Test video captions API validator', function () { url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr', token: server.accessToken, - statusCodeExpected: 404 + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) @@ -250,22 +255,32 @@ describe('Test video captions API validator', function () { it('Should fail without access token', async function () { const captionPath = path + videoUUID + '/captions/fr' - await makeDeleteRequest({ url: server.url, path: captionPath, statusCodeExpected: 401 }) + await makeDeleteRequest({ url: server.url, path: captionPath, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with a bad access token', async function () { const captionPath = path + videoUUID + '/captions/fr' - await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', statusCodeExpected: 401 }) + await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with another user', async function () { const captionPath = path + videoUUID + '/captions/fr' - await makeDeleteRequest({ url: server.url, path: captionPath, token: userAccessToken, statusCodeExpected: 403 }) + await makeDeleteRequest({ + url: server.url, + path: captionPath, + token: userAccessToken, + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + }) }) it('Should success with the correct parameters', async function () { const captionPath = path + videoUUID + '/captions/fr' - await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken, statusCodeExpected: 204 }) + await makeDeleteRequest({ + url: server.url, + path: captionPath, + token: server.accessToken, + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + }) }) }) diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts index 2795ad7d5..0dd436426 100644 --- a/server/tests/api/check-params/video-channels.ts +++ b/server/tests/api/check-params/video-channels.ts @@ -25,6 +25,7 @@ import { } from '../../../../shared/extra-utils/requests/check-api-params' import { join } from 'path' import { VideoChannelUpdate } from '../../../../shared/models/videos' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' const expect = chai.expect @@ -83,14 +84,14 @@ describe('Test video channels API validator', function () { }) it('Should fail with a unknown account', async function () { - await getAccountVideoChannelsList({ url: server.url, accountName: 'unknown', specialStatus: 404 }) + await getAccountVideoChannelsList({ url: server.url, accountName: 'unknown', specialStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should succeed with the correct parameters', async function () { await makeGetRequest({ url: server.url, path: accountChannelPath, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) }) }) @@ -109,7 +110,7 @@ describe('Test video channels API validator', function () { path: videoChannelPath, token: 'none', fields: baseCorrectParams, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -154,7 +155,7 @@ describe('Test video channels API validator', function () { path: videoChannelPath, token: server.accessToken, fields: baseCorrectParams, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) }) @@ -164,7 +165,7 @@ describe('Test video channels API validator', function () { path: videoChannelPath, token: server.accessToken, fields: baseCorrectParams, - statusCodeExpected: 409 + statusCodeExpected: HttpStatusCode.CONFLICT_409 }) }) }) @@ -188,7 +189,7 @@ describe('Test video channels API validator', function () { path, token: 'hi', fields: baseCorrectParams, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -198,7 +199,7 @@ describe('Test video channels API validator', function () { path, token: accessTokenUser, fields: baseCorrectParams, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) @@ -228,7 +229,7 @@ describe('Test video channels API validator', function () { path, token: server.accessToken, fields: baseCorrectParams, - statusCodeExpected: 204 + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -266,7 +267,7 @@ describe('Test video channels API validator', function () { path: path + '/avatar/pick', fields, attaches, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -281,7 +282,7 @@ describe('Test video channels API validator', function () { token: server.accessToken, fields, attaches, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) }) }) @@ -291,7 +292,7 @@ describe('Test video channels API validator', function () { const res = await makeGetRequest({ url: server.url, path: videoChannelPath, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) expect(res.body.data).to.be.an('array') @@ -301,7 +302,7 @@ describe('Test video channels API validator', function () { await makeGetRequest({ url: server.url, path: videoChannelPath + '/super_channel2', - statusCodeExpected: 404 + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) @@ -309,22 +310,22 @@ describe('Test video channels API validator', function () { await makeGetRequest({ url: server.url, path: videoChannelPath + '/super_channel', - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) }) }) describe('When deleting a video channel', function () { it('Should fail with a non authenticated user', async function () { - await deleteVideoChannel(server.url, 'coucou', 'super_channel', 401) + await deleteVideoChannel(server.url, 'coucou', 'super_channel', HttpStatusCode.UNAUTHORIZED_401) }) it('Should fail with another authenticated user', async function () { - await deleteVideoChannel(server.url, accessTokenUser, 'super_channel', 403) + await deleteVideoChannel(server.url, accessTokenUser, 'super_channel', HttpStatusCode.FORBIDDEN_403) }) it('Should fail with an unknown video channel id', async function () { - await deleteVideoChannel(server.url, server.accessToken, 'super_channel2', 404) + await deleteVideoChannel(server.url, server.accessToken, 'super_channel2', HttpStatusCode.NOT_FOUND_404) }) it('Should succeed with the correct parameters', async function () { @@ -332,7 +333,7 @@ describe('Test video channels API validator', function () { }) it('Should fail to delete the last user video channel', async function () { - await deleteVideoChannel(server.url, server.accessToken, 'root_channel', 409) + await deleteVideoChannel(server.url, server.accessToken, 'root_channel', HttpStatusCode.CONFLICT_409) }) }) diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts index 662d4a70d..659a10c41 100644 --- a/server/tests/api/check-params/video-comments.ts +++ b/server/tests/api/check-params/video-comments.ts @@ -20,6 +20,7 @@ import { checkBadStartPagination } from '../../../../shared/extra-utils/requests/check-api-params' import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' const expect = chai.expect @@ -83,7 +84,7 @@ describe('Test video comments API validator', function () { await makeGetRequest({ url: server.url, path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads', - statusCodeExpected: 404 + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) }) @@ -93,7 +94,7 @@ describe('Test video comments API validator', function () { await makeGetRequest({ url: server.url, path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads/' + commentId, - statusCodeExpected: 404 + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) @@ -101,7 +102,7 @@ describe('Test video comments API validator', function () { await makeGetRequest({ url: server.url, path: '/api/v1/videos/' + videoUUID + '/comment-threads/156', - statusCodeExpected: 404 + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) @@ -109,7 +110,7 @@ describe('Test video comments API validator', function () { await makeGetRequest({ url: server.url, path: '/api/v1/videos/' + videoUUID + '/comment-threads/' + commentId, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) }) }) @@ -120,7 +121,13 @@ describe('Test video comments API validator', function () { const fields = { text: 'text' } - await makePostBodyRequest({ url: server.url, path: pathThread, token: 'none', fields, statusCodeExpected: 401 }) + await makePostBodyRequest({ + url: server.url, + path: pathThread, + token: 'none', + fields, + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + }) }) it('Should fail with nothing', async function () { @@ -147,14 +154,26 @@ describe('Test video comments API validator', function () { const fields = { text: 'super comment' } - await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 }) + await makePostBodyRequest({ + url: server.url, + path, + token: server.accessToken, + fields, + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + }) }) it('Should succeed with the correct parameters', async function () { const fields = { text: 'super comment' } - await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields, statusCodeExpected: 200 }) + await makePostBodyRequest({ + url: server.url, + path: pathThread, + token: server.accessToken, + fields, + statusCodeExpected: HttpStatusCode.OK_200 + }) }) }) @@ -163,7 +182,13 @@ describe('Test video comments API validator', function () { const fields = { text: 'text' } - await makePostBodyRequest({ url: server.url, path: pathComment, token: 'none', fields, statusCodeExpected: 401 }) + await makePostBodyRequest({ + url: server.url, + path: pathComment, + token: 'none', + fields, + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + }) }) it('Should fail with nothing', async function () { @@ -190,7 +215,13 @@ describe('Test video comments API validator', function () { const fields = { text: 'super comment' } - await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 }) + await makePostBodyRequest({ + url: server.url, + path, + token: server.accessToken, + fields, + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + }) }) it('Should fail with an incorrect comment', async function () { @@ -198,34 +229,51 @@ describe('Test video comments API validator', function () { const fields = { text: 'super comment' } - await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 }) + await makePostBodyRequest({ + url: server.url, + path, + token: server.accessToken, + fields, + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + }) }) it('Should succeed with the correct parameters', async function () { const fields = { text: 'super comment' } - await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields, statusCodeExpected: 200 }) + await makePostBodyRequest({ + url: server.url, + path: pathComment, + token: server.accessToken, + fields, + statusCodeExpected: HttpStatusCode.OK_200 + }) }) }) describe('When removing video comments', function () { it('Should fail with a non authenticated user', async function () { - await makeDeleteRequest({ url: server.url, path: pathComment, token: 'none', statusCodeExpected: 401 }) + await makeDeleteRequest({ url: server.url, path: pathComment, token: 'none', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with another user', async function () { - await makeDeleteRequest({ url: server.url, path: pathComment, token: userAccessToken, statusCodeExpected: 403 }) + await makeDeleteRequest({ + url: server.url, + path: pathComment, + token: userAccessToken, + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + }) }) it('Should fail with an incorrect video', async function () { const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId - await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 404 }) + await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) it('Should fail with an incorrect comment', async function () { const path = '/api/v1/videos/' + videoUUID + '/comments/124' - await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 404 }) + await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) it('Should succeed with the same user', async function () { @@ -238,8 +286,8 @@ describe('Test video comments API validator', function () { const path = '/api/v1/videos/' + videoUUID + '/comments/' + commentToDelete - await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, statusCodeExpected: 403 }) - await makeDeleteRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 204 }) + await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) + await makeDeleteRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) }) it('Should succeed with the owner of the video', async function () { @@ -258,12 +306,17 @@ describe('Test video comments API validator', function () { const path = '/api/v1/videos/' + anotherVideoUUID + '/comments/' + commentToDelete - await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, statusCodeExpected: 403 }) - await makeDeleteRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 204 }) + await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) + await makeDeleteRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) }) it('Should succeed with the correct parameters', async function () { - await makeDeleteRequest({ url: server.url, path: pathComment, token: server.accessToken, statusCodeExpected: 204 }) + await makeDeleteRequest({ + url: server.url, + path: pathComment, + token: server.accessToken, + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + }) }) }) @@ -278,7 +331,7 @@ describe('Test video comments API validator', function () { const res = await makeGetRequest({ url: server.url, path: pathThread, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) expect(res.body.total).to.equal(0) expect(res.body.data).to.have.lengthOf(0) @@ -290,7 +343,13 @@ describe('Test video comments API validator', function () { const fields = { text: 'super comment' } - await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields, statusCodeExpected: 409 }) + await makePostBodyRequest({ + url: server.url, + path: pathThread, + token: server.accessToken, + fields, + statusCodeExpected: HttpStatusCode.CONFLICT_409 + }) }) it('Should return conflict on comment thread add') @@ -315,7 +374,7 @@ describe('Test video comments API validator', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -324,7 +383,7 @@ describe('Test video comments API validator', function () { url: server.url, path, token: userAccessToken, - statusCodeExpected: 403 + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) }) @@ -339,7 +398,7 @@ describe('Test video comments API validator', function () { searchAccount: 'toto', searchVideo: 'toto' }, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) }) }) diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts index f954ba089..49ff96117 100644 --- a/server/tests/api/check-params/video-imports.ts +++ b/server/tests/api/check-params/video-imports.ts @@ -24,6 +24,7 @@ import { } from '../../../../shared/extra-utils/requests/check-api-params' import { getMagnetURI, getGoodVideoUrl } from '../../../../shared/extra-utils/videos/video-imports' import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' describe('Test video imports API validator', function () { const path = '/api/v1/videos/imports' @@ -67,7 +68,7 @@ describe('Test video imports API validator', function () { }) it('Should success with the correct parameters', async function () { - await makeGetRequest({ url: server.url, path: myPath, statusCodeExpected: 200, token: server.accessToken }) + await makeGetRequest({ url: server.url, path: myPath, statusCodeExpected: HttpStatusCode.OK_200, token: server.accessToken }) }) }) @@ -100,7 +101,13 @@ describe('Test video imports API validator', function () { it('Should fail without a target url', async function () { const fields = omit(baseCorrectParams, 'targetUrl') - await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 400 }) + await makePostBodyRequest({ + url: server.url, + path, + token: server.accessToken, + fields, + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + }) }) it('Should fail with a bad target url', async function () { @@ -251,7 +258,7 @@ describe('Test video imports API validator', function () { path, token: server.accessToken, fields: baseCorrectParams, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) }) @@ -274,7 +281,7 @@ describe('Test video imports API validator', function () { path, token: server.accessToken, fields: baseCorrectParams, - statusCodeExpected: 409 + statusCodeExpected: HttpStatusCode.CONFLICT_409 }) }) @@ -295,14 +302,27 @@ describe('Test video imports API validator', function () { let fields = omit(baseCorrectParams, 'targetUrl') fields = immutableAssign(fields, { magnetUri: getMagnetURI() }) - await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 }) + await makePostBodyRequest({ + url: server.url, + path, + token: server.accessToken, + fields, + statusCodeExpected: HttpStatusCode.CONFLICT_409 + }) fields = omit(fields, 'magnetUri') const attaches = { torrentfile: join(__dirname, '..', '..', 'fixtures', 'video-720p.torrent') } - await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches, statusCodeExpected: 409 }) + await makeUploadRequest({ + url: server.url, + path, + token: server.accessToken, + fields, + attaches, + statusCodeExpected: HttpStatusCode.CONFLICT_409 + }) }) }) diff --git a/server/tests/api/check-params/video-playlists.ts b/server/tests/api/check-params/video-playlists.ts index 179ae9201..418af05d1 100644 --- a/server/tests/api/check-params/video-playlists.ts +++ b/server/tests/api/check-params/video-playlists.ts @@ -28,6 +28,7 @@ import { } from '../../../../shared/extra-utils/requests/check-api-params' import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' describe('Test video playlists API validator', function () { let server: ServerInfo @@ -114,19 +115,34 @@ describe('Test video playlists API validator', function () { it('Should fail with a bad account parameter', async function () { const accountPath = '/api/v1/accounts/root2/video-playlists' - await makeGetRequest({ url: server.url, path: accountPath, statusCodeExpected: 404, token: server.accessToken }) + await makeGetRequest({ + url: server.url, + path: accountPath, + statusCodeExpected: HttpStatusCode.NOT_FOUND_404, + token: server.accessToken + }) }) it('Should fail with a bad video channel parameter', async function () { const accountPath = '/api/v1/video-channels/bad_channel/video-playlists' - await makeGetRequest({ url: server.url, path: accountPath, statusCodeExpected: 404, token: server.accessToken }) + await makeGetRequest({ + url: server.url, + path: accountPath, + statusCodeExpected: HttpStatusCode.NOT_FOUND_404, + token: server.accessToken + }) }) it('Should success with the correct parameters', async function () { - await makeGetRequest({ url: server.url, path: globalPath, statusCodeExpected: 200, token: server.accessToken }) - await makeGetRequest({ url: server.url, path: accountPath, statusCodeExpected: 200, token: server.accessToken }) - await makeGetRequest({ url: server.url, path: videoChannelPath, statusCodeExpected: 200, token: server.accessToken }) + await makeGetRequest({ url: server.url, path: globalPath, statusCodeExpected: HttpStatusCode.OK_200, token: server.accessToken }) + await makeGetRequest({ url: server.url, path: accountPath, statusCodeExpected: HttpStatusCode.OK_200, token: server.accessToken }) + await makeGetRequest({ + url: server.url, + path: videoChannelPath, + statusCodeExpected: HttpStatusCode.OK_200, + token: server.accessToken + }) }) }) @@ -142,17 +158,17 @@ describe('Test video playlists API validator', function () { }) it('Should success with the correct parameters', async function () { - await makeGetRequest({ url: server.url, path: path + playlistUUID + '/videos', statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path: path + playlistUUID + '/videos', statusCodeExpected: HttpStatusCode.OK_200 }) }) }) describe('When getting a video playlist', function () { it('Should fail with a bad id or uuid', async function () { - await getVideoPlaylist(server.url, 'toto', 400) + await getVideoPlaylist(server.url, 'toto', HttpStatusCode.BAD_REQUEST_400) }) it('Should fail with an unknown playlist', async function () { - await getVideoPlaylist(server.url, 42, 404) + await getVideoPlaylist(server.url, 42, HttpStatusCode.NOT_FOUND_404) }) it('Should fail to get an unlisted playlist with the number id', async function () { @@ -166,19 +182,19 @@ describe('Test video playlists API validator', function () { }) const playlist = res.body.videoPlaylist - await getVideoPlaylist(server.url, playlist.id, 404) - await getVideoPlaylist(server.url, playlist.uuid, 200) + await getVideoPlaylist(server.url, playlist.id, HttpStatusCode.NOT_FOUND_404) + await getVideoPlaylist(server.url, playlist.uuid, HttpStatusCode.OK_200) }) it('Should succeed with the correct params', async function () { - await getVideoPlaylist(server.url, playlistUUID, 200) + await getVideoPlaylist(server.url, playlistUUID, HttpStatusCode.OK_200) }) }) describe('When creating/updating a video playlist', function () { const getBase = (playlistAttrs: any = {}, wrapper: any = {}) => { return Object.assign({ - expectedStatus: 400, + expectedStatus: HttpStatusCode.BAD_REQUEST_400, url: server.url, token: server.accessToken, playlistAttrs: Object.assign({ @@ -194,7 +210,7 @@ describe('Test video playlists API validator', function () { } it('Should fail with an unauthenticated user', async function () { - const params = getBase({}, { token: null, expectedStatus: 401 }) + const params = getBase({}, { token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) await createVideoPlaylist(params) await updateVideoPlaylist(getUpdate(params, playlistUUID)) @@ -228,7 +244,7 @@ describe('Test video playlists API validator', function () { }) it('Should fail with an unknown video channel id', async function () { - const params = getBase({ videoChannelId: 42 }, { expectedStatus: 404 }) + const params = getBase({ videoChannelId: 42 }, { expectedStatus: HttpStatusCode.NOT_FOUND_404 }) await createVideoPlaylist(params) await updateVideoPlaylist(getUpdate(params, playlistUUID)) @@ -255,33 +271,33 @@ describe('Test video playlists API validator', function () { it('Should fail with an unknown playlist to update', async function () { await updateVideoPlaylist(getUpdate( - getBase({}, { expectedStatus: 404 }), + getBase({}, { expectedStatus: HttpStatusCode.NOT_FOUND_404 }), 42 )) }) it('Should fail to update a playlist of another user', async function () { await updateVideoPlaylist(getUpdate( - getBase({}, { token: userAccessToken, expectedStatus: 403 }), + getBase({}, { token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }), playlistUUID )) }) it('Should fail to update the watch later playlist', async function () { await updateVideoPlaylist(getUpdate( - getBase({}, { expectedStatus: 400 }), + getBase({}, { expectedStatus: HttpStatusCode.BAD_REQUEST_400 }), watchLaterPlaylistId )) }) it('Should succeed with the correct params', async function () { { - const params = getBase({}, { expectedStatus: 200 }) + const params = getBase({}, { expectedStatus: HttpStatusCode.OK_200 }) await createVideoPlaylist(params) } { - const params = getBase({}, { expectedStatus: 204 }) + const params = getBase({}, { expectedStatus: HttpStatusCode.NO_CONTENT_204 }) await updateVideoPlaylist(getUpdate(params, playlistUUID)) } }) @@ -290,7 +306,7 @@ describe('Test video playlists API validator', function () { describe('When adding an element in a playlist', function () { const getBase = (elementAttrs: any = {}, wrapper: any = {}) => { return Object.assign({ - expectedStatus: 400, + expectedStatus: HttpStatusCode.BAD_REQUEST_400, url: server.url, token: server.accessToken, playlistId: playlistUUID, @@ -303,12 +319,12 @@ describe('Test video playlists API validator', function () { } it('Should fail with an unauthenticated user', async function () { - const params = getBase({}, { token: null, expectedStatus: 401 }) + const params = getBase({}, { token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) await addVideoInPlaylist(params) }) it('Should fail with the playlist of another user', async function () { - const params = getBase({}, { token: userAccessToken, expectedStatus: 403 }) + const params = getBase({}, { token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) await addVideoInPlaylist(params) }) @@ -319,13 +335,13 @@ describe('Test video playlists API validator', function () { } { - const params = getBase({}, { playlistId: 42, expectedStatus: 404 }) + const params = getBase({}, { playlistId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) await addVideoInPlaylist(params) } }) it('Should fail with an unknown or incorrect video id', async function () { - const params = getBase({ videoId: 42 }, { expectedStatus: 404 }) + const params = getBase({ videoId: 42 }, { expectedStatus: HttpStatusCode.NOT_FOUND_404 }) await addVideoInPlaylist(params) }) @@ -342,7 +358,7 @@ describe('Test video playlists API validator', function () { }) it('Succeed with the correct params', async function () { - const params = getBase({}, { expectedStatus: 200 }) + const params = getBase({}, { expectedStatus: HttpStatusCode.OK_200 }) const res = await addVideoInPlaylist(params) playlistElementId = res.body.videoPlaylistElement.id }) @@ -359,17 +375,17 @@ describe('Test video playlists API validator', function () { }, elementAttrs), playlistElementId, playlistId: playlistUUID, - expectedStatus: 400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }, wrapper) } it('Should fail with an unauthenticated user', async function () { - const params = getBase({}, { token: null, expectedStatus: 401 }) + const params = getBase({}, { token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) await updateVideoPlaylistElement(params) }) it('Should fail with the playlist of another user', async function () { - const params = getBase({}, { token: userAccessToken, expectedStatus: 403 }) + const params = getBase({}, { token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) await updateVideoPlaylistElement(params) }) @@ -380,7 +396,7 @@ describe('Test video playlists API validator', function () { } { - const params = getBase({}, { playlistId: 42, expectedStatus: 404 }) + const params = getBase({}, { playlistId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) await updateVideoPlaylistElement(params) } }) @@ -392,7 +408,7 @@ describe('Test video playlists API validator', function () { } { - const params = getBase({}, { playlistElementId: 42, expectedStatus: 404 }) + const params = getBase({}, { playlistElementId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) await updateVideoPlaylistElement(params) } }) @@ -410,12 +426,12 @@ describe('Test video playlists API validator', function () { }) it('Should fail with an unknown element', async function () { - const params = getBase({}, { playlistElementId: 888, expectedStatus: 404 }) + const params = getBase({}, { playlistElementId: 888, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) await updateVideoPlaylistElement(params) }) it('Succeed with the correct params', async function () { - const params = getBase({}, { expectedStatus: 204 }) + const params = getBase({}, { expectedStatus: HttpStatusCode.NO_CONTENT_204 }) await updateVideoPlaylistElement(params) }) }) @@ -434,7 +450,7 @@ describe('Test video playlists API validator', function () { insertAfterPosition: 2, reorderLength: 3 }, elementAttrs), - expectedStatus: 400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }, wrapper) } @@ -453,12 +469,12 @@ describe('Test video playlists API validator', function () { }) it('Should fail with an unauthenticated user', async function () { - const params = getBase({}, { token: null, expectedStatus: 401 }) + const params = getBase({}, { token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) await reorderVideosPlaylist(params) }) it('Should fail with the playlist of another user', async function () { - const params = getBase({}, { token: userAccessToken, expectedStatus: 403 }) + const params = getBase({}, { token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) await reorderVideosPlaylist(params) }) @@ -469,7 +485,7 @@ describe('Test video playlists API validator', function () { } { - const params = getBase({}, { playlistId: 42, expectedStatus: 404 }) + const params = getBase({}, { playlistId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) await reorderVideosPlaylist(params) } }) @@ -526,7 +542,7 @@ describe('Test video playlists API validator', function () { }) it('Succeed with the correct params', async function () { - const params = getBase({}, { expectedStatus: 204 }) + const params = getBase({}, { expectedStatus: HttpStatusCode.NO_CONTENT_204 }) await reorderVideosPlaylist(params) }) }) @@ -539,7 +555,7 @@ describe('Test video playlists API validator', function () { url: server.url, path, query: { videoIds: [ 1, 2 ] }, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -572,7 +588,7 @@ describe('Test video playlists API validator', function () { token: server.accessToken, path, query: { videoIds: [ 1, 2 ] }, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) }) }) @@ -584,17 +600,17 @@ describe('Test video playlists API validator', function () { token: server.accessToken, playlistElementId, playlistId: playlistUUID, - expectedStatus: 400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }, wrapper) } it('Should fail with an unauthenticated user', async function () { - const params = getBase({ token: null, expectedStatus: 401 }) + const params = getBase({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) await removeVideoFromPlaylist(params) }) it('Should fail with the playlist of another user', async function () { - const params = getBase({ token: userAccessToken, expectedStatus: 403 }) + const params = getBase({ token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) await removeVideoFromPlaylist(params) }) @@ -605,7 +621,7 @@ describe('Test video playlists API validator', function () { } { - const params = getBase({ playlistId: 42, expectedStatus: 404 }) + const params = getBase({ playlistId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) await removeVideoFromPlaylist(params) } }) @@ -617,33 +633,33 @@ describe('Test video playlists API validator', function () { } { - const params = getBase({ playlistElementId: 42, expectedStatus: 404 }) + const params = getBase({ playlistElementId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) await removeVideoFromPlaylist(params) } }) it('Should fail with an unknown element', async function () { - const params = getBase({ playlistElementId: 888, expectedStatus: 404 }) + const params = getBase({ playlistElementId: 888, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) await removeVideoFromPlaylist(params) }) it('Succeed with the correct params', async function () { - const params = getBase({ expectedStatus: 204 }) + const params = getBase({ expectedStatus: HttpStatusCode.NO_CONTENT_204 }) await removeVideoFromPlaylist(params) }) }) describe('When deleting a playlist', function () { it('Should fail with an unknown playlist', async function () { - await deleteVideoPlaylist(server.url, server.accessToken, 42, 404) + await deleteVideoPlaylist(server.url, server.accessToken, 42, HttpStatusCode.NOT_FOUND_404) }) it('Should fail with a playlist of another user', async function () { - await deleteVideoPlaylist(server.url, userAccessToken, playlistUUID, 403) + await deleteVideoPlaylist(server.url, userAccessToken, playlistUUID, HttpStatusCode.FORBIDDEN_403) }) it('Should fail with the watch later playlist', async function () { - await deleteVideoPlaylist(server.url, server.accessToken, watchLaterPlaylistId, 400) + await deleteVideoPlaylist(server.url, server.accessToken, watchLaterPlaylistId, HttpStatusCode.BAD_REQUEST_400) }) it('Should succeed with the correct params', async function () { diff --git a/server/tests/api/check-params/videos-filter.ts b/server/tests/api/check-params/videos-filter.ts index bf8248b0e..2391584a7 100644 --- a/server/tests/api/check-params/videos-filter.ts +++ b/server/tests/api/check-params/videos-filter.ts @@ -12,8 +12,9 @@ import { userLogin } from '../../../../shared/extra-utils' import { UserRole } from '../../../../shared/models/users' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' -async function testEndpoints (server: ServerInfo, token: string, filter: string, statusCodeExpected: number) { +async function testEndpoints (server: ServerInfo, token: string, filter: string, statusCodeExpected: HttpStatusCode) { const paths = [ '/api/v1/video-channels/root_channel/videos', '/api/v1/accounts/root/videos', @@ -71,26 +72,26 @@ describe('Test videos filters', function () { describe('When setting a video filter', function () { it('Should fail with a bad filter', async function () { - await testEndpoints(server, server.accessToken, 'bad-filter', 400) + await testEndpoints(server, server.accessToken, 'bad-filter', HttpStatusCode.BAD_REQUEST_400) }) it('Should succeed with a good filter', async function () { - await testEndpoints(server, server.accessToken, 'local', 200) + await testEndpoints(server, server.accessToken, 'local', HttpStatusCode.OK_200) }) it('Should fail to list all-local/all with a simple user', async function () { - await testEndpoints(server, userAccessToken, 'all-local', 401) - await testEndpoints(server, userAccessToken, 'all', 401) + await testEndpoints(server, userAccessToken, 'all-local', HttpStatusCode.UNAUTHORIZED_401) + await testEndpoints(server, userAccessToken, 'all', HttpStatusCode.UNAUTHORIZED_401) }) it('Should succeed to list all-local/all with a moderator', async function () { - await testEndpoints(server, moderatorAccessToken, 'all-local', 200) - await testEndpoints(server, moderatorAccessToken, 'all', 200) + await testEndpoints(server, moderatorAccessToken, 'all-local', HttpStatusCode.OK_200) + await testEndpoints(server, moderatorAccessToken, 'all', HttpStatusCode.OK_200) }) it('Should succeed to list all-local/all with an admin', async function () { - await testEndpoints(server, server.accessToken, 'all-local', 200) - await testEndpoints(server, server.accessToken, 'all', 200) + await testEndpoints(server, server.accessToken, 'all-local', HttpStatusCode.OK_200) + await testEndpoints(server, server.accessToken, 'all', HttpStatusCode.OK_200) }) // Because we cannot authenticate the user on the RSS endpoint @@ -99,7 +100,7 @@ describe('Test videos filters', function () { await makeGetRequest({ url: server.url, path: '/feeds/videos.json', - statusCodeExpected: 401, + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401, query: { filter } @@ -111,7 +112,7 @@ describe('Test videos filters', function () { await makeGetRequest({ url: server.url, path: '/feeds/videos.json', - statusCodeExpected: 200, + statusCodeExpected: HttpStatusCode.OK_200, query: { filter: 'local' } diff --git a/server/tests/api/check-params/videos-history.ts b/server/tests/api/check-params/videos-history.ts index 941f62654..0e91fe0a8 100644 --- a/server/tests/api/check-params/videos-history.ts +++ b/server/tests/api/check-params/videos-history.ts @@ -13,6 +13,7 @@ import { setAccessTokensToServers, uploadVideo } from '../../../../shared/extra-utils' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' describe('Test videos history API validator', function () { const myHistoryPath = '/api/v1/users/me/history/videos' @@ -39,31 +40,55 @@ describe('Test videos history API validator', function () { it('Should fail with an unauthenticated user', async function () { const fields = { currentTime: 5 } - await makePutBodyRequest({ url: server.url, path: watchingPath, fields, statusCodeExpected: 401 }) + await makePutBodyRequest({ url: server.url, path: watchingPath, fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with an incorrect video id', async function () { const fields = { currentTime: 5 } const path = '/api/v1/videos/blabla/watching' - await makePutBodyRequest({ url: server.url, path, fields, token: server.accessToken, statusCodeExpected: 400 }) + await makePutBodyRequest({ + url: server.url, + path, + fields, + token: server.accessToken, + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + }) }) it('Should fail with an unknown video', async function () { const fields = { currentTime: 5 } const path = '/api/v1/videos/d91fff41-c24d-4508-8e13-3bd5902c3b02/watching' - await makePutBodyRequest({ url: server.url, path, fields, token: server.accessToken, statusCodeExpected: 404 }) + await makePutBodyRequest({ + url: server.url, + path, + fields, + token: server.accessToken, + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + }) }) it('Should fail with a bad current time', async function () { const fields = { currentTime: 'hello' } - await makePutBodyRequest({ url: server.url, path: watchingPath, fields, token: server.accessToken, statusCodeExpected: 400 }) + await makePutBodyRequest({ + url: server.url, + path: watchingPath, + fields, + token: server.accessToken, + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + }) }) it('Should succeed with the correct parameters', async function () { const fields = { currentTime: 5 } - await makePutBodyRequest({ url: server.url, path: watchingPath, fields, token: server.accessToken, statusCodeExpected: 204 }) + await makePutBodyRequest({ + url: server.url, + path: watchingPath, + fields, + token: server.accessToken, + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + }) }) }) @@ -77,17 +102,17 @@ describe('Test videos history API validator', function () { }) it('Should fail with an unauthenticated user', async function () { - await makeGetRequest({ url: server.url, path: myHistoryPath, statusCodeExpected: 401 }) + await makeGetRequest({ url: server.url, path: myHistoryPath, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should succeed with the correct params', async function () { - await makeGetRequest({ url: server.url, token: server.accessToken, path: myHistoryPath, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, token: server.accessToken, path: myHistoryPath, statusCodeExpected: HttpStatusCode.OK_200 }) }) }) describe('When removing user videos history', function () { it('Should fail with an unauthenticated user', async function () { - await makePostBodyRequest({ url: server.url, path: myHistoryPath + '/remove', statusCodeExpected: 401 }) + await makePostBodyRequest({ url: server.url, path: myHistoryPath + '/remove', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with a bad beforeDate parameter', async function () { @@ -97,7 +122,7 @@ describe('Test videos history API validator', function () { token: server.accessToken, path: myHistoryRemove, fields: body, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -108,7 +133,7 @@ describe('Test videos history API validator', function () { token: server.accessToken, path: myHistoryRemove, fields: body, - statusCodeExpected: 204 + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) }) @@ -117,7 +142,7 @@ describe('Test videos history API validator', function () { url: server.url, token: server.accessToken, path: myHistoryRemove, - statusCodeExpected: 204 + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) }) }) diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts index 0d4665954..d60546917 100644 --- a/server/tests/api/check-params/videos.ts +++ b/server/tests/api/check-params/videos.ts @@ -28,6 +28,7 @@ import { checkBadSortPagination, checkBadStartPagination } from '../../../../shared/extra-utils/requests/check-api-params' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' const expect = chai.expect @@ -76,11 +77,11 @@ describe('Test videos API validator', function () { }) it('Should fail with a bad skipVideos query', async function () { - await makeGetRequest({ url: server.url, path, statusCodeExpected: 200, query: { skipCount: 'toto' } }) + await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200, query: { skipCount: 'toto' } }) }) it('Should success with the correct parameters', async function () { - await makeGetRequest({ url: server.url, path, statusCodeExpected: 200, query: { skipCount: false } }) + await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200, query: { skipCount: false } }) }) }) @@ -90,7 +91,7 @@ describe('Test videos API validator', function () { await makeGetRequest({ url: server.url, path: join(path, 'search'), - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) @@ -107,7 +108,7 @@ describe('Test videos API validator', function () { }) it('Should success with the correct parameters', async function () { - await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 }) }) }) @@ -127,7 +128,7 @@ describe('Test videos API validator', function () { }) it('Should success with the correct parameters', async function () { - await makeGetRequest({ url: server.url, token: server.accessToken, path, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, token: server.accessToken, path, statusCodeExpected: HttpStatusCode.OK_200 }) }) }) @@ -151,7 +152,7 @@ describe('Test videos API validator', function () { }) it('Should success with the correct parameters', async function () { - await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 }) }) }) @@ -175,7 +176,7 @@ describe('Test videos API validator', function () { }) it('Should success with the correct parameters', async function () { - await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 }) }) }) @@ -408,7 +409,7 @@ describe('Test videos API validator', function () { token: server.accessToken, fields, attaches, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) } @@ -423,7 +424,7 @@ describe('Test videos API validator', function () { token: server.accessToken, fields, attaches, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) } @@ -438,7 +439,7 @@ describe('Test videos API validator', function () { token: server.accessToken, fields, attaches, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) } }) @@ -481,7 +482,7 @@ describe('Test videos API validator', function () { path: path + '4da6fde3-88f7-4d16-b119-108df5630b06', token: server.accessToken, fields, - statusCodeExpected: 404 + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) @@ -630,7 +631,13 @@ describe('Test videos API validator', function () { it('Should fail with a video of another user without the appropriate right', async function () { const fields = baseCorrectParams - await makePutBodyRequest({ url: server.url, path: path + videoId, token: userAccessToken, fields, statusCodeExpected: 403 }) + await makePutBodyRequest({ + url: server.url, + path: path + videoId, + token: userAccessToken, + fields, + statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + }) }) it('Should fail with a video of another server') @@ -638,7 +645,13 @@ describe('Test videos API validator', function () { it('Should succeed with the correct parameters', async function () { const fields = baseCorrectParams - await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields, statusCodeExpected: 204 }) + await makePutBodyRequest({ + url: server.url, + path: path + videoId, + token: server.accessToken, + fields, + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + }) }) }) @@ -647,7 +660,7 @@ describe('Test videos API validator', function () { const res = await makeGetRequest({ url: server.url, path, - statusCodeExpected: 200 + statusCodeExpected: HttpStatusCode.OK_200 }) expect(res.body.data).to.be.an('array') @@ -655,11 +668,11 @@ describe('Test videos API validator', function () { }) it('Should fail without a correct uuid', async function () { - await getVideo(server.url, 'coucou', 400) + await getVideo(server.url, 'coucou', HttpStatusCode.BAD_REQUEST_400) }) it('Should return 404 with an incorrect video', async function () { - await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', 404) + await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404) }) it('Should succeed with the correct parameters', async function () { @@ -691,7 +704,7 @@ describe('Test videos API validator', function () { path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate', token: server.accessToken, fields, - statusCodeExpected: 404 + statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) }) @@ -711,7 +724,7 @@ describe('Test videos API validator', function () { path: path + videoId + '/rate', token: server.accessToken, fields, - statusCodeExpected: 204 + statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) }) }) @@ -721,20 +734,20 @@ describe('Test videos API validator', function () { await makeDeleteRequest({ url: server.url, path, - statusCodeExpected: 400 + statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should fail without a correct uuid', async function () { - await removeVideo(server.url, server.accessToken, 'hello', 400) + await removeVideo(server.url, server.accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400) }) it('Should fail with a video which does not exist', async function () { - await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404) + await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404) }) it('Should fail with a video of another user without the appropriate right', async function () { - await removeVideo(server.url, userAccessToken, videoId, 403) + await removeVideo(server.url, userAccessToken, videoId, HttpStatusCode.FORBIDDEN_403) }) it('Should fail with a video of another server') diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts index c5037a541..7cfcf70e1 100644 --- a/server/tests/api/redundancy/redundancy.ts +++ b/server/tests/api/redundancy/redundancy.ts @@ -41,6 +41,7 @@ import { join } from 'path' import { VideoRedundancy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '../../../../shared/models/redundancy' import { getStats } from '../../../../shared/extra-utils/server/stats' import { ServerStats } from '../../../../shared/models/server/server-stats.model' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' const expect = chai.expect @@ -147,13 +148,13 @@ async function check2Webseeds (videoUUID?: string) { await makeGetRequest({ url: servers[0].url, - statusCodeExpected: 200, + statusCodeExpected: HttpStatusCode.OK_200, path: '/static/redundancy/' + `${videoUUID}-${file.resolution.id}.mp4`, contentType: null }) await makeGetRequest({ url: servers[1].url, - statusCodeExpected: 200, + statusCodeExpected: HttpStatusCode.OK_200, path: `/static/webseed/${videoUUID}-${file.resolution.id}.mp4`, contentType: null }) diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index fe83ca041..cd928b980 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -47,6 +47,7 @@ import { follow } from '../../../../shared/extra-utils/server/follows' import { logout, serverLogin, setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' import { getMyVideos } from '../../../../shared/extra-utils/videos/videos' import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' const expect = chai.expect @@ -86,14 +87,14 @@ describe('Test users', function () { it('Should not login with an invalid client id', async function () { const client = { id: 'client', secret: server.client.secret } - const res = await login(server.url, client, server.user, 400) + const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400) expect(res.body.error).to.contain('client is invalid') }) it('Should not login with an invalid client secret', async function () { const client = { id: server.client.id, secret: 'coucou' } - const res = await login(server.url, client, server.user, 400) + const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400) expect(res.body.error).to.contain('client is invalid') }) @@ -103,14 +104,14 @@ describe('Test users', function () { it('Should not login with an invalid username', async function () { const user = { username: 'captain crochet', password: server.user.password } - const res = await login(server.url, server.client, user, 400) + const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400) expect(res.body.error).to.contain('credentials are invalid') }) it('Should not login with an invalid password', async function () { const user = { username: server.user.username, password: 'mew_three' } - const res = await login(server.url, server.client, user, 400) + const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400) expect(res.body.error).to.contain('credentials are invalid') }) @@ -119,31 +120,31 @@ describe('Test users', function () { accessToken = 'my_super_token' const videoAttributes = {} - await uploadVideo(server.url, accessToken, videoAttributes, 401) + await uploadVideo(server.url, accessToken, videoAttributes, HttpStatusCode.UNAUTHORIZED_401) }) it('Should not be able to follow', async function () { accessToken = 'my_super_token' - await follow(server.url, [ 'http://example.com' ], accessToken, 401) + await follow(server.url, [ 'http://example.com' ], accessToken, HttpStatusCode.UNAUTHORIZED_401) }) it('Should not be able to unfollow') it('Should be able to login', async function () { - const res = await login(server.url, server.client, server.user, 200) + const res = await login(server.url, server.client, server.user, HttpStatusCode.OK_200) accessToken = res.body.access_token }) it('Should be able to login with an insensitive username', async function () { const user = { username: 'RoOt', password: server.user.password } - await login(server.url, server.client, user, 200) + await login(server.url, server.client, user, HttpStatusCode.OK_200) const user2 = { username: 'rOoT', password: server.user.password } - await login(server.url, server.client, user2, 200) + await login(server.url, server.client, user2, HttpStatusCode.OK_200) const user3 = { username: 'ROOt', password: server.user.password } - await login(server.url, server.client, user3, 200) + await login(server.url, server.client, user3, HttpStatusCode.OK_200) }) }) @@ -179,7 +180,7 @@ describe('Test users', function () { it('Should retrieve ratings list', async function () { await rateVideo(server.url, accessToken, videoId, 'like') - const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, 200) + const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, HttpStatusCode.OK_200) const ratings = res.body expect(ratings.total).to.equal(1) @@ -204,7 +205,7 @@ describe('Test users', function () { describe('Remove video', function () { it('Should not be able to remove the video with an incorrect token', async function () { - await removeVideo(server.url, 'bad_token', videoId, 401) + await removeVideo(server.url, 'bad_token', videoId, HttpStatusCode.UNAUTHORIZED_401) }) it('Should not be able to remove the video with the token of another account') @@ -220,11 +221,11 @@ describe('Test users', function () { }) it('Should not be able to get the user information', async function () { - await getMyUserInformation(server.url, server.accessToken, 401) + await getMyUserInformation(server.url, server.accessToken, HttpStatusCode.UNAUTHORIZED_401) }) it('Should not be able to upload a video', async function () { - await uploadVideo(server.url, server.accessToken, { name: 'video' }, 401) + await uploadVideo(server.url, server.accessToken, { name: 'video' }, HttpStatusCode.UNAUTHORIZED_401) }) it('Should not be able to rate a video', async function () { @@ -238,7 +239,7 @@ describe('Test users', function () { path: path + videoId, token: 'wrong token', fields: data, - statusCodeExpected: 401 + statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 } await makePutBodyRequest(options) }) @@ -534,7 +535,7 @@ describe('Test users', function () { }) user.password = 'new password' - await userLogin(server, user, 200) + await userLogin(server, user, HttpStatusCode.OK_200) }) it('Should be able to change the NSFW display attribute', async function () { @@ -732,7 +733,7 @@ describe('Test users', function () { }) it('Should have removed the user token', async function () { - await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401) + await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401) accessTokenUser = await userLogin(server, user) }) @@ -745,9 +746,9 @@ describe('Test users', function () { password: 'password updated' }) - await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401) + await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401) - await userLogin(server, user, 400) + await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400) user.password = 'password updated' accessTokenUser = await userLogin(server, user) @@ -766,7 +767,7 @@ describe('Test users', function () { }) it('Should not be able to login with this user', async function () { - await userLogin(server, user, 400) + await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400) }) it('Should not have videos of this user', async function () { @@ -852,11 +853,11 @@ describe('Test users', function () { user16AccessToken = await userLogin(server, user16) - await getMyUserInformation(server.url, user16AccessToken, 200) + await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200) await blockUser(server.url, user16Id, server.accessToken) - await getMyUserInformation(server.url, user16AccessToken, 401) - await userLogin(server, user16, 400) + await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.UNAUTHORIZED_401) + await userLogin(server, user16, HttpStatusCode.BAD_REQUEST_400) }) it('Should search user by banned status', async function () { @@ -884,7 +885,7 @@ describe('Test users', function () { it('Should unblock a user', async function () { await unblockUser(server.url, user16Id, server.accessToken) user16AccessToken = await userLogin(server, user16) - await getMyUserInformation(server.url, user16AccessToken, 200) + await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200) }) }) diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts index f9500d617..f88c59f0d 100644 --- a/server/tests/api/videos/video-transcoder.ts +++ b/server/tests/api/videos/video-transcoder.ts @@ -37,6 +37,7 @@ import { getVideoFileFPS, getVideoFileResolution } from '../../../helpers/ffprobe-utils' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' const expect = chai.expect @@ -280,7 +281,7 @@ describe('Test video transcoding', function () { expect(videoToFindInList).to.be.undefined // Server 1 should not have the video yet - await getVideo(servers[0].url, videoId, 404) + await getVideo(servers[0].url, videoId, HttpStatusCode.NOT_FOUND_404) } await waitJobs(servers) @@ -400,8 +401,8 @@ describe('Test video transcoding', function () { expect(videoDetails.files).to.have.lengthOf(1) - await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: 200 }) - await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: HttpStatusCode.OK_200 }) const magnetUri = videoDetails.files[0].magnetUri expect(magnetUri).to.contain('.mp4') @@ -425,8 +426,8 @@ describe('Test video transcoding', function () { expect(videoDetails.files).to.have.lengthOf(1) - await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: 200 }) - await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: 200 }) + await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: HttpStatusCode.OK_200 }) const magnetUri = videoDetails.files[0].magnetUri expect(magnetUri).to.contain('.mp4') diff --git a/server/tests/api/videos/videos-filter.ts b/server/tests/api/videos/videos-filter.ts index 6b9a4b6d4..2961c8e78 100644 --- a/server/tests/api/videos/videos-filter.ts +++ b/server/tests/api/videos/videos-filter.ts @@ -15,10 +15,11 @@ import { } from '../../../../shared/extra-utils' import { Video, VideoPrivacy } from '../../../../shared/models/videos' import { UserRole } from '../../../../shared/models/users' +import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' const expect = chai.expect -async function getVideosNames (server: ServerInfo, token: string, filter: string, statusCodeExpected = 200) { +async function getVideosNames (server: ServerInfo, token: string, filter: string, statusCodeExpected = HttpStatusCode.OK_200) { const paths = [ '/api/v1/video-channels/root_channel/videos', '/api/v1/accounts/root/videos', -- cgit v1.2.3