X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fcheck-params%2Fabuses.ts;h=331d3f8f77e14d6cf7282b418b79c1f613483dc9;hb=3f3530c3dbc5339b4cba53710b8568b4ad39152e;hp=87d93195cbf2827e66a93657cfe3306a307d5c2a;hpb=c0e8b12e7fd554ba4d2ceb0c4900804c6a4c63ea;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/check-params/abuses.ts b/server/tests/api/check-params/abuses.ts index 87d93195c..331d3f8f7 100644 --- a/server/tests/api/check-params/abuses.ts +++ b/server/tests/api/check-params/abuses.ts @@ -1,22 +1,18 @@ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ -import 'mocha' -import { HttpStatusCode } from '@shared/models' +import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared' +import { AbuseCreate, AbuseState, HttpStatusCode } from '@shared/models' import { AbusesCommand, - checkBadCountPagination, - checkBadSortPagination, - checkBadStartPagination, cleanupTests, - doubleFollow, createSingleServer, + doubleFollow, makeGetRequest, makePostBodyRequest, 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/' @@ -42,7 +38,7 @@ describe('Test abuses API validators', function () { userToken = await server.users.generateUserAndToken('user_1') userToken2 = await server.users.generateUserAndToken('user_2') - server.store.video = await server.videos.upload() + server.store.videoCreated = await server.videos.upload() command = server.abuses }) @@ -166,7 +162,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 () { @@ -182,7 +178,7 @@ describe('Test abuses API validators', function () { 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 () { @@ -198,7 +194,7 @@ describe('Test abuses API validators', function () { 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 () { @@ -224,25 +220,25 @@ describe('Test abuses API validators', function () { }) it('Should fail with a non authenticated user', async function () { - const fields = { video: { id: server.store.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, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) }) it('Should fail with a reason too short', async function () { - const fields = { video: { id: server.store.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.store.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.store.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, @@ -255,27 +251,27 @@ describe('Test abuses API validators', function () { }) it('Should fail with a wrong predefined reason', async function () { - const fields = { video: { id: server.store.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.store.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.store.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.store.video.id, + id: server.store.videoCreated.id, startAt: 1, endAt: 5 }, @@ -336,7 +332,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 }) @@ -414,7 +410,7 @@ describe('Test abuses API validators', function () { await doubleFollow(anotherServer, server) - const server2VideoId = await anotherServer.videos.getId({ uuid: server.store.video.uuid }) + const server2VideoId = await anotherServer.videos.getId({ uuid: server.store.videoCreated.uuid }) await anotherServer.abuses.report({ reason: 'remote server', videoId: server2VideoId }) await waitJobs([ server, anotherServer ])