aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/video-abuses.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params/video-abuses.ts')
-rw-r--r--server/tests/api/check-params/video-abuses.ts216
1 files changed, 0 insertions, 216 deletions
diff --git a/server/tests/api/check-params/video-abuses.ts b/server/tests/api/check-params/video-abuses.ts
deleted file mode 100644
index 3b361ca79..000000000
--- a/server/tests/api/check-params/video-abuses.ts
+++ /dev/null
@@ -1,216 +0,0 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import { AbuseState, VideoAbuseCreate } from '@shared/models'
5import {
6 cleanupTests,
7 createUser,
8 deleteVideoAbuse,
9 flushAndRunServer,
10 makeGetRequest,
11 makePostBodyRequest,
12 ServerInfo,
13 setAccessTokensToServers,
14 updateVideoAbuse,
15 uploadVideo,
16 userLogin
17} from '../../../../shared/extra-utils'
18import {
19 checkBadCountPagination,
20 checkBadSortPagination,
21 checkBadStartPagination
22} from '../../../../shared/extra-utils/requests/check-api-params'
23
24// FIXME: deprecated in 2.3. Remove this controller
25
26describe('Test video abuses API validators', function () {
27 let server: ServerInfo
28 let userAccessToken = ''
29 let videoAbuseId: number
30
31 // ---------------------------------------------------------------
32
33 before(async function () {
34 this.timeout(30000)
35
36 server = await flushAndRunServer(1)
37
38 await setAccessTokensToServers([ server ])
39
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 })
44
45 const res = await uploadVideo(server.url, server.accessToken, {})
46 server.video = res.body.video
47 })
48
49 describe('When listing video abuses', function () {
50 const path = '/api/v1/videos/abuse'
51
52 it('Should fail with a bad start pagination', async function () {
53 await checkBadStartPagination(server.url, path, server.accessToken)
54 })
55
56 it('Should fail with a bad count pagination', async function () {
57 await checkBadCountPagination(server.url, path, server.accessToken)
58 })
59
60 it('Should fail with an incorrect sort', async function () {
61 await checkBadSortPagination(server.url, path, server.accessToken)
62 })
63
64 it('Should fail with a non authenticated user', async function () {
65 await makeGetRequest({
66 url: server.url,
67 path,
68 statusCodeExpected: 401
69 })
70 })
71
72 it('Should fail with a non admin user', async function () {
73 await makeGetRequest({
74 url: server.url,
75 path,
76 token: userAccessToken,
77 statusCodeExpected: 403
78 })
79 })
80
81 it('Should fail with a bad id filter', async function () {
82 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { id: 'toto' } })
83 })
84
85 it('Should fail with a bad state filter', async function () {
86 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { state: 'toto' } })
87 })
88
89 it('Should fail with a bad videoIs filter', async function () {
90 await makeGetRequest({ url: server.url, path, token: server.accessToken, query: { videoIs: 'toto' } })
91 })
92
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 })
95 })
96 })
97
98 describe('When reporting a video abuse', function () {
99 const basePath = '/api/v1/videos/'
100 let path: string
101
102 before(() => {
103 path = basePath + server.video.id + '/abuse'
104 })
105
106 it('Should fail with nothing', async function () {
107 const fields = {}
108 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
109 })
110
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' }
114
115 await makePostBodyRequest({ url: server.url, path: wrongPath, token: server.accessToken, fields })
116 })
117
118 it('Should fail with a non authenticated user', async function () {
119 const fields = { reason: 'my super reason' }
120
121 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 })
122 })
123
124 it('Should fail with a reason too short', async function () {
125 const fields = { reason: 'h' }
126
127 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
128 })
129
130 it('Should fail with a too big reason', async function () {
131 const fields = { reason: 'super'.repeat(605) }
132
133 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
134 })
135
136 it('Should succeed with the correct parameters (basic)', async function () {
137 const fields = { reason: 'my super reason' }
138
139 const res = await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 200 })
140 videoAbuseId = res.body.abuse.id
141 })
142
143 it('Should fail with a wrong predefined reason', async function () {
144 const fields = { reason: 'my super reason', predefinedReasons: [ 'wrongPredefinedReason' ] }
145
146 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
147 })
148
149 it('Should fail with negative timestamps', async function () {
150 const fields = { reason: 'my super reason', startAt: -1 }
151
152 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
153 })
154
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 }
157
158 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 200 })
159 })
160 })
161
162 describe('When updating a video abuse', function () {
163
164 it('Should fail with a non authenticated user', async function () {
165 await updateVideoAbuse(server.url, 'blabla', server.video.uuid, videoAbuseId, {}, 401)
166 })
167
168 it('Should fail with a non admin user', async function () {
169 await updateVideoAbuse(server.url, userAccessToken, server.video.uuid, videoAbuseId, {}, 403)
170 })
171
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)
175 })
176
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)
180 })
181
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)
185 })
186
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)
190 })
191 })
192
193 describe('When deleting a video abuse', function () {
194
195 it('Should fail with a non authenticated user', async function () {
196 await deleteVideoAbuse(server.url, 'blabla', server.video.uuid, videoAbuseId, 401)
197 })
198
199 it('Should fail with a non admin user', async function () {
200 await deleteVideoAbuse(server.url, userAccessToken, server.video.uuid, videoAbuseId, 403)
201 })
202
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)
206 })
207
208 it('Should succeed with the correct params', async function () {
209 await deleteVideoAbuse(server.url, server.accessToken, server.video.uuid, videoAbuseId)
210 })
211 })
212
213 after(async function () {
214 await cleanupTests([ server ])
215 })
216})