aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/abuses.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-21 15:51:30 +0200
committerChocobozzz <me@florianbigard.com>2021-07-21 15:51:30 +0200
commita24bd1ed41b43790bab6ba789580bb4e85f07d85 (patch)
treea54b0f6c921ba83a6e909cd0ced325b2d4b8863c /server/tests/api/check-params/abuses.ts
parent5f26f13b3c16ac5ae0a3b0a7142d84a9528cf565 (diff)
parentc63830f15403ac4e750829f27d8bbbdc9a59282c (diff)
downloadPeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.gz
PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.zst
PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.zip
Merge branch 'next' into develop
Diffstat (limited to 'server/tests/api/check-params/abuses.ts')
-rw-r--r--server/tests/api/check-params/abuses.ts205
1 files changed, 91 insertions, 114 deletions
diff --git a/server/tests/api/check-params/abuses.ts b/server/tests/api/check-params/abuses.ts
index 2054776cc..72f2cbd8f 100644
--- a/server/tests/api/check-params/abuses.ts
+++ b/server/tests/api/check-params/abuses.ts
@@ -1,66 +1,49 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { AbuseCreate, AbuseState } from '@shared/models'
5import { 4import {
6 addAbuseMessage, 5 AbusesCommand,
6 checkBadCountPagination,
7 checkBadSortPagination,
8 checkBadStartPagination,
7 cleanupTests, 9 cleanupTests,
8 createUser, 10 createSingleServer,
9 deleteAbuse,
10 deleteAbuseMessage,
11 doubleFollow, 11 doubleFollow,
12 flushAndRunServer,
13 generateUserAccessToken,
14 getAdminAbusesList,
15 getVideoIdFromUUID,
16 listAbuseMessages,
17 makeGetRequest, 12 makeGetRequest,
18 makePostBodyRequest, 13 makePostBodyRequest,
19 reportAbuse, 14 PeerTubeServer,
20 ServerInfo,
21 setAccessTokensToServers, 15 setAccessTokensToServers,
22 updateAbuse,
23 uploadVideo,
24 userLogin,
25 waitJobs 16 waitJobs
26} from '../../../../shared/extra-utils' 17} from '@shared/extra-utils'
27import { 18import { AbuseCreate, AbuseState, HttpStatusCode } from '@shared/models'
28 checkBadCountPagination,
29 checkBadSortPagination,
30 checkBadStartPagination
31} from '../../../../shared/extra-utils/requests/check-api-params'
32import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
33 19
34describe('Test abuses API validators', function () { 20describe('Test abuses API validators', function () {
35 const basePath = '/api/v1/abuses/' 21 const basePath = '/api/v1/abuses/'
36 22
37 let server: ServerInfo 23 let server: PeerTubeServer
38 24
39 let userAccessToken = '' 25 let userToken = ''
40 let userAccessToken2 = '' 26 let userToken2 = ''
41 let abuseId: number 27 let abuseId: number
42 let messageId: number 28 let messageId: number
43 29
30 let command: AbusesCommand
31
44 // --------------------------------------------------------------- 32 // ---------------------------------------------------------------
45 33
46 before(async function () { 34 before(async function () {
47 this.timeout(30000) 35 this.timeout(30000)
48 36
49 server = await flushAndRunServer(1) 37 server = await createSingleServer(1)
50 38
51 await setAccessTokensToServers([ server ]) 39 await setAccessTokensToServers([ server ])
52 40
53 const username = 'user1' 41 userToken = await server.users.generateUserAndToken('user_1')
54 const password = 'my super password' 42 userToken2 = await server.users.generateUserAndToken('user_2')
55 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
56 userAccessToken = await userLogin(server, { username, password })
57 43
58 { 44 server.store.video = await server.videos.upload()
59 userAccessToken2 = await generateUserAccessToken(server, 'user_2')
60 }
61 45
62 const res = await uploadVideo(server.url, server.accessToken, {}) 46 command = server.abuses
63 server.video = res.body.video
64 }) 47 })
65 48
66 describe('When listing abuses for admins', function () { 49 describe('When listing abuses for admins', function () {
@@ -82,7 +65,7 @@ describe('Test abuses API validators', function () {
82 await makeGetRequest({ 65 await makeGetRequest({
83 url: server.url, 66 url: server.url,
84 path, 67 path,
85 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 68 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
86 }) 69 })
87 }) 70 })
88 71
@@ -90,8 +73,8 @@ describe('Test abuses API validators', function () {
90 await makeGetRequest({ 73 await makeGetRequest({
91 url: server.url, 74 url: server.url,
92 path, 75 path,
93 token: userAccessToken, 76 token: userToken,
94 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 77 expectedStatus: HttpStatusCode.FORBIDDEN_403
95 }) 78 })
96 }) 79 })
97 80
@@ -126,7 +109,7 @@ describe('Test abuses API validators', function () {
126 videoIs: 'deleted' 109 videoIs: 'deleted'
127 } 110 }
128 111
129 await makeGetRequest({ url: server.url, path, token: server.accessToken, query, statusCodeExpected: HttpStatusCode.OK_200 }) 112 await makeGetRequest({ url: server.url, path, token: server.accessToken, query, expectedStatus: HttpStatusCode.OK_200 })
130 }) 113 })
131 }) 114 })
132 115
@@ -134,32 +117,32 @@ describe('Test abuses API validators', function () {
134 const path = '/api/v1/users/me/abuses' 117 const path = '/api/v1/users/me/abuses'
135 118
136 it('Should fail with a bad start pagination', async function () { 119 it('Should fail with a bad start pagination', async function () {
137 await checkBadStartPagination(server.url, path, userAccessToken) 120 await checkBadStartPagination(server.url, path, userToken)
138 }) 121 })
139 122
140 it('Should fail with a bad count pagination', async function () { 123 it('Should fail with a bad count pagination', async function () {
141 await checkBadCountPagination(server.url, path, userAccessToken) 124 await checkBadCountPagination(server.url, path, userToken)
142 }) 125 })
143 126
144 it('Should fail with an incorrect sort', async function () { 127 it('Should fail with an incorrect sort', async function () {
145 await checkBadSortPagination(server.url, path, userAccessToken) 128 await checkBadSortPagination(server.url, path, userToken)
146 }) 129 })
147 130
148 it('Should fail with a non authenticated user', async function () { 131 it('Should fail with a non authenticated user', async function () {
149 await makeGetRequest({ 132 await makeGetRequest({
150 url: server.url, 133 url: server.url,
151 path, 134 path,
152 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 135 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
153 }) 136 })
154 }) 137 })
155 138
156 it('Should fail with a bad id filter', async function () { 139 it('Should fail with a bad id filter', async function () {
157 await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { id: 'toto' } }) 140 await makeGetRequest({ url: server.url, path, token: userToken, query: { id: 'toto' } })
158 }) 141 })
159 142
160 it('Should fail with a bad state filter', async function () { 143 it('Should fail with a bad state filter', async function () {
161 await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { state: 'toto' } }) 144 await makeGetRequest({ url: server.url, path, token: userToken, query: { state: 'toto' } })
162 await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { state: 0 } }) 145 await makeGetRequest({ url: server.url, path, token: userToken, query: { state: 0 } })
163 }) 146 })
164 147
165 it('Should succeed with the correct params', async function () { 148 it('Should succeed with the correct params', async function () {
@@ -168,7 +151,7 @@ describe('Test abuses API validators', function () {
168 state: 2 151 state: 2
169 } 152 }
170 153
171 await makeGetRequest({ url: server.url, path, token: userAccessToken, query, statusCodeExpected: HttpStatusCode.OK_200 }) 154 await makeGetRequest({ url: server.url, path, token: userToken, query, expectedStatus: HttpStatusCode.OK_200 })
172 }) 155 })
173 }) 156 })
174 157
@@ -177,12 +160,12 @@ describe('Test abuses API validators', function () {
177 160
178 it('Should fail with nothing', async function () { 161 it('Should fail with nothing', async function () {
179 const fields = {} 162 const fields = {}
180 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) 163 await makePostBodyRequest({ url: server.url, path, token: userToken, fields })
181 }) 164 })
182 165
183 it('Should fail with a wrong video', async function () { 166 it('Should fail with a wrong video', async function () {
184 const fields = { video: { id: 'blabla' }, reason: 'my super reason' } 167 const fields = { video: { id: 'blabla' }, reason: 'my super reason' }
185 await makePostBodyRequest({ url: server.url, path: path, token: userAccessToken, fields }) 168 await makePostBodyRequest({ url: server.url, path: path, token: userToken, fields })
186 }) 169 })
187 170
188 it('Should fail with an unknown video', async function () { 171 it('Should fail with an unknown video', async function () {
@@ -190,15 +173,15 @@ describe('Test abuses API validators', function () {
190 await makePostBodyRequest({ 173 await makePostBodyRequest({
191 url: server.url, 174 url: server.url,
192 path, 175 path,
193 token: userAccessToken, 176 token: userToken,
194 fields, 177 fields,
195 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 178 expectedStatus: HttpStatusCode.NOT_FOUND_404
196 }) 179 })
197 }) 180 })
198 181
199 it('Should fail with a wrong comment', async function () { 182 it('Should fail with a wrong comment', async function () {
200 const fields = { comment: { id: 'blabla' }, reason: 'my super reason' } 183 const fields = { comment: { id: 'blabla' }, reason: 'my super reason' }
201 await makePostBodyRequest({ url: server.url, path: path, token: userAccessToken, fields }) 184 await makePostBodyRequest({ url: server.url, path: path, token: userToken, fields })
202 }) 185 })
203 186
204 it('Should fail with an unknown comment', async function () { 187 it('Should fail with an unknown comment', async function () {
@@ -206,15 +189,15 @@ describe('Test abuses API validators', function () {
206 await makePostBodyRequest({ 189 await makePostBodyRequest({
207 url: server.url, 190 url: server.url,
208 path, 191 path,
209 token: userAccessToken, 192 token: userToken,
210 fields, 193 fields,
211 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 194 expectedStatus: HttpStatusCode.NOT_FOUND_404
212 }) 195 })
213 }) 196 })
214 197
215 it('Should fail with a wrong account', async function () { 198 it('Should fail with a wrong account', async function () {
216 const fields = { account: { id: 'blabla' }, reason: 'my super reason' } 199 const fields = { account: { id: 'blabla' }, reason: 'my super reason' }
217 await makePostBodyRequest({ url: server.url, path: path, token: userAccessToken, fields }) 200 await makePostBodyRequest({ url: server.url, path: path, token: userToken, fields })
218 }) 201 })
219 202
220 it('Should fail with an unknown account', async function () { 203 it('Should fail with an unknown account', async function () {
@@ -222,9 +205,9 @@ describe('Test abuses API validators', function () {
222 await makePostBodyRequest({ 205 await makePostBodyRequest({
223 url: server.url, 206 url: server.url,
224 path, 207 path,
225 token: userAccessToken, 208 token: userToken,
226 fields, 209 fields,
227 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 210 expectedStatus: HttpStatusCode.NOT_FOUND_404
228 }) 211 })
229 }) 212 })
230 213
@@ -233,65 +216,65 @@ describe('Test abuses API validators', function () {
233 await makePostBodyRequest({ 216 await makePostBodyRequest({
234 url: server.url, 217 url: server.url,
235 path, 218 path,
236 token: userAccessToken, 219 token: userToken,
237 fields, 220 fields,
238 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 221 expectedStatus: HttpStatusCode.BAD_REQUEST_400
239 }) 222 })
240 }) 223 })
241 224
242 it('Should fail with a non authenticated user', async function () { 225 it('Should fail with a non authenticated user', async function () {
243 const fields = { video: { id: server.video.id }, reason: 'my super reason' } 226 const fields = { video: { id: server.store.video.id }, reason: 'my super reason' }
244 227
245 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) 228 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
246 }) 229 })
247 230
248 it('Should fail with a reason too short', async function () { 231 it('Should fail with a reason too short', async function () {
249 const fields = { video: { id: server.video.id }, reason: 'h' } 232 const fields = { video: { id: server.store.video.id }, reason: 'h' }
250 233
251 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) 234 await makePostBodyRequest({ url: server.url, path, token: userToken, fields })
252 }) 235 })
253 236
254 it('Should fail with a too big reason', async function () { 237 it('Should fail with a too big reason', async function () {
255 const fields = { video: { id: server.video.id }, reason: 'super'.repeat(605) } 238 const fields = { video: { id: server.store.video.id }, reason: 'super'.repeat(605) }
256 239
257 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) 240 await makePostBodyRequest({ url: server.url, path, token: userToken, fields })
258 }) 241 })
259 242
260 it('Should succeed with the correct parameters (basic)', async function () { 243 it('Should succeed with the correct parameters (basic)', async function () {
261 const fields: AbuseCreate = { video: { id: server.video.shortUUID }, reason: 'my super reason' } 244 const fields: AbuseCreate = { video: { id: server.store.video.shortUUID }, reason: 'my super reason' }
262 245
263 const res = await makePostBodyRequest({ 246 const res = await makePostBodyRequest({
264 url: server.url, 247 url: server.url,
265 path, 248 path,
266 token: userAccessToken, 249 token: userToken,
267 fields, 250 fields,
268 statusCodeExpected: HttpStatusCode.OK_200 251 expectedStatus: HttpStatusCode.OK_200
269 }) 252 })
270 abuseId = res.body.abuse.id 253 abuseId = res.body.abuse.id
271 }) 254 })
272 255
273 it('Should fail with a wrong predefined reason', async function () { 256 it('Should fail with a wrong predefined reason', async function () {
274 const fields = { video: { id: server.video.id }, reason: 'my super reason', predefinedReasons: [ 'wrongPredefinedReason' ] } 257 const fields = { video: { id: server.store.video.id }, reason: 'my super reason', predefinedReasons: [ 'wrongPredefinedReason' ] }
275 258
276 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) 259 await makePostBodyRequest({ url: server.url, path, token: userToken, fields })
277 }) 260 })
278 261
279 it('Should fail with negative timestamps', async function () { 262 it('Should fail with negative timestamps', async function () {
280 const fields = { video: { id: server.video.id, startAt: -1 }, reason: 'my super reason' } 263 const fields = { video: { id: server.store.video.id, startAt: -1 }, reason: 'my super reason' }
281 264
282 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) 265 await makePostBodyRequest({ url: server.url, path, token: userToken, fields })
283 }) 266 })
284 267
285 it('Should fail mith misordered startAt/endAt', async function () { 268 it('Should fail mith misordered startAt/endAt', async function () {
286 const fields = { video: { id: server.video.id, startAt: 5, endAt: 1 }, reason: 'my super reason' } 269 const fields = { video: { id: server.store.video.id, startAt: 5, endAt: 1 }, reason: 'my super reason' }
287 270
288 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) 271 await makePostBodyRequest({ url: server.url, path, token: userToken, fields })
289 }) 272 })
290 273
291 it('Should succeed with the corret parameters (advanced)', async function () { 274 it('Should succeed with the corret parameters (advanced)', async function () {
292 const fields: AbuseCreate = { 275 const fields: AbuseCreate = {
293 video: { 276 video: {
294 id: server.video.id, 277 id: server.store.video.id,
295 startAt: 1, 278 startAt: 1,
296 endAt: 5 279 endAt: 5
297 }, 280 },
@@ -299,37 +282,37 @@ describe('Test abuses API validators', function () {
299 predefinedReasons: [ 'serverRules' ] 282 predefinedReasons: [ 'serverRules' ]
300 } 283 }
301 284
302 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: HttpStatusCode.OK_200 }) 285 await makePostBodyRequest({ url: server.url, path, token: userToken, fields, expectedStatus: HttpStatusCode.OK_200 })
303 }) 286 })
304 }) 287 })
305 288
306 describe('When updating an abuse', function () { 289 describe('When updating an abuse', function () {
307 290
308 it('Should fail with a non authenticated user', async function () { 291 it('Should fail with a non authenticated user', async function () {
309 await updateAbuse(server.url, 'blabla', abuseId, {}, HttpStatusCode.UNAUTHORIZED_401) 292 await command.update({ token: 'blabla', abuseId, body: {}, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
310 }) 293 })
311 294
312 it('Should fail with a non admin user', async function () { 295 it('Should fail with a non admin user', async function () {
313 await updateAbuse(server.url, userAccessToken, abuseId, {}, HttpStatusCode.FORBIDDEN_403) 296 await command.update({ token: userToken, abuseId, body: {}, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
314 }) 297 })
315 298
316 it('Should fail with a bad abuse id', async function () { 299 it('Should fail with a bad abuse id', async function () {
317 await updateAbuse(server.url, server.accessToken, 45, {}, HttpStatusCode.NOT_FOUND_404) 300 await command.update({ abuseId: 45, body: {}, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
318 }) 301 })
319 302
320 it('Should fail with a bad state', async function () { 303 it('Should fail with a bad state', async function () {
321 const body = { state: 5 } 304 const body = { state: 5 }
322 await updateAbuse(server.url, server.accessToken, abuseId, body, HttpStatusCode.BAD_REQUEST_400) 305 await command.update({ abuseId, body, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
323 }) 306 })
324 307
325 it('Should fail with a bad moderation comment', async function () { 308 it('Should fail with a bad moderation comment', async function () {
326 const body = { moderationComment: 'b'.repeat(3001) } 309 const body = { moderationComment: 'b'.repeat(3001) }
327 await updateAbuse(server.url, server.accessToken, abuseId, body, HttpStatusCode.BAD_REQUEST_400) 310 await command.update({ abuseId, body, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
328 }) 311 })
329 312
330 it('Should succeed with the correct params', async function () { 313 it('Should succeed with the correct params', async function () {
331 const body = { state: AbuseState.ACCEPTED } 314 const body = { state: AbuseState.ACCEPTED }
332 await updateAbuse(server.url, server.accessToken, abuseId, body) 315 await command.update({ abuseId, body })
333 }) 316 })
334 }) 317 })
335 318
@@ -337,23 +320,23 @@ describe('Test abuses API validators', function () {
337 const message = 'my super message' 320 const message = 'my super message'
338 321
339 it('Should fail with an invalid abuse id', async function () { 322 it('Should fail with an invalid abuse id', async function () {
340 await addAbuseMessage(server.url, userAccessToken2, 888, message, HttpStatusCode.NOT_FOUND_404) 323 await command.addMessage({ token: userToken2, abuseId: 888, message, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
341 }) 324 })
342 325
343 it('Should fail with a non authenticated user', async function () { 326 it('Should fail with a non authenticated user', async function () {
344 await addAbuseMessage(server.url, 'fake_token', abuseId, message, HttpStatusCode.UNAUTHORIZED_401) 327 await command.addMessage({ token: 'fake_token', abuseId, message, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
345 }) 328 })
346 329
347 it('Should fail with an invalid logged in user', async function () { 330 it('Should fail with an invalid logged in user', async function () {
348 await addAbuseMessage(server.url, userAccessToken2, abuseId, message, HttpStatusCode.FORBIDDEN_403) 331 await command.addMessage({ token: userToken2, abuseId, message, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
349 }) 332 })
350 333
351 it('Should fail with an invalid message', async function () { 334 it('Should fail with an invalid message', async function () {
352 await addAbuseMessage(server.url, userAccessToken, abuseId, 'a'.repeat(5000), HttpStatusCode.BAD_REQUEST_400) 335 await command.addMessage({ token: userToken, abuseId, message: 'a'.repeat(5000), expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
353 }) 336 })
354 337
355 it('Should suceed with the correct params', async function () { 338 it('Should suceed with the correct params', async function () {
356 const res = await addAbuseMessage(server.url, userAccessToken, abuseId, message) 339 const res = await command.addMessage({ token: userToken, abuseId, message })
357 messageId = res.body.abuseMessage.id 340 messageId = res.body.abuseMessage.id
358 }) 341 })
359 }) 342 })
@@ -361,96 +344,90 @@ describe('Test abuses API validators', function () {
361 describe('When listing abuse messages', function () { 344 describe('When listing abuse messages', function () {
362 345
363 it('Should fail with an invalid abuse id', async function () { 346 it('Should fail with an invalid abuse id', async function () {
364 await listAbuseMessages(server.url, userAccessToken, 888, HttpStatusCode.NOT_FOUND_404) 347 await command.listMessages({ token: userToken, abuseId: 888, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
365 }) 348 })
366 349
367 it('Should fail with a non authenticated user', async function () { 350 it('Should fail with a non authenticated user', async function () {
368 await listAbuseMessages(server.url, 'fake_token', abuseId, HttpStatusCode.UNAUTHORIZED_401) 351 await command.listMessages({ token: 'fake_token', abuseId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
369 }) 352 })
370 353
371 it('Should fail with an invalid logged in user', async function () { 354 it('Should fail with an invalid logged in user', async function () {
372 await listAbuseMessages(server.url, userAccessToken2, abuseId, HttpStatusCode.FORBIDDEN_403) 355 await command.listMessages({ token: userToken2, abuseId, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
373 }) 356 })
374 357
375 it('Should succeed with the correct params', async function () { 358 it('Should succeed with the correct params', async function () {
376 await listAbuseMessages(server.url, userAccessToken, abuseId) 359 await command.listMessages({ token: userToken, abuseId })
377 }) 360 })
378 }) 361 })
379 362
380 describe('When deleting an abuse message', function () { 363 describe('When deleting an abuse message', function () {
381
382 it('Should fail with an invalid abuse id', async function () { 364 it('Should fail with an invalid abuse id', async function () {
383 await deleteAbuseMessage(server.url, userAccessToken, 888, messageId, HttpStatusCode.NOT_FOUND_404) 365 await command.deleteMessage({ token: userToken, abuseId: 888, messageId, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
384 }) 366 })
385 367
386 it('Should fail with an invalid message id', async function () { 368 it('Should fail with an invalid message id', async function () {
387 await deleteAbuseMessage(server.url, userAccessToken, abuseId, 888, HttpStatusCode.NOT_FOUND_404) 369 await command.deleteMessage({ token: userToken, abuseId, messageId: 888, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
388 }) 370 })
389 371
390 it('Should fail with a non authenticated user', async function () { 372 it('Should fail with a non authenticated user', async function () {
391 await deleteAbuseMessage(server.url, 'fake_token', abuseId, messageId, HttpStatusCode.UNAUTHORIZED_401) 373 await command.deleteMessage({ token: 'fake_token', abuseId, messageId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
392 }) 374 })
393 375
394 it('Should fail with an invalid logged in user', async function () { 376 it('Should fail with an invalid logged in user', async function () {
395 await deleteAbuseMessage(server.url, userAccessToken2, abuseId, messageId, HttpStatusCode.FORBIDDEN_403) 377 await command.deleteMessage({ token: userToken2, abuseId, messageId, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
396 }) 378 })
397 379
398 it('Should succeed with the correct params', async function () { 380 it('Should succeed with the correct params', async function () {
399 await deleteAbuseMessage(server.url, userAccessToken, abuseId, messageId) 381 await command.deleteMessage({ token: userToken, abuseId, messageId })
400 }) 382 })
401 }) 383 })
402 384
403 describe('When deleting a video abuse', function () { 385 describe('When deleting a video abuse', function () {
404 386
405 it('Should fail with a non authenticated user', async function () { 387 it('Should fail with a non authenticated user', async function () {
406 await deleteAbuse(server.url, 'blabla', abuseId, HttpStatusCode.UNAUTHORIZED_401) 388 await command.delete({ token: 'blabla', abuseId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
407 }) 389 })
408 390
409 it('Should fail with a non admin user', async function () { 391 it('Should fail with a non admin user', async function () {
410 await deleteAbuse(server.url, userAccessToken, abuseId, HttpStatusCode.FORBIDDEN_403) 392 await command.delete({ token: userToken, abuseId, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
411 }) 393 })
412 394
413 it('Should fail with a bad abuse id', async function () { 395 it('Should fail with a bad abuse id', async function () {
414 await deleteAbuse(server.url, server.accessToken, 45, HttpStatusCode.NOT_FOUND_404) 396 await command.delete({ abuseId: 45, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
415 }) 397 })
416 398
417 it('Should succeed with the correct params', async function () { 399 it('Should succeed with the correct params', async function () {
418 await deleteAbuse(server.url, server.accessToken, abuseId) 400 await command.delete({ abuseId })
419 }) 401 })
420 }) 402 })
421 403
422 describe('When trying to manage messages of a remote abuse', function () { 404 describe('When trying to manage messages of a remote abuse', function () {
423 let remoteAbuseId: number 405 let remoteAbuseId: number
424 let anotherServer: ServerInfo 406 let anotherServer: PeerTubeServer
425 407
426 before(async function () { 408 before(async function () {
427 this.timeout(50000) 409 this.timeout(50000)
428 410
429 anotherServer = await flushAndRunServer(2) 411 anotherServer = await createSingleServer(2)
430 await setAccessTokensToServers([ anotherServer ]) 412 await setAccessTokensToServers([ anotherServer ])
431 413
432 await doubleFollow(anotherServer, server) 414 await doubleFollow(anotherServer, server)
433 415
434 const server2VideoId = await getVideoIdFromUUID(anotherServer.url, server.video.uuid) 416 const server2VideoId = await anotherServer.videos.getId({ uuid: server.store.video.uuid })
435 await reportAbuse({ 417 await anotherServer.abuses.report({ reason: 'remote server', videoId: server2VideoId })
436 url: anotherServer.url,
437 token: anotherServer.accessToken,
438 reason: 'remote server',
439 videoId: server2VideoId
440 })
441 418
442 await waitJobs([ server, anotherServer ]) 419 await waitJobs([ server, anotherServer ])
443 420
444 const res = await getAdminAbusesList({ url: server.url, token: server.accessToken, sort: '-createdAt' }) 421 const body = await command.getAdminList({ sort: '-createdAt' })
445 remoteAbuseId = res.body.data[0].id 422 remoteAbuseId = body.data[0].id
446 }) 423 })
447 424
448 it('Should fail when listing abuse messages of a remote abuse', async function () { 425 it('Should fail when listing abuse messages of a remote abuse', async function () {
449 await listAbuseMessages(server.url, server.accessToken, remoteAbuseId, HttpStatusCode.BAD_REQUEST_400) 426 await command.listMessages({ abuseId: remoteAbuseId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
450 }) 427 })
451 428
452 it('Should fail when creating abuse message of a remote abuse', async function () { 429 it('Should fail when creating abuse message of a remote abuse', async function () {
453 await addAbuseMessage(server.url, server.accessToken, remoteAbuseId, 'message', HttpStatusCode.BAD_REQUEST_400) 430 await command.addMessage({ abuseId: remoteAbuseId, message: 'message', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
454 }) 431 })
455 432
456 after(async function () { 433 after(async function () {