1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { AbuseState, VideoAbuseCreate } 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 let server: ServerInfo
28 let userAccessToken = ''
29 let videoAbuseId: number
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 video abuses', function () {
50 const path = '/api/v1/videos/abuse'
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 state filter', async function () {
86 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { state: 'toto' } })
89 it('Should fail with a bad videoIs filter', async function () {
90 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { videoIs: 'toto' } })
93 it('Should succeed with the correct params', async function () {
94 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { id: 13 }, statusCodeExpected: 200 })
98 describe('When reporting a video abuse', function () {
99 const basePath = '/api/v1/videos/'
103 path = basePath + server.video.id + '/abuse'
106 it('Should fail with nothing', async function () {
108 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
111 it('Should fail with a wrong video', async function () {
112 const wrongPath = '/api/v1/videos/blabla/abuse'
113 const fields = { reason: 'my super reason' }
115 await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
118 it('Should fail with a non authenticated user', async function () {
119 const fields = { reason: 'my super reason' }
121 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
124 it('Should fail with a reason too short', async function () {
125 const fields = { reason: 'h' }
127 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
130 it('Should fail with a too big reason', async function () {
131 const fields = { reason: 'super'.repeat(605) }
133 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
136 it('Should succeed with the correct parameters (basic)', async function () {
137 const fields = { reason: 'my super reason' }
139 const res = await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 200 })
140 videoAbuseId = res.body.abuse.id
143 it('Should fail with a wrong predefined reason', async function () {
144 const fields = { reason: 'my super reason', predefinedReasons: [ 'wrongPredefinedReason' ] }
146 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
149 it('Should fail with negative timestamps', async function () {
150 const fields = { reason: 'my super reason', startAt: -1 }
152 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
155 it('Should succeed with the corret parameters (advanced)', async function () {
156 const fields: VideoAbuseCreate = { reason: 'my super reason', predefinedReasons: [ 'serverRules' ], startAt: 1, endAt: 5 }
158 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 200 })
162 describe('When updating a video abuse', function () {
164 it('Should fail with a non authenticated user', async function () {
165 await updateVideoAbuse(server.url, 'blabla', server.video.uuid, videoAbuseId, {}, 401)
168 it('Should fail with a non admin user', async function () {
169 await updateVideoAbuse(server.url, userAccessToken, server.video.uuid, videoAbuseId, {}, 403)
172 it('Should fail with a bad video id or bad video abuse id', async function () {
173 await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, 45, {}, 404)
174 await updateVideoAbuse(server.url, server.accessToken, 52, videoAbuseId, {}, 404)
177 it('Should fail with a bad state', async function () {
178 const body = { state: 5 }
179 await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId, body, 400)
182 it('Should fail with a bad moderation comment', async function () {
183 const body = { moderationComment: 'b'.repeat(3001) }
184 await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId, body, 400)
187 it('Should succeed with the correct params', async function () {
188 const body = { state: AbuseState.ACCEPTED }
189 await updateVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId, body)
193 describe('When deleting a video abuse', function () {
195 it('Should fail with a non authenticated user', async function () {
196 await deleteVideoAbuse(server.url, 'blabla', server.video.uuid, videoAbuseId, 401)
199 it('Should fail with a non admin user', async function () {
200 await deleteVideoAbuse(server.url, userAccessToken, server.video.uuid, videoAbuseId, 403)
203 it('Should fail with a bad video id or bad video abuse id', async function () {
204 await deleteVideoAbuse(server.url, server.accessToken, server.video.uuid, 45, 404)
205 await deleteVideoAbuse(server.url, server.accessToken, 52, videoAbuseId, 404)
208 it('Should succeed with the correct params', async function () {
209 await deleteVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId)
213 after(async function () {
214 await cleanupTests([ server ])