1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { AbuseCreate, AbuseState } from '@shared/models'
13 setAccessTokensToServers,
17 } from '../../../../shared/extra-utils'
19 checkBadCountPagination,
20 checkBadSortPagination,
21 checkBadStartPagination
22 } from '../../../../shared/extra-utils/requests/check-api-params'
24 describe('Test abuses API validators', function () {
25 const basePath = '/api/v1/abuses/'
27 let server: ServerInfo
28 let userAccessToken = ''
31 // ---------------------------------------------------------------
33 before(async function () {
36 server = await flushAndRunServer(1)
38 await setAccessTokensToServers([ server ])
40 const username = 'user1'
41 const password = 'my super password'
42 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
43 userAccessToken = await userLogin(server, { username, password })
45 const res = await uploadVideo(server.url, server.accessToken, {})
46 server.video = res.body.video
49 describe('When listing abuses', function () {
52 it('Should fail with a bad start pagination', async function () {
53 await checkBadStartPagination(server.url, path, server.accessToken)
56 it('Should fail with a bad count pagination', async function () {
57 await checkBadCountPagination(server.url, path, server.accessToken)
60 it('Should fail with an incorrect sort', async function () {
61 await checkBadSortPagination(server.url, path, server.accessToken)
64 it('Should fail with a non authenticated user', async function () {
65 await makeGetRequest({
68 statusCodeExpected: 401
72 it('Should fail with a non admin user', async function () {
73 await makeGetRequest({
76 token: userAccessToken,
77 statusCodeExpected: 403
81 it('Should fail with a bad id filter', async function () {
82 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { id: 'toto' } })
85 it('Should fail with a bad filter', async function () {
86 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { filter: 'toto' } })
87 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { filter: 'videos' } })
90 it('Should fail with bad predefined reason', async function () {
91 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { predefinedReason: 'violentOrRepulsives' } })
94 it('Should fail with a bad state filter', async function () {
95 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { state: 'toto' } })
96 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { state: 0 } })
99 it('Should fail with a bad videoIs filter', async function () {
100 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { videoIs: 'toto' } })
103 it('Should succeed with the correct params', async function () {
106 predefinedReason: 'violentOrRepulsive',
112 await makeGetRequest({ url: server.url, path, token: server.accessToken, query, statusCodeExpected: 200 })
116 describe('When reporting an abuse', function () {
117 const path = basePath
119 it('Should fail with nothing', async function () {
121 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
124 it('Should fail with a wrong video', async function () {
125 const fields = { video: { id: 'blabla' }, reason: 'my super reason' }
126 await makePostBodyRequest({ url: server.url, path: path, token: server.accessToken, fields })
129 it('Should fail with an unknown video', async function () {
130 const fields = { video: { id: 42 }, reason: 'my super reason' }
131 await makePostBodyRequest({ url: server.url, path: path, token: server.accessToken, fields, statusCodeExpected: 404 })
134 it('Should fail with a wrong comment', async function () {
135 const fields = { comment: { id: 'blabla' }, reason: 'my super reason' }
136 await makePostBodyRequest({ url: server.url, path: path, token: server.accessToken, fields })
139 it('Should fail with an unknown comment', async function () {
140 const fields = { comment: { id: 42 }, reason: 'my super reason' }
141 await makePostBodyRequest({ url: server.url, path: path, token: server.accessToken, fields, statusCodeExpected: 404 })
144 it('Should fail with a wrong account', async function () {
145 const fields = { account: { id: 'blabla' }, reason: 'my super reason' }
146 await makePostBodyRequest({ url: server.url, path: path, token: server.accessToken, fields })
149 it('Should fail with an unknown account', async function () {
150 const fields = { account: { id: 42 }, reason: 'my super reason' }
151 await makePostBodyRequest({ url: server.url, path: path, token: server.accessToken, fields, statusCodeExpected: 404 })
154 it('Should fail with not account, comment or video', async function () {
155 const fields = { reason: 'my super reason' }
156 await makePostBodyRequest({ url: server.url, path: path, token: server.accessToken, fields, statusCodeExpected: 400 })
159 it('Should fail with a non authenticated user', async function () {
160 const fields = { video: { id: server.video.id }, reason: 'my super reason' }
162 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
165 it('Should fail with a reason too short', async function () {
166 const fields = { video: { id: server.video.id }, reason: 'h' }
168 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
171 it('Should fail with a too big reason', async function () {
172 const fields = { video: { id: server.video.id }, reason: 'super'.repeat(605) }
174 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
177 it('Should succeed with the correct parameters (basic)', async function () {
178 const fields: AbuseCreate = { video: { id: server.video.id }, reason: 'my super reason' }
180 const res = await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 200 })
181 abuseId = res.body.abuse.id
184 it('Should fail with a wrong predefined reason', async function () {
185 const fields = { video: { id: server.video.id }, reason: 'my super reason', predefinedReasons: [ 'wrongPredefinedReason' ] }
187 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
190 it('Should fail with negative timestamps', async function () {
191 const fields = { video: { id: server.video.id, startAt: -1 }, reason: 'my super reason' }
193 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
196 it('Should fail mith misordered startAt/endAt', async function () {
197 const fields = { video: { id: server.video.id, startAt: 5, endAt: 1 }, reason: 'my super reason' }
199 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
202 it('Should succeed with the corret parameters (advanced)', async function () {
203 const fields: AbuseCreate = {
209 reason: 'my super reason',
210 predefinedReasons: [ 'serverRules' ]
213 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 200 })
217 describe('When updating an abuse', function () {
219 it('Should fail with a non authenticated user', async function () {
220 await updateAbuse(server.url, 'blabla', abuseId, {}, 401)
223 it('Should fail with a non admin user', async function () {
224 await updateAbuse(server.url, userAccessToken, abuseId, {}, 403)
227 it('Should fail with a bad abuse id', async function () {
228 await updateAbuse(server.url, server.accessToken, 45, {}, 404)
231 it('Should fail with a bad state', async function () {
232 const body = { state: 5 }
233 await updateAbuse(server.url, server.accessToken, abuseId, body, 400)
236 it('Should fail with a bad moderation comment', async function () {
237 const body = { moderationComment: 'b'.repeat(3001) }
238 await updateAbuse(server.url, server.accessToken, abuseId, body, 400)
241 it('Should succeed with the correct params', async function () {
242 const body = { state: AbuseState.ACCEPTED }
243 await updateAbuse(server.url, server.accessToken, abuseId, body)
247 describe('When deleting a video abuse', function () {
249 it('Should fail with a non authenticated user', async function () {
250 await deleteAbuse(server.url, 'blabla', abuseId, 401)
253 it('Should fail with a non admin user', async function () {
254 await deleteAbuse(server.url, userAccessToken, abuseId, 403)
257 it('Should fail with a bad abuse id', async function () {
258 await deleteAbuse(server.url, server.accessToken, 45, 404)
261 it('Should succeed with the correct params', async function () {
262 await deleteAbuse(server.url, server.accessToken, abuseId)
266 after(async function () {
267 await cleanupTests([ server ])