aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params/abuses.ts
diff options
context:
space:
mode:
authorRigel Kent <sendmemail@rigelk.eu>2020-12-07 14:32:36 +0100
committerGitHub <noreply@github.com>2020-12-07 14:32:36 +0100
commit2d53be0267acc49cda46707b885096193a1f4e9c (patch)
tree887061a34bc67f40acbb96a6278f9544bf83caeb /server/tests/api/check-params/abuses.ts
parentadc1f09c0dbd997f34028c1c82d1c118dc8ead80 (diff)
downloadPeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.gz
PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.tar.zst
PeerTube-2d53be0267acc49cda46707b885096193a1f4e9c.zip
replace numbers with typed http status codes (#3409)
Diffstat (limited to 'server/tests/api/check-params/abuses.ts')
-rw-r--r--server/tests/api/check-params/abuses.ts97
1 files changed, 64 insertions, 33 deletions
diff --git a/server/tests/api/check-params/abuses.ts b/server/tests/api/check-params/abuses.ts
index 8dadd9922..ef6c66b72 100644
--- a/server/tests/api/check-params/abuses.ts
+++ b/server/tests/api/check-params/abuses.ts
@@ -29,6 +29,7 @@ import {
29 checkBadSortPagination, 29 checkBadSortPagination,
30 checkBadStartPagination 30 checkBadStartPagination
31} from '../../../../shared/extra-utils/requests/check-api-params' 31} from '../../../../shared/extra-utils/requests/check-api-params'
32import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
32 33
33describe('Test abuses API validators', function () { 34describe('Test abuses API validators', function () {
34 const basePath = '/api/v1/abuses/' 35 const basePath = '/api/v1/abuses/'
@@ -81,7 +82,7 @@ describe('Test abuses API validators', function () {
81 await makeGetRequest({ 82 await makeGetRequest({
82 url: server.url, 83 url: server.url,
83 path, 84 path,
84 statusCodeExpected: 401 85 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
85 }) 86 })
86 }) 87 })
87 88
@@ -90,7 +91,7 @@ describe('Test abuses API validators', function () {
90 url: server.url, 91 url: server.url,
91 path, 92 path,
92 token: userAccessToken, 93 token: userAccessToken,
93 statusCodeExpected: 403 94 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
94 }) 95 })
95 }) 96 })
96 97
@@ -125,7 +126,7 @@ describe('Test abuses API validators', function () {
125 videoIs: 'deleted' 126 videoIs: 'deleted'
126 } 127 }
127 128
128 await makeGetRequest({ url: server.url, path, token: server.accessToken, query, statusCodeExpected: 200 }) 129 await makeGetRequest({ url: server.url, path, token: server.accessToken, query, statusCodeExpected: HttpStatusCode.OK_200 })
129 }) 130 })
130 }) 131 })
131 132
@@ -148,7 +149,7 @@ describe('Test abuses API validators', function () {
148 await makeGetRequest({ 149 await makeGetRequest({
149 url: server.url, 150 url: server.url,
150 path, 151 path,
151 statusCodeExpected: 401 152 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
152 }) 153 })
153 }) 154 })
154 155
@@ -167,7 +168,7 @@ describe('Test abuses API validators', function () {
167 state: 2 168 state: 2
168 } 169 }
169 170
170 await makeGetRequest({ url: server.url, path, token: userAccessToken, query, statusCodeExpected: 200 }) 171 await makeGetRequest({ url: server.url, path, token: userAccessToken, query, statusCodeExpected: HttpStatusCode.OK_200 })
171 }) 172 })
172 }) 173 })
173 174
@@ -186,7 +187,13 @@ describe('Test abuses API validators', function () {
186 187
187 it('Should fail with an unknown video', async function () { 188 it('Should fail with an unknown video', async function () {
188 const fields = { video: { id: 42 }, reason: 'my super reason' } 189 const fields = { video: { id: 42 }, reason: 'my super reason' }
189 await makePostBodyRequest({ url: server.url, path: path, token: userAccessToken, fields, statusCodeExpected: 404 }) 190 await makePostBodyRequest({
191 url: server.url,
192 path,
193 token: userAccessToken,
194 fields,
195 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
196 })
190 }) 197 })
191 198
192 it('Should fail with a wrong comment', async function () { 199 it('Should fail with a wrong comment', async function () {
@@ -196,7 +203,13 @@ describe('Test abuses API validators', function () {
196 203
197 it('Should fail with an unknown comment', async function () { 204 it('Should fail with an unknown comment', async function () {
198 const fields = { comment: { id: 42 }, reason: 'my super reason' } 205 const fields = { comment: { id: 42 }, reason: 'my super reason' }
199 await makePostBodyRequest({ url: server.url, path: path, token: userAccessToken, fields, statusCodeExpected: 404 }) 206 await makePostBodyRequest({
207 url: server.url,
208 path,
209 token: userAccessToken,
210 fields,
211 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
212 })
200 }) 213 })
201 214
202 it('Should fail with a wrong account', async function () { 215 it('Should fail with a wrong account', async function () {
@@ -206,18 +219,30 @@ describe('Test abuses API validators', function () {
206 219
207 it('Should fail with an unknown account', async function () { 220 it('Should fail with an unknown account', async function () {
208 const fields = { account: { id: 42 }, reason: 'my super reason' } 221 const fields = { account: { id: 42 }, reason: 'my super reason' }
209 await makePostBodyRequest({ url: server.url, path: path, token: userAccessToken, fields, statusCodeExpected: 404 }) 222 await makePostBodyRequest({
223 url: server.url,
224 path,
225 token: userAccessToken,
226 fields,
227 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
228 })
210 }) 229 })
211 230
212 it('Should fail with not account, comment or video', async function () { 231 it('Should fail with not account, comment or video', async function () {
213 const fields = { reason: 'my super reason' } 232 const fields = { reason: 'my super reason' }
214 await makePostBodyRequest({ url: server.url, path: path, token: userAccessToken, fields, statusCodeExpected: 400 }) 233 await makePostBodyRequest({
234 url: server.url,
235 path,
236 token: userAccessToken,
237 fields,
238 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
239 })
215 }) 240 })
216 241
217 it('Should fail with a non authenticated user', async function () { 242 it('Should fail with a non authenticated user', async function () {
218 const fields = { video: { id: server.video.id }, reason: 'my super reason' } 243 const fields = { video: { id: server.video.id }, reason: 'my super reason' }
219 244
220 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: 401 }) 245 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
221 }) 246 })
222 247
223 it('Should fail with a reason too short', async function () { 248 it('Should fail with a reason too short', async function () {
@@ -235,7 +260,13 @@ describe('Test abuses API validators', function () {
235 it('Should succeed with the correct parameters (basic)', async function () { 260 it('Should succeed with the correct parameters (basic)', async function () {
236 const fields: AbuseCreate = { video: { id: server.video.id }, reason: 'my super reason' } 261 const fields: AbuseCreate = { video: { id: server.video.id }, reason: 'my super reason' }
237 262
238 const res = await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 200 }) 263 const res = await makePostBodyRequest({
264 url: server.url,
265 path,
266 token: userAccessToken,
267 fields,
268 statusCodeExpected: HttpStatusCode.OK_200
269 })
239 abuseId = res.body.abuse.id 270 abuseId = res.body.abuse.id
240 }) 271 })
241 272
@@ -268,32 +299,32 @@ describe('Test abuses API validators', function () {
268 predefinedReasons: [ 'serverRules' ] 299 predefinedReasons: [ 'serverRules' ]
269 } 300 }
270 301
271 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 200 }) 302 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: HttpStatusCode.OK_200 })
272 }) 303 })
273 }) 304 })
274 305
275 describe('When updating an abuse', function () { 306 describe('When updating an abuse', function () {
276 307
277 it('Should fail with a non authenticated user', async function () { 308 it('Should fail with a non authenticated user', async function () {
278 await updateAbuse(server.url, 'blabla', abuseId, {}, 401) 309 await updateAbuse(server.url, 'blabla', abuseId, {}, HttpStatusCode.UNAUTHORIZED_401)
279 }) 310 })
280 311
281 it('Should fail with a non admin user', async function () { 312 it('Should fail with a non admin user', async function () {
282 await updateAbuse(server.url, userAccessToken, abuseId, {}, 403) 313 await updateAbuse(server.url, userAccessToken, abuseId, {}, HttpStatusCode.FORBIDDEN_403)
283 }) 314 })
284 315
285 it('Should fail with a bad abuse id', async function () { 316 it('Should fail with a bad abuse id', async function () {
286 await updateAbuse(server.url, server.accessToken, 45, {}, 404) 317 await updateAbuse(server.url, server.accessToken, 45, {}, HttpStatusCode.NOT_FOUND_404)
287 }) 318 })
288 319
289 it('Should fail with a bad state', async function () { 320 it('Should fail with a bad state', async function () {
290 const body = { state: 5 } 321 const body = { state: 5 }
291 await updateAbuse(server.url, server.accessToken, abuseId, body, 400) 322 await updateAbuse(server.url, server.accessToken, abuseId, body, HttpStatusCode.BAD_REQUEST_400)
292 }) 323 })
293 324
294 it('Should fail with a bad moderation comment', async function () { 325 it('Should fail with a bad moderation comment', async function () {
295 const body = { moderationComment: 'b'.repeat(3001) } 326 const body = { moderationComment: 'b'.repeat(3001) }
296 await updateAbuse(server.url, server.accessToken, abuseId, body, 400) 327 await updateAbuse(server.url, server.accessToken, abuseId, body, HttpStatusCode.BAD_REQUEST_400)
297 }) 328 })
298 329
299 it('Should succeed with the correct params', async function () { 330 it('Should succeed with the correct params', async function () {
@@ -306,19 +337,19 @@ describe('Test abuses API validators', function () {
306 const message = 'my super message' 337 const message = 'my super message'
307 338
308 it('Should fail with an invalid abuse id', async function () { 339 it('Should fail with an invalid abuse id', async function () {
309 await addAbuseMessage(server.url, userAccessToken2, 888, message, 404) 340 await addAbuseMessage(server.url, userAccessToken2, 888, message, HttpStatusCode.NOT_FOUND_404)
310 }) 341 })
311 342
312 it('Should fail with a non authenticated user', async function () { 343 it('Should fail with a non authenticated user', async function () {
313 await addAbuseMessage(server.url, 'fake_token', abuseId, message, 401) 344 await addAbuseMessage(server.url, 'fake_token', abuseId, message, HttpStatusCode.UNAUTHORIZED_401)
314 }) 345 })
315 346
316 it('Should fail with an invalid logged in user', async function () { 347 it('Should fail with an invalid logged in user', async function () {
317 await addAbuseMessage(server.url, userAccessToken2, abuseId, message, 403) 348 await addAbuseMessage(server.url, userAccessToken2, abuseId, message, HttpStatusCode.FORBIDDEN_403)
318 }) 349 })
319 350
320 it('Should fail with an invalid message', async function () { 351 it('Should fail with an invalid message', async function () {
321 await addAbuseMessage(server.url, userAccessToken, abuseId, 'a'.repeat(5000), 400) 352 await addAbuseMessage(server.url, userAccessToken, abuseId, 'a'.repeat(5000), HttpStatusCode.BAD_REQUEST_400)
322 }) 353 })
323 354
324 it('Should suceed with the correct params', async function () { 355 it('Should suceed with the correct params', async function () {
@@ -330,15 +361,15 @@ describe('Test abuses API validators', function () {
330 describe('When listing abuse messages', function () { 361 describe('When listing abuse messages', function () {
331 362
332 it('Should fail with an invalid abuse id', async function () { 363 it('Should fail with an invalid abuse id', async function () {
333 await listAbuseMessages(server.url, userAccessToken, 888, 404) 364 await listAbuseMessages(server.url, userAccessToken, 888, HttpStatusCode.NOT_FOUND_404)
334 }) 365 })
335 366
336 it('Should fail with a non authenticated user', async function () { 367 it('Should fail with a non authenticated user', async function () {
337 await listAbuseMessages(server.url, 'fake_token', abuseId, 401) 368 await listAbuseMessages(server.url, 'fake_token', abuseId, HttpStatusCode.UNAUTHORIZED_401)
338 }) 369 })
339 370
340 it('Should fail with an invalid logged in user', async function () { 371 it('Should fail with an invalid logged in user', async function () {
341 await listAbuseMessages(server.url, userAccessToken2, abuseId, 403) 372 await listAbuseMessages(server.url, userAccessToken2, abuseId, HttpStatusCode.FORBIDDEN_403)
342 }) 373 })
343 374
344 it('Should succeed with the correct params', async function () { 375 it('Should succeed with the correct params', async function () {
@@ -349,19 +380,19 @@ describe('Test abuses API validators', function () {
349 describe('When deleting an abuse message', function () { 380 describe('When deleting an abuse message', function () {
350 381
351 it('Should fail with an invalid abuse id', async function () { 382 it('Should fail with an invalid abuse id', async function () {
352 await deleteAbuseMessage(server.url, userAccessToken, 888, messageId, 404) 383 await deleteAbuseMessage(server.url, userAccessToken, 888, messageId, HttpStatusCode.NOT_FOUND_404)
353 }) 384 })
354 385
355 it('Should fail with an invalid message id', async function () { 386 it('Should fail with an invalid message id', async function () {
356 await deleteAbuseMessage(server.url, userAccessToken, abuseId, 888, 404) 387 await deleteAbuseMessage(server.url, userAccessToken, abuseId, 888, HttpStatusCode.NOT_FOUND_404)
357 }) 388 })
358 389
359 it('Should fail with a non authenticated user', async function () { 390 it('Should fail with a non authenticated user', async function () {
360 await deleteAbuseMessage(server.url, 'fake_token', abuseId, messageId, 401) 391 await deleteAbuseMessage(server.url, 'fake_token', abuseId, messageId, HttpStatusCode.UNAUTHORIZED_401)
361 }) 392 })
362 393
363 it('Should fail with an invalid logged in user', async function () { 394 it('Should fail with an invalid logged in user', async function () {
364 await deleteAbuseMessage(server.url, userAccessToken2, abuseId, messageId, 403) 395 await deleteAbuseMessage(server.url, userAccessToken2, abuseId, messageId, HttpStatusCode.FORBIDDEN_403)
365 }) 396 })
366 397
367 it('Should succeed with the correct params', async function () { 398 it('Should succeed with the correct params', async function () {
@@ -372,15 +403,15 @@ describe('Test abuses API validators', function () {
372 describe('When deleting a video abuse', function () { 403 describe('When deleting a video abuse', function () {
373 404
374 it('Should fail with a non authenticated user', async function () { 405 it('Should fail with a non authenticated user', async function () {
375 await deleteAbuse(server.url, 'blabla', abuseId, 401) 406 await deleteAbuse(server.url, 'blabla', abuseId, HttpStatusCode.UNAUTHORIZED_401)
376 }) 407 })
377 408
378 it('Should fail with a non admin user', async function () { 409 it('Should fail with a non admin user', async function () {
379 await deleteAbuse(server.url, userAccessToken, abuseId, 403) 410 await deleteAbuse(server.url, userAccessToken, abuseId, HttpStatusCode.FORBIDDEN_403)
380 }) 411 })
381 412
382 it('Should fail with a bad abuse id', async function () { 413 it('Should fail with a bad abuse id', async function () {
383 await deleteAbuse(server.url, server.accessToken, 45, 404) 414 await deleteAbuse(server.url, server.accessToken, 45, HttpStatusCode.NOT_FOUND_404)
384 }) 415 })
385 416
386 it('Should succeed with the correct params', async function () { 417 it('Should succeed with the correct params', async function () {
@@ -415,11 +446,11 @@ describe('Test abuses API validators', function () {
415 }) 446 })
416 447
417 it('Should fail when listing abuse messages of a remote abuse', async function () { 448 it('Should fail when listing abuse messages of a remote abuse', async function () {
418 await listAbuseMessages(server.url, server.accessToken, remoteAbuseId, 400) 449 await listAbuseMessages(server.url, server.accessToken, remoteAbuseId, HttpStatusCode.BAD_REQUEST_400)
419 }) 450 })
420 451
421 it('Should fail when creating abuse message of a remote abuse', async function () { 452 it('Should fail when creating abuse message of a remote abuse', async function () {
422 await addAbuseMessage(server.url, server.accessToken, remoteAbuseId, 'message', 400) 453 await addAbuseMessage(server.url, server.accessToken, remoteAbuseId, 'message', HttpStatusCode.BAD_REQUEST_400)
423 }) 454 })
424 455
425 after(async function () { 456 after(async function () {