X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fcheck-params%2Fredundancy.ts;h=73dfd489d49d2141c3b79a0280fd5682ec993505;hb=0a8a79552cf59c800011c9f63eaa8658230acddc;hp=fca92fde44482a0ef219c31d45088cbab154251f;hpb=89d241a79c262b9775c233b73cff080043ebb5e6;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/check-params/redundancy.ts b/server/tests/api/check-params/redundancy.ts index fca92fde4..73dfd489d 100644 --- a/server/tests/api/check-params/redundancy.ts +++ b/server/tests/api/check-params/redundancy.ts @@ -1,26 +1,22 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import 'mocha' -import { VideoCreateResult } from '@shared/models' -import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' +import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared' +import { HttpStatusCode, VideoCreateResult } from '@shared/models' import { - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination, cleanupTests, + createMultipleServers, doubleFollow, - flushAndRunMultipleServers, makeDeleteRequest, makeGetRequest, makePostBodyRequest, makePutBodyRequest, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, waitJobs -} from '../../../../shared/extra-utils' +} from '@shared/server-commands' describe('Test server redundancy API validators', function () { - let servers: ServerInfo[] + let servers: PeerTubeServer[] let userAccessToken = null let videoIdLocal: number let videoRemote: VideoCreateResult @@ -28,9 +24,9 @@ describe('Test server redundancy API validators', function () { // --------------------------------------------------------------- before(async function () { - this.timeout(80000) + this.timeout(160000) - servers = await flushAndRunMultipleServers(2) + servers = await createMultipleServers(2) await setAccessTokensToServers(servers) await doubleFollow(servers[0], servers[1]) @@ -64,11 +60,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: HttpStatusCode.UNAUTHORIZED_401 }) + await makeGetRequest({ url, path, token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail if the user is not an administrator', async function () { - await makeGetRequest({ url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) + await makeGetRequest({ url, path, token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should fail with a bad start pagination', async function () { @@ -92,7 +88,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: HttpStatusCode.OK_200 }) + await makeGetRequest({ url, path, token, query: { target: 'my-videos' }, expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -108,11 +104,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: HttpStatusCode.UNAUTHORIZED_401 }) + await makePostBodyRequest({ url, path, token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail if the user is not an administrator', async function () { - await makePostBodyRequest({ url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) + await makePostBodyRequest({ url, path, token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should fail without a video id', async function () { @@ -124,7 +120,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: HttpStatusCode.NOT_FOUND_404 }) + await makePostBodyRequest({ url, path, token, fields: { videoId: 6565 }, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should fail with a local a video id', async function () { @@ -137,7 +133,7 @@ describe('Test server redundancy API validators', function () { path, token, fields: { videoId: videoRemote.shortUUID }, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) @@ -151,7 +147,7 @@ describe('Test server redundancy API validators', function () { path, token, fields: { videoId: videoRemote.uuid }, - statusCodeExpected: HttpStatusCode.CONFLICT_409 + expectedStatus: HttpStatusCode.CONFLICT_409 }) }) }) @@ -168,11 +164,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: HttpStatusCode.UNAUTHORIZED_401 }) + await makeDeleteRequest({ url, path: path + '1', token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail if the user is not an administrator', async function () { - await makeDeleteRequest({ url, path: path + '1', token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) + await makeDeleteRequest({ url, path: path + '1', token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) it('Should fail with an incorrect video id', async function () { @@ -180,7 +176,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: HttpStatusCode.NOT_FOUND_404 }) + await makeDeleteRequest({ url, path: path + '454545', token, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) }) @@ -190,20 +186,20 @@ describe('Test server redundancy API validators', function () { it('Should fail with an invalid token', async function () { await makePutBodyRequest({ url: servers[0].url, - path: path + '/localhost:' + servers[1].port, + path: path + '/' + servers[1].host, fields: { redundancyAllowed: true }, token: 'fake_token', - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail if the user is not an administrator', async function () { await makePutBodyRequest({ url: servers[0].url, - path: path + '/localhost:' + servers[1].port, + path: path + '/' + servers[1].host, fields: { redundancyAllowed: true }, token: userAccessToken, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -213,27 +209,27 @@ describe('Test server redundancy API validators', function () { path: path + '/example.com', fields: { redundancyAllowed: true }, token: servers[0].accessToken, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should fail without de redundancyAllowed param', async function () { await makePutBodyRequest({ url: servers[0].url, - path: path + '/localhost:' + servers[1].port, + path: path + '/' + servers[1].host, fields: { blabla: true }, token: servers[0].accessToken, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) it('Should succeed with the correct parameters', async function () { await makePutBodyRequest({ url: servers[0].url, - path: path + '/localhost:' + servers[1].port, + path: path + '/' + servers[1].host, fields: { redundancyAllowed: true }, token: servers[0].accessToken, - statusCodeExpected: HttpStatusCode.NO_CONTENT_204 + expectedStatus: HttpStatusCode.NO_CONTENT_204 }) }) })