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 // FIXME: deprecated in 2.3. Remove this controller
26 describe('Test video abuses API validators', function () {
27 const basePath = '/api/v1/abuses/'
29 let server: ServerInfo
30 let userAccessToken = ''
33 // ---------------------------------------------------------------
35 before(async function () {
38 server = await flushAndRunServer(1)
40 await setAccessTokensToServers([ server ])
42 const username = 'user1'
43 const password = 'my super password'
44 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
45 userAccessToken = await userLogin(server, { username, password })
47 const res = await uploadVideo(server.url, server.accessToken, {})
48 server.video = res.body.video
51 describe('When listing abuses', function () {
54 it('Should fail with a bad start pagination', async function () {
55 await checkBadStartPagination(server.url, path, server.accessToken)
58 it('Should fail with a bad count pagination', async function () {
59 await checkBadCountPagination(server.url, path, server.accessToken)
62 it('Should fail with an incorrect sort', async function () {
63 await checkBadSortPagination(server.url, path, server.accessToken)
66 it('Should fail with a non authenticated user', async function () {
67 await makeGetRequest({
70 statusCodeExpected: 401
74 it('Should fail with a non admin user', async function () {
75 await makeGetRequest({
78 token: userAccessToken,
79 statusCodeExpected: 403
83 it('Should fail with a bad id filter', async function () {
84 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { id: 'toto' } })
87 it('Should fail with a bad filter', async function () {
88 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { filter: 'toto' } })
89 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { filter: 'videos' } })
92 it('Should fail with bad predefined reason', async function () {
93 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { predefinedReason: 'violentOrRepulsives' } })
96 it('Should fail with a bad state filter', async function () {
97 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { state: 'toto' } })
98 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { state: 0 } })
101 it('Should fail with a bad videoIs filter', async function () {
102 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { videoIs: 'toto' } })
105 it('Should succeed with the correct params', async function () {
108 predefinedReason: 'violentOrRepulsive',
114 await makeGetRequest({ url: server.url, path, token: server.accessToken, query, statusCodeExpected: 200 })
118 describe('When reporting an abuse', function () {
119 const path = basePath
121 it('Should fail with nothing', async function () {
123 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
126 it('Should fail with a wrong video', async function () {
127 const fields = { video: { id: 'blabla' }, reason: 'my super reason' }
128 await makePostBodyRequest({ url: server.url, path: path, token: server.accessToken, fields })
131 it('Should fail with an unknown video', async function () {
132 const fields = { video: { id: 42 }, reason: 'my super reason' }
133 await makePostBodyRequest({ url: server.url, path: path, token: server.accessToken, fields, statusCodeExpected: 404 })
136 it('Should fail with a wrong comment', async function () {
137 const fields = { comment: { id: 'blabla' }, reason: 'my super reason' }
138 await makePostBodyRequest({ url: server.url, path: path, token: server.accessToken, fields })
141 it('Should fail with an unknown comment', async function () {
142 const fields = { comment: { id: 42 }, reason: 'my super reason' }
143 await makePostBodyRequest({ url: server.url, path: path, token: server.accessToken, fields, statusCodeExpected: 404 })
146 it('Should fail with a wrong account', async function () {
147 const fields = { account: { id: 'blabla' }, reason: 'my super reason' }
148 await makePostBodyRequest({ url: server.url, path: path, token: server.accessToken, fields })
151 it('Should fail with an unknown account', async function () {
152 const fields = { account: { id: 42 }, reason: 'my super reason' }
153 await makePostBodyRequest({ url: server.url, path: path, token: server.accessToken, fields, statusCodeExpected: 404 })
156 it('Should fail with not account, comment or video', async function () {
157 const fields = { reason: 'my super reason' }
158 await makePostBodyRequest({ url: server.url, path: path, token: server.accessToken, fields, statusCodeExpected: 400 })
161 it('Should fail with a non authenticated user', async function () {
162 const fields = { video: { id: server.video.id }, reason: 'my super reason' }
164 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
167 it('Should fail with a reason too short', async function () {
168 const fields = { video: { id: server.video.id }, reason: 'h' }
170 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
173 it('Should fail with a too big reason', async function () {
174 const fields = { video: { id: server.video.id }, reason: 'super'.repeat(605) }
176 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
179 it('Should succeed with the correct parameters (basic)', async function () {
180 const fields: AbuseCreate = { video: { id: server.video.id }, reason: 'my super reason' }
182 const res = await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 200 })
183 abuseId = res.body.abuse.id
186 it('Should fail with a wrong predefined reason', async function () {
187 const fields = { video: { id: server.video.id }, reason: 'my super reason', predefinedReasons: [ 'wrongPredefinedReason' ] }
189 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
192 it('Should fail with negative timestamps', async function () {
193 const fields = { video: { id: server.video.id, startAt: -1 }, reason: 'my super reason' }
195 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
198 it('Should fail mith misordered startAt/endAt', async function () {
199 const fields = { video: { id: server.video.id, startAt: 5, endAt: 1 }, reason: 'my super reason' }
201 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
204 it('Should succeed with the corret parameters (advanced)', async function () {
205 const fields: AbuseCreate = {
211 reason: 'my super reason',
212 predefinedReasons: [ 'serverRules' ]
215 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 200 })
219 describe('When updating an abuse', function () {
221 it('Should fail with a non authenticated user', async function () {
222 await updateAbuse(server.url, 'blabla', abuseId, {}, 401)
225 it('Should fail with a non admin user', async function () {
226 await updateAbuse(server.url, userAccessToken, abuseId, {}, 403)
229 it('Should fail with a bad abuse id', async function () {
230 await updateAbuse(server.url, server.accessToken, 45, {}, 404)
233 it('Should fail with a bad state', async function () {
234 const body = { state: 5 }
235 await updateAbuse(server.url, server.accessToken, abuseId, body, 400)
238 it('Should fail with a bad moderation comment', async function () {
239 const body = { moderationComment: 'b'.repeat(3001) }
240 await updateAbuse(server.url, server.accessToken, abuseId, body, 400)
243 it('Should succeed with the correct params', async function () {
244 const body = { state: AbuseState.ACCEPTED }
245 await updateAbuse(server.url, server.accessToken, abuseId, body)
249 describe('When deleting a video abuse', function () {
251 it('Should fail with a non authenticated user', async function () {
252 await deleteAbuse(server.url, 'blabla', abuseId, 401)
255 it('Should fail with a non admin user', async function () {
256 await deleteAbuse(server.url, userAccessToken, abuseId, 403)
259 it('Should fail with a bad abuse id', async function () {
260 await deleteAbuse(server.url, server.accessToken, 45, 404)
263 it('Should succeed with the correct params', async function () {
264 await deleteAbuse(server.url, server.accessToken, abuseId)
268 after(async function () {
269 await cleanupTests([ server ])