X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fcheck-params%2Fabuses.ts;h=7d8347412b077bef8cbb4c184742a630a7f270a3;hb=fd3c2e87051f5029cdec39d877b576a62f48e219;hp=199cc55997101990c13c229cfd5e929251f07374;hpb=d23dd9fbfc4d26026352c10f81d2795ceaf2908a;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/check-params/abuses.ts b/server/tests/api/check-params/abuses.ts index 199cc5599..7d8347412 100644 --- a/server/tests/api/check-params/abuses.ts +++ b/server/tests/api/check-params/abuses.ts @@ -1,27 +1,24 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ import 'mocha' -import { HttpStatusCode } from '@shared/core-utils' +import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared' +import { AbuseCreate, AbuseState, HttpStatusCode } from '@shared/models' import { AbusesCommand, - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination, cleanupTests, + createSingleServer, doubleFollow, - flushAndRunServer, makeGetRequest, makePostBodyRequest, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, waitJobs -} from '@shared/extra-utils' -import { AbuseCreate, AbuseState } from '@shared/models' +} from '@shared/server-commands' describe('Test abuses API validators', function () { const basePath = '/api/v1/abuses/' - let server: ServerInfo + let server: PeerTubeServer let userToken = '' let userToken2 = '' @@ -35,16 +32,16 @@ describe('Test abuses API validators', function () { before(async function () { this.timeout(30000) - server = await flushAndRunServer(1) + server = await createSingleServer(1) await setAccessTokensToServers([ server ]) - userToken = await server.usersCommand.generateUserAndToken('user_1') - userToken2 = await server.usersCommand.generateUserAndToken('user_2') + userToken = await server.users.generateUserAndToken('user_1') + userToken2 = await server.users.generateUserAndToken('user_2') - server.video = await server.videosCommand.upload() + server.store.videoCreated = await server.videos.upload() - command = server.abusesCommand + command = server.abuses }) describe('When listing abuses for admins', function () { @@ -66,7 +63,7 @@ describe('Test abuses API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -75,7 +72,7 @@ describe('Test abuses API validators', function () { url: server.url, path, token: userToken, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -110,7 +107,7 @@ describe('Test abuses API validators', function () { videoIs: 'deleted' } - await makeGetRequest({ url: server.url, path, token: server.accessToken, query, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path, token: server.accessToken, query, expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -133,7 +130,7 @@ describe('Test abuses API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -152,7 +149,7 @@ describe('Test abuses API validators', function () { state: 2 } - await makeGetRequest({ url: server.url, path, token: userToken, query, statusCodeExpected: HttpStatusCode.OK_200 }) + await makeGetRequest({ url: server.url, path, token: userToken, query, expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -166,7 +163,7 @@ describe('Test abuses API validators', function () { it('Should fail with a wrong video', async function () { const fields = { video: { id: 'blabla' }, reason: 'my super reason' } - await makePostBodyRequest({ url: server.url, path: path, token: userToken, fields }) + await makePostBodyRequest({ url: server.url, path, token: userToken, fields }) }) it('Should fail with an unknown video', async function () { @@ -176,13 +173,13 @@ describe('Test abuses API validators', function () { path, token: userToken, fields, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should fail with a wrong comment', async function () { const fields = { comment: { id: 'blabla' }, reason: 'my super reason' } - await makePostBodyRequest({ url: server.url, path: path, token: userToken, fields }) + await makePostBodyRequest({ url: server.url, path, token: userToken, fields }) }) it('Should fail with an unknown comment', async function () { @@ -192,13 +189,13 @@ describe('Test abuses API validators', function () { path, token: userToken, fields, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) it('Should fail with a wrong account', async function () { const fields = { account: { id: 'blabla' }, reason: 'my super reason' } - await makePostBodyRequest({ url: server.url, path: path, token: userToken, fields }) + await makePostBodyRequest({ url: server.url, path, token: userToken, fields }) }) it('Should fail with an unknown account', async function () { @@ -208,7 +205,7 @@ describe('Test abuses API validators', function () { path, token: userToken, fields, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -219,63 +216,63 @@ describe('Test abuses API validators', function () { path, token: userToken, fields, - statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 + expectedStatus: 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' } + const fields = { video: { id: server.store.videoCreated.id }, reason: 'my super reason' } - await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) + await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with a reason too short', async function () { - const fields = { video: { id: server.video.id }, reason: 'h' } + const fields = { video: { id: server.store.videoCreated.id }, reason: 'h' } await makePostBodyRequest({ url: server.url, path, token: userToken, fields }) }) it('Should fail with a too big reason', async function () { - const fields = { video: { id: server.video.id }, reason: 'super'.repeat(605) } + const fields = { video: { id: server.store.videoCreated.id }, reason: 'super'.repeat(605) } await makePostBodyRequest({ url: server.url, path, token: userToken, fields }) }) it('Should succeed with the correct parameters (basic)', async function () { - const fields: AbuseCreate = { video: { id: server.video.shortUUID }, reason: 'my super reason' } + const fields: AbuseCreate = { video: { id: server.store.videoCreated.shortUUID }, reason: 'my super reason' } const res = await makePostBodyRequest({ url: server.url, path, token: userToken, fields, - statusCodeExpected: HttpStatusCode.OK_200 + expectedStatus: HttpStatusCode.OK_200 }) abuseId = res.body.abuse.id }) it('Should fail with a wrong predefined reason', async function () { - const fields = { video: { id: server.video.id }, reason: 'my super reason', predefinedReasons: [ 'wrongPredefinedReason' ] } + const fields = { video: server.store.videoCreated, reason: 'my super reason', predefinedReasons: [ 'wrongPredefinedReason' ] } await makePostBodyRequest({ url: server.url, path, token: userToken, fields }) }) it('Should fail with negative timestamps', async function () { - const fields = { video: { id: server.video.id, startAt: -1 }, reason: 'my super reason' } + const fields = { video: { id: server.store.videoCreated.id, startAt: -1 }, reason: 'my super reason' } await makePostBodyRequest({ url: server.url, path, token: userToken, fields }) }) it('Should fail mith misordered startAt/endAt', async function () { - const fields = { video: { id: server.video.id, startAt: 5, endAt: 1 }, reason: 'my super reason' } + const fields = { video: { id: server.store.videoCreated.id, startAt: 5, endAt: 1 }, reason: 'my super reason' } await makePostBodyRequest({ url: server.url, path, token: userToken, fields }) }) - it('Should succeed with the corret parameters (advanced)', async function () { + it('Should succeed with the correct parameters (advanced)', async function () { const fields: AbuseCreate = { video: { - id: server.video.id, + id: server.store.videoCreated.id, startAt: 1, endAt: 5 }, @@ -283,7 +280,7 @@ describe('Test abuses API validators', function () { predefinedReasons: [ 'serverRules' ] } - await makePostBodyRequest({ url: server.url, path, token: userToken, fields, statusCodeExpected: HttpStatusCode.OK_200 }) + await makePostBodyRequest({ url: server.url, path, token: userToken, fields, expectedStatus: HttpStatusCode.OK_200 }) }) }) @@ -336,7 +333,7 @@ describe('Test abuses API validators', function () { await command.addMessage({ token: userToken, abuseId, message: 'a'.repeat(5000), expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) }) - it('Should suceed with the correct params', async function () { + it('Should succeed with the correct params', async function () { const res = await command.addMessage({ token: userToken, abuseId, message }) messageId = res.body.abuseMessage.id }) @@ -404,18 +401,18 @@ describe('Test abuses API validators', function () { describe('When trying to manage messages of a remote abuse', function () { let remoteAbuseId: number - let anotherServer: ServerInfo + let anotherServer: PeerTubeServer before(async function () { this.timeout(50000) - anotherServer = await flushAndRunServer(2) + anotherServer = await createSingleServer(2) await setAccessTokensToServers([ anotherServer ]) await doubleFollow(anotherServer, server) - const server2VideoId = await anotherServer.videosCommand.getId({ uuid: server.video.uuid }) - await anotherServer.abusesCommand.report({ reason: 'remote server', videoId: server2VideoId }) + const server2VideoId = await anotherServer.videos.getId({ uuid: server.store.videoCreated.uuid }) + await anotherServer.abuses.report({ reason: 'remote server', videoId: server2VideoId }) await waitJobs([ server, anotherServer ])