1 /* tslint:disable:no-unused-expression */
6 createUser, flushTests, killallServers, makeGetRequest, makePostBodyRequest, runServer, ServerInfo, setAccessTokensToServers,
9 import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
11 describe('Test video abuses API validators', function () {
12 let server: ServerInfo
13 let userAccessToken = ''
15 // ---------------------------------------------------------------
17 before(async function () {
22 server = await runServer(1)
24 await setAccessTokensToServers([ server ])
26 const username = 'user1'
27 const password = 'my super password'
28 await createUser(server.url, server.accessToken, username, password)
29 userAccessToken = await userLogin(server, { username, password })
31 const res = await uploadVideo(server.url, server.accessToken, {})
32 server.video = res.body.video
35 describe('When listing video abuses', function () {
36 const path = '/api/v1/videos/abuse'
38 it('Should fail with a bad start pagination', async function () {
39 await checkBadStartPagination(server.url, path, server.accessToken)
42 it('Should fail with a bad count pagination', async function () {
43 await checkBadCountPagination(server.url, path, server.accessToken)
46 it('Should fail with an incorrect sort', async function () {
47 await checkBadSortPagination(server.url, path, server.accessToken)
50 it('Should fail with a non authenticated user', async function () {
51 await makeGetRequest({
54 statusCodeExpected: 401
58 it('Should fail with a non admin user', async function () {
59 await makeGetRequest({
62 token: userAccessToken,
63 statusCodeExpected: 403
68 describe('When reporting a video abuse', function () {
69 const basePath = '/api/v1/videos/'
71 it('Should fail with nothing', async function () {
72 const path = basePath + server.video.id + '/abuse'
74 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
77 it('Should fail with a wrong video', async function () {
78 const wrongPath = '/api/v1/videos/blabla/abuse'
80 reason: 'my super reason'
82 await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
85 it('Should fail with a non authenticated user', async function () {
86 const path = basePath + server.video.id + '/abuse'
88 reason: 'my super reason'
90 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
93 it('Should fail with a reason too short', async function () {
94 const path = basePath + server.video.id + '/abuse'
98 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
101 it('Should fail with a reason too big', async function () {
102 const path = basePath + server.video.id + '/abuse'
104 reason: 'super'.repeat(61)
106 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
110 after(async function () {
111 killallServers([ server ])
113 // Keep the logs if the test failed