X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fcheck-params%2Fabuses.ts;h=7d8347412b077bef8cbb4c184742a630a7f270a3;hb=fd3c2e87051f5029cdec39d877b576a62f48e219;hp=14949d30111b6c8fb97449875482ba9ccd75a375;hpb=41d1d075011174e73dccb74006181a92a618d7b4;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/check-params/abuses.ts b/server/tests/api/check-params/abuses.ts index 14949d301..7d8347412 100644 --- a/server/tests/api/check-params/abuses.ts +++ b/server/tests/api/check-params/abuses.ts @@ -1,31 +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, - createUser, + createSingleServer, doubleFollow, - flushAndRunServer, - generateUserAccessToken, - getVideoIdFromUUID, makeGetRequest, makePostBodyRequest, - ServerInfo, + PeerTubeServer, setAccessTokensToServers, - uploadVideo, 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 = '' @@ -39,21 +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 ]) - const username = 'user1' - const password = 'my super password' - await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) - userToken = await server.loginCommand.getAccessToken({ username, password }) + userToken = await server.users.generateUserAndToken('user_1') + userToken2 = await server.users.generateUserAndToken('user_2') - userToken2 = await generateUserAccessToken(server, 'user_2') + server.store.videoCreated = await server.videos.upload() - const res = await uploadVideo(server.url, server.accessToken, {}) - server.video = res.body.video - - command = server.abusesCommand + command = server.abuses }) describe('When listing abuses for admins', function () { @@ -75,7 +63,7 @@ describe('Test abuses API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -84,7 +72,7 @@ describe('Test abuses API validators', function () { url: server.url, path, token: userToken, - statusCodeExpected: HttpStatusCode.FORBIDDEN_403 + expectedStatus: HttpStatusCode.FORBIDDEN_403 }) }) @@ -119,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 }) }) }) @@ -142,7 +130,7 @@ describe('Test abuses API validators', function () { await makeGetRequest({ url: server.url, path, - statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 + expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) @@ -161,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 }) }) }) @@ -175,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 () { @@ -185,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 () { @@ -201,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 () { @@ -217,7 +205,7 @@ describe('Test abuses API validators', function () { path, token: userToken, fields, - statusCodeExpected: HttpStatusCode.NOT_FOUND_404 + expectedStatus: HttpStatusCode.NOT_FOUND_404 }) }) @@ -228,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 }, @@ -292,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 }) }) }) @@ -345,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 }) @@ -413,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 getVideoIdFromUUID(anotherServer.url, 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 ])