/* 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 = ''
before(async function () {
this.timeout(30000)
- server = await flushAndRunServer(1)
+ server = await createSingleServer(1)
await setAccessTokensToServers([ server ])
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
})
await makeGetRequest({
url: server.url,
path,
- statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
+ expectedStatus: HttpStatusCode.UNAUTHORIZED_401
})
})
url: server.url,
path,
token: userToken,
- statusCodeExpected: HttpStatusCode.FORBIDDEN_403
+ expectedStatus: HttpStatusCode.FORBIDDEN_403
})
})
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 })
})
})
await makeGetRequest({
url: server.url,
path,
- statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
+ expectedStatus: HttpStatusCode.UNAUTHORIZED_401
})
})
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 })
})
})
path,
token: userToken,
fields,
- statusCodeExpected: HttpStatusCode.NOT_FOUND_404
+ expectedStatus: HttpStatusCode.NOT_FOUND_404
})
})
path,
token: userToken,
fields,
- statusCodeExpected: HttpStatusCode.NOT_FOUND_404
+ expectedStatus: HttpStatusCode.NOT_FOUND_404
})
})
path,
token: userToken,
fields,
- statusCodeExpected: HttpStatusCode.NOT_FOUND_404
+ expectedStatus: HttpStatusCode.NOT_FOUND_404
})
})
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.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, 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.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,
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.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 () {
const fields: AbuseCreate = {
video: {
- id: server.store.video.id,
+ id: server.store.videoCreated.id,
startAt: 1,
endAt: 5
},
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 })
})
})
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.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 ])