aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/activitypub/security.ts17
-rw-r--r--server/tests/api/check-params/abuses.ts97
-rw-r--r--server/tests/api/check-params/blocklist.ts77
-rw-r--r--server/tests/api/check-params/bulk.ts11
-rw-r--r--server/tests/api/check-params/config.ts23
-rw-r--r--server/tests/api/check-params/debug.ts7
-rw-r--r--server/tests/api/check-params/follows.ts49
-rw-r--r--server/tests/api/check-params/jobs.ts5
-rw-r--r--server/tests/api/check-params/live.ts43
-rw-r--r--server/tests/api/check-params/logs.ts15
-rw-r--r--server/tests/api/check-params/plugins.ts69
-rw-r--r--server/tests/api/check-params/redundancy.ts33
-rw-r--r--server/tests/api/check-params/search.ts59
-rw-r--r--server/tests/api/check-params/services.ts17
-rw-r--r--server/tests/api/check-params/user-notifications.ts31
-rw-r--r--server/tests/api/check-params/user-subscriptions.ts51
-rw-r--r--server/tests/api/check-params/users.ts210
-rw-r--r--server/tests/api/check-params/video-blacklist.ts82
-rw-r--r--server/tests/api/check-params/video-captions.ts41
-rw-r--r--server/tests/api/check-params/video-channels.ts35
-rw-r--r--server/tests/api/check-params/video-comments.ts109
-rw-r--r--server/tests/api/check-params/video-imports.ts32
-rw-r--r--server/tests/api/check-params/video-playlists.ts114
-rw-r--r--server/tests/api/check-params/videos-filter.ts23
-rw-r--r--server/tests/api/check-params/videos-history.ts47
-rw-r--r--server/tests/api/check-params/videos.ts57
-rw-r--r--server/tests/api/redundancy/redundancy.ts5
-rw-r--r--server/tests/api/users/users.ts49
-rw-r--r--server/tests/api/videos/video-transcoder.ts11
-rw-r--r--server/tests/api/videos/videos-filter.ts3
-rw-r--r--server/tests/cli/prune-storage.ts5
-rw-r--r--server/tests/client.ts31
-rw-r--r--server/tests/external-plugins/auto-mute.ts7
-rw-r--r--server/tests/misc-endpoints.ts23
-rw-r--r--server/tests/plugins/external-auth.ts47
-rw-r--r--server/tests/plugins/plugin-helpers.ts3
-rw-r--r--server/tests/plugins/plugin-router.ts9
37 files changed, 937 insertions, 610 deletions
diff --git a/server/tests/api/activitypub/security.ts b/server/tests/api/activitypub/security.ts
index e6002b661..55dcced15 100644
--- a/server/tests/api/activitypub/security.ts
+++ b/server/tests/api/activitypub/security.ts
@@ -9,6 +9,7 @@ import * as chai from 'chai'
9import { activityPubContextify, buildSignedActivity } from '../../../helpers/activitypub' 9import { activityPubContextify, buildSignedActivity } from '../../../helpers/activitypub'
10import { makeFollowRequest, makePOSTAPRequest } from '../../../../shared/extra-utils/requests/activitypub' 10import { makeFollowRequest, makePOSTAPRequest } from '../../../../shared/extra-utils/requests/activitypub'
11import { buildDigest } from '@server/helpers/peertube-crypto' 11import { buildDigest } from '@server/helpers/peertube-crypto'
12import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
12 13
13const expect = chai.expect 14const expect = chai.expect
14 15
@@ -74,7 +75,7 @@ describe('Test ActivityPub security', function () {
74 75
75 const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers) 76 const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers)
76 77
77 expect(response.statusCode).to.equal(403) 78 expect(response.statusCode).to.equal(HttpStatusCode.FORBIDDEN_403)
78 }) 79 })
79 80
80 it('Should fail with an invalid date', async function () { 81 it('Should fail with an invalid date', async function () {
@@ -84,7 +85,7 @@ describe('Test ActivityPub security', function () {
84 85
85 const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers) 86 const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers)
86 87
87 expect(response.statusCode).to.equal(403) 88 expect(response.statusCode).to.equal(HttpStatusCode.FORBIDDEN_403)
88 }) 89 })
89 90
90 it('Should fail with bad keys', async function () { 91 it('Should fail with bad keys', async function () {
@@ -96,7 +97,7 @@ describe('Test ActivityPub security', function () {
96 97
97 const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers) 98 const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers)
98 99
99 expect(response.statusCode).to.equal(403) 100 expect(response.statusCode).to.equal(HttpStatusCode.FORBIDDEN_403)
100 }) 101 })
101 102
102 it('Should reject requests without appropriate signed headers', async function () { 103 it('Should reject requests without appropriate signed headers', async function () {
@@ -117,7 +118,7 @@ describe('Test ActivityPub security', function () {
117 signatureOptions.headers = badHeaders 118 signatureOptions.headers = badHeaders
118 119
119 const { response } = await makePOSTAPRequest(url, body, signatureOptions, headers) 120 const { response } = await makePOSTAPRequest(url, body, signatureOptions, headers)
120 expect(response.statusCode).to.equal(403) 121 expect(response.statusCode).to.equal(HttpStatusCode.FORBIDDEN_403)
121 } 122 }
122 }) 123 })
123 124
@@ -127,7 +128,7 @@ describe('Test ActivityPub security', function () {
127 128
128 const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers) 129 const { response } = await makePOSTAPRequest(url, body, baseHttpSignature(), headers)
129 130
130 expect(response.statusCode).to.equal(204) 131 expect(response.statusCode).to.equal(HttpStatusCode.NO_CONTENT_204)
131 }) 132 })
132 }) 133 })
133 134
@@ -156,7 +157,7 @@ describe('Test ActivityPub security', function () {
156 157
157 const { response } = await makePOSTAPRequest(url, signedBody, baseHttpSignature(), headers) 158 const { response } = await makePOSTAPRequest(url, signedBody, baseHttpSignature(), headers)
158 159
159 expect(response.statusCode).to.equal(403) 160 expect(response.statusCode).to.equal(HttpStatusCode.FORBIDDEN_403)
160 }) 161 })
161 162
162 it('Should fail with an altered body', async function () { 163 it('Should fail with an altered body', async function () {
@@ -177,7 +178,7 @@ describe('Test ActivityPub security', function () {
177 178
178 const { response } = await makePOSTAPRequest(url, signedBody, baseHttpSignature(), headers) 179 const { response } = await makePOSTAPRequest(url, signedBody, baseHttpSignature(), headers)
179 180
180 expect(response.statusCode).to.equal(403) 181 expect(response.statusCode).to.equal(HttpStatusCode.FORBIDDEN_403)
181 }) 182 })
182 183
183 it('Should succeed with a valid signature', async function () { 184 it('Should succeed with a valid signature', async function () {
@@ -193,7 +194,7 @@ describe('Test ActivityPub security', function () {
193 194
194 const { response } = await makePOSTAPRequest(url, signedBody, baseHttpSignature(), headers) 195 const { response } = await makePOSTAPRequest(url, signedBody, baseHttpSignature(), headers)
195 196
196 expect(response.statusCode).to.equal(204) 197 expect(response.statusCode).to.equal(HttpStatusCode.NO_CONTENT_204)
197 }) 198 })
198 }) 199 })
199 200
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 () {
diff --git a/server/tests/api/check-params/blocklist.ts b/server/tests/api/check-params/blocklist.ts
index 1219ec9bd..5ed8810ce 100644
--- a/server/tests/api/check-params/blocklist.ts
+++ b/server/tests/api/check-params/blocklist.ts
@@ -19,6 +19,7 @@ import {
19 checkBadSortPagination, 19 checkBadSortPagination,
20 checkBadStartPagination 20 checkBadStartPagination
21} from '../../../../shared/extra-utils/requests/check-api-params' 21} from '../../../../shared/extra-utils/requests/check-api-params'
22import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
22 23
23describe('Test blocklist API validators', function () { 24describe('Test blocklist API validators', function () {
24 let servers: ServerInfo[] 25 let servers: ServerInfo[]
@@ -53,7 +54,7 @@ describe('Test blocklist API validators', function () {
53 await makeGetRequest({ 54 await makeGetRequest({
54 url: server.url, 55 url: server.url,
55 path, 56 path,
56 statusCodeExpected: 401 57 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
57 }) 58 })
58 }) 59 })
59 60
@@ -76,7 +77,7 @@ describe('Test blocklist API validators', function () {
76 url: server.url, 77 url: server.url,
77 path, 78 path,
78 fields: { accountName: 'user1' }, 79 fields: { accountName: 'user1' },
79 statusCodeExpected: 401 80 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
80 }) 81 })
81 }) 82 })
82 83
@@ -86,7 +87,7 @@ describe('Test blocklist API validators', function () {
86 token: server.accessToken, 87 token: server.accessToken,
87 path, 88 path,
88 fields: { accountName: 'user2' }, 89 fields: { accountName: 'user2' },
89 statusCodeExpected: 404 90 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
90 }) 91 })
91 }) 92 })
92 93
@@ -96,7 +97,7 @@ describe('Test blocklist API validators', function () {
96 token: server.accessToken, 97 token: server.accessToken,
97 path, 98 path,
98 fields: { accountName: 'root' }, 99 fields: { accountName: 'root' },
99 statusCodeExpected: 409 100 statusCodeExpected: HttpStatusCode.CONFLICT_409
100 }) 101 })
101 }) 102 })
102 103
@@ -106,7 +107,7 @@ describe('Test blocklist API validators', function () {
106 token: server.accessToken, 107 token: server.accessToken,
107 path, 108 path,
108 fields: { accountName: 'user1' }, 109 fields: { accountName: 'user1' },
109 statusCodeExpected: 204 110 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
110 }) 111 })
111 }) 112 })
112 }) 113 })
@@ -116,7 +117,7 @@ describe('Test blocklist API validators', function () {
116 await makeDeleteRequest({ 117 await makeDeleteRequest({
117 url: server.url, 118 url: server.url,
118 path: path + '/user1', 119 path: path + '/user1',
119 statusCodeExpected: 401 120 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
120 }) 121 })
121 }) 122 })
122 123
@@ -125,7 +126,7 @@ describe('Test blocklist API validators', function () {
125 url: server.url, 126 url: server.url,
126 path: path + '/user2', 127 path: path + '/user2',
127 token: server.accessToken, 128 token: server.accessToken,
128 statusCodeExpected: 404 129 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
129 }) 130 })
130 }) 131 })
131 132
@@ -134,7 +135,7 @@ describe('Test blocklist API validators', function () {
134 url: server.url, 135 url: server.url,
135 path: path + '/user1', 136 path: path + '/user1',
136 token: server.accessToken, 137 token: server.accessToken,
137 statusCodeExpected: 204 138 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
138 }) 139 })
139 }) 140 })
140 }) 141 })
@@ -148,7 +149,7 @@ describe('Test blocklist 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
@@ -171,7 +172,7 @@ describe('Test blocklist API validators', function () {
171 url: server.url, 172 url: server.url,
172 path, 173 path,
173 fields: { host: 'localhost:9002' }, 174 fields: { host: 'localhost:9002' },
174 statusCodeExpected: 401 175 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
175 }) 176 })
176 }) 177 })
177 178
@@ -181,7 +182,7 @@ describe('Test blocklist API validators', function () {
181 token: server.accessToken, 182 token: server.accessToken,
182 path, 183 path,
183 fields: { host: 'localhost:9003' }, 184 fields: { host: 'localhost:9003' },
184 statusCodeExpected: 204 185 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
185 }) 186 })
186 }) 187 })
187 188
@@ -191,7 +192,7 @@ describe('Test blocklist API validators', function () {
191 token: server.accessToken, 192 token: server.accessToken,
192 path, 193 path,
193 fields: { host: 'localhost:' + server.port }, 194 fields: { host: 'localhost:' + server.port },
194 statusCodeExpected: 409 195 statusCodeExpected: HttpStatusCode.CONFLICT_409
195 }) 196 })
196 }) 197 })
197 198
@@ -201,7 +202,7 @@ describe('Test blocklist API validators', function () {
201 token: server.accessToken, 202 token: server.accessToken,
202 path, 203 path,
203 fields: { host: 'localhost:' + servers[1].port }, 204 fields: { host: 'localhost:' + servers[1].port },
204 statusCodeExpected: 204 205 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
205 }) 206 })
206 }) 207 })
207 }) 208 })
@@ -211,7 +212,7 @@ describe('Test blocklist API validators', function () {
211 await makeDeleteRequest({ 212 await makeDeleteRequest({
212 url: server.url, 213 url: server.url,
213 path: path + '/localhost:' + servers[1].port, 214 path: path + '/localhost:' + servers[1].port,
214 statusCodeExpected: 401 215 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
215 }) 216 })
216 }) 217 })
217 218
@@ -220,7 +221,7 @@ describe('Test blocklist API validators', function () {
220 url: server.url, 221 url: server.url,
221 path: path + '/localhost:9004', 222 path: path + '/localhost:9004',
222 token: server.accessToken, 223 token: server.accessToken,
223 statusCodeExpected: 404 224 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
224 }) 225 })
225 }) 226 })
226 227
@@ -229,7 +230,7 @@ describe('Test blocklist API validators', function () {
229 url: server.url, 230 url: server.url,
230 path: path + '/localhost:' + servers[1].port, 231 path: path + '/localhost:' + servers[1].port,
231 token: server.accessToken, 232 token: server.accessToken,
232 statusCodeExpected: 204 233 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
233 }) 234 })
234 }) 235 })
235 }) 236 })
@@ -246,7 +247,7 @@ describe('Test blocklist API validators', function () {
246 await makeGetRequest({ 247 await makeGetRequest({
247 url: server.url, 248 url: server.url,
248 path, 249 path,
249 statusCodeExpected: 401 250 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
250 }) 251 })
251 }) 252 })
252 253
@@ -255,7 +256,7 @@ describe('Test blocklist API validators', function () {
255 url: server.url, 256 url: server.url,
256 token: userAccessToken, 257 token: userAccessToken,
257 path, 258 path,
258 statusCodeExpected: 403 259 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
259 }) 260 })
260 }) 261 })
261 262
@@ -278,7 +279,7 @@ describe('Test blocklist API validators', function () {
278 url: server.url, 279 url: server.url,
279 path, 280 path,
280 fields: { accountName: 'user1' }, 281 fields: { accountName: 'user1' },
281 statusCodeExpected: 401 282 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
282 }) 283 })
283 }) 284 })
284 285
@@ -288,7 +289,7 @@ describe('Test blocklist API validators', function () {
288 token: userAccessToken, 289 token: userAccessToken,
289 path, 290 path,
290 fields: { accountName: 'user1' }, 291 fields: { accountName: 'user1' },
291 statusCodeExpected: 403 292 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
292 }) 293 })
293 }) 294 })
294 295
@@ -298,7 +299,7 @@ describe('Test blocklist API validators', function () {
298 token: server.accessToken, 299 token: server.accessToken,
299 path, 300 path,
300 fields: { accountName: 'user2' }, 301 fields: { accountName: 'user2' },
301 statusCodeExpected: 404 302 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
302 }) 303 })
303 }) 304 })
304 305
@@ -308,7 +309,7 @@ describe('Test blocklist API validators', function () {
308 token: server.accessToken, 309 token: server.accessToken,
309 path, 310 path,
310 fields: { accountName: 'root' }, 311 fields: { accountName: 'root' },
311 statusCodeExpected: 409 312 statusCodeExpected: HttpStatusCode.CONFLICT_409
312 }) 313 })
313 }) 314 })
314 315
@@ -318,7 +319,7 @@ describe('Test blocklist API validators', function () {
318 token: server.accessToken, 319 token: server.accessToken,
319 path, 320 path,
320 fields: { accountName: 'user1' }, 321 fields: { accountName: 'user1' },
321 statusCodeExpected: 204 322 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
322 }) 323 })
323 }) 324 })
324 }) 325 })
@@ -328,7 +329,7 @@ describe('Test blocklist API validators', function () {
328 await makeDeleteRequest({ 329 await makeDeleteRequest({
329 url: server.url, 330 url: server.url,
330 path: path + '/user1', 331 path: path + '/user1',
331 statusCodeExpected: 401 332 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
332 }) 333 })
333 }) 334 })
334 335
@@ -337,7 +338,7 @@ describe('Test blocklist API validators', function () {
337 url: server.url, 338 url: server.url,
338 path: path + '/user1', 339 path: path + '/user1',
339 token: userAccessToken, 340 token: userAccessToken,
340 statusCodeExpected: 403 341 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
341 }) 342 })
342 }) 343 })
343 344
@@ -346,7 +347,7 @@ describe('Test blocklist API validators', function () {
346 url: server.url, 347 url: server.url,
347 path: path + '/user2', 348 path: path + '/user2',
348 token: server.accessToken, 349 token: server.accessToken,
349 statusCodeExpected: 404 350 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
350 }) 351 })
351 }) 352 })
352 353
@@ -355,7 +356,7 @@ describe('Test blocklist API validators', function () {
355 url: server.url, 356 url: server.url,
356 path: path + '/user1', 357 path: path + '/user1',
357 token: server.accessToken, 358 token: server.accessToken,
358 statusCodeExpected: 204 359 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
359 }) 360 })
360 }) 361 })
361 }) 362 })
@@ -369,7 +370,7 @@ describe('Test blocklist API validators', function () {
369 await makeGetRequest({ 370 await makeGetRequest({
370 url: server.url, 371 url: server.url,
371 path, 372 path,
372 statusCodeExpected: 401 373 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
373 }) 374 })
374 }) 375 })
375 376
@@ -378,7 +379,7 @@ describe('Test blocklist API validators', function () {
378 url: server.url, 379 url: server.url,
379 token: userAccessToken, 380 token: userAccessToken,
380 path, 381 path,
381 statusCodeExpected: 403 382 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
382 }) 383 })
383 }) 384 })
384 385
@@ -401,7 +402,7 @@ describe('Test blocklist API validators', function () {
401 url: server.url, 402 url: server.url,
402 path, 403 path,
403 fields: { host: 'localhost:' + servers[1].port }, 404 fields: { host: 'localhost:' + servers[1].port },
404 statusCodeExpected: 401 405 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
405 }) 406 })
406 }) 407 })
407 408
@@ -411,7 +412,7 @@ describe('Test blocklist API validators', function () {
411 token: userAccessToken, 412 token: userAccessToken,
412 path, 413 path,
413 fields: { host: 'localhost:' + servers[1].port }, 414 fields: { host: 'localhost:' + servers[1].port },
414 statusCodeExpected: 403 415 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
415 }) 416 })
416 }) 417 })
417 418
@@ -421,7 +422,7 @@ describe('Test blocklist API validators', function () {
421 token: server.accessToken, 422 token: server.accessToken,
422 path, 423 path,
423 fields: { host: 'localhost:9003' }, 424 fields: { host: 'localhost:9003' },
424 statusCodeExpected: 204 425 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
425 }) 426 })
426 }) 427 })
427 428
@@ -431,7 +432,7 @@ describe('Test blocklist API validators', function () {
431 token: server.accessToken, 432 token: server.accessToken,
432 path, 433 path,
433 fields: { host: 'localhost:' + server.port }, 434 fields: { host: 'localhost:' + server.port },
434 statusCodeExpected: 409 435 statusCodeExpected: HttpStatusCode.CONFLICT_409
435 }) 436 })
436 }) 437 })
437 438
@@ -441,7 +442,7 @@ describe('Test blocklist API validators', function () {
441 token: server.accessToken, 442 token: server.accessToken,
442 path, 443 path,
443 fields: { host: 'localhost:' + servers[1].port }, 444 fields: { host: 'localhost:' + servers[1].port },
444 statusCodeExpected: 204 445 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
445 }) 446 })
446 }) 447 })
447 }) 448 })
@@ -451,7 +452,7 @@ describe('Test blocklist API validators', function () {
451 await makeDeleteRequest({ 452 await makeDeleteRequest({
452 url: server.url, 453 url: server.url,
453 path: path + '/localhost:' + servers[1].port, 454 path: path + '/localhost:' + servers[1].port,
454 statusCodeExpected: 401 455 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
455 }) 456 })
456 }) 457 })
457 458
@@ -460,7 +461,7 @@ describe('Test blocklist API validators', function () {
460 url: server.url, 461 url: server.url,
461 path: path + '/localhost:' + servers[1].port, 462 path: path + '/localhost:' + servers[1].port,
462 token: userAccessToken, 463 token: userAccessToken,
463 statusCodeExpected: 403 464 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
464 }) 465 })
465 }) 466 })
466 467
@@ -469,7 +470,7 @@ describe('Test blocklist API validators', function () {
469 url: server.url, 470 url: server.url,
470 path: path + '/localhost:9004', 471 path: path + '/localhost:9004',
471 token: server.accessToken, 472 token: server.accessToken,
472 statusCodeExpected: 404 473 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
473 }) 474 })
474 }) 475 })
475 476
@@ -478,7 +479,7 @@ describe('Test blocklist API validators', function () {
478 url: server.url, 479 url: server.url,
479 path: path + '/localhost:' + servers[1].port, 480 path: path + '/localhost:' + servers[1].port,
480 token: server.accessToken, 481 token: server.accessToken,
481 statusCodeExpected: 204 482 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
482 }) 483 })
483 }) 484 })
484 }) 485 })
diff --git a/server/tests/api/check-params/bulk.ts b/server/tests/api/check-params/bulk.ts
index 432858b33..07b920ba7 100644
--- a/server/tests/api/check-params/bulk.ts
+++ b/server/tests/api/check-params/bulk.ts
@@ -10,6 +10,7 @@ import {
10 userLogin 10 userLogin
11} from '../../../../shared/extra-utils' 11} from '../../../../shared/extra-utils'
12import { makePostBodyRequest } from '../../../../shared/extra-utils/requests/requests' 12import { makePostBodyRequest } from '../../../../shared/extra-utils/requests/requests'
13import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
13 14
14describe('Test bulk API validators', function () { 15describe('Test bulk API validators', function () {
15 let server: ServerInfo 16 let server: ServerInfo
@@ -37,7 +38,7 @@ describe('Test bulk API validators', function () {
37 url: server.url, 38 url: server.url,
38 path, 39 path,
39 fields: { accountName: 'user1', scope: 'my-videos' }, 40 fields: { accountName: 'user1', scope: 'my-videos' },
40 statusCodeExpected: 401 41 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
41 }) 42 })
42 }) 43 })
43 44
@@ -47,7 +48,7 @@ describe('Test bulk API validators', function () {
47 token: server.accessToken, 48 token: server.accessToken,
48 path, 49 path,
49 fields: { accountName: 'user2', scope: 'my-videos' }, 50 fields: { accountName: 'user2', scope: 'my-videos' },
50 statusCodeExpected: 404 51 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
51 }) 52 })
52 }) 53 })
53 54
@@ -57,7 +58,7 @@ describe('Test bulk API validators', function () {
57 token: server.accessToken, 58 token: server.accessToken,
58 path, 59 path,
59 fields: { accountName: 'user1', scope: 'my-videoss' }, 60 fields: { accountName: 'user1', scope: 'my-videoss' },
60 statusCodeExpected: 400 61 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
61 }) 62 })
62 }) 63 })
63 64
@@ -67,7 +68,7 @@ describe('Test bulk API validators', function () {
67 token: userAccessToken, 68 token: userAccessToken,
68 path, 69 path,
69 fields: { accountName: 'user1', scope: 'instance' }, 70 fields: { accountName: 'user1', scope: 'instance' },
70 statusCodeExpected: 403 71 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
71 }) 72 })
72 }) 73 })
73 74
@@ -77,7 +78,7 @@ describe('Test bulk API validators', function () {
77 token: server.accessToken, 78 token: server.accessToken,
78 path, 79 path,
79 fields: { accountName: 'user1', scope: 'instance' }, 80 fields: { accountName: 'user1', scope: 'instance' },
80 statusCodeExpected: 204 81 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
81 }) 82 })
82 }) 83 })
83 }) 84 })
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts
index 42ac5e1f9..08576c3ae 100644
--- a/server/tests/api/check-params/config.ts
+++ b/server/tests/api/check-params/config.ts
@@ -16,6 +16,7 @@ import {
16 setAccessTokensToServers, 16 setAccessTokensToServers,
17 userLogin 17 userLogin
18} from '../../../../shared/extra-utils' 18} from '../../../../shared/extra-utils'
19import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
19 20
20describe('Test config API validators', function () { 21describe('Test config API validators', function () {
21 const path = '/api/v1/config/custom' 22 const path = '/api/v1/config/custom'
@@ -197,7 +198,7 @@ describe('Test config API validators', function () {
197 await makeGetRequest({ 198 await makeGetRequest({
198 url: server.url, 199 url: server.url,
199 path, 200 path,
200 statusCodeExpected: 401 201 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
201 }) 202 })
202 }) 203 })
203 204
@@ -206,7 +207,7 @@ describe('Test config API validators', function () {
206 url: server.url, 207 url: server.url,
207 path, 208 path,
208 token: userAccessToken, 209 token: userAccessToken,
209 statusCodeExpected: 403 210 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
210 }) 211 })
211 }) 212 })
212 }) 213 })
@@ -217,7 +218,7 @@ describe('Test config API validators', function () {
217 url: server.url, 218 url: server.url,
218 path, 219 path,
219 fields: updateParams, 220 fields: updateParams,
220 statusCodeExpected: 401 221 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
221 }) 222 })
222 }) 223 })
223 224
@@ -227,7 +228,7 @@ describe('Test config API validators', function () {
227 path, 228 path,
228 fields: updateParams, 229 fields: updateParams,
229 token: userAccessToken, 230 token: userAccessToken,
230 statusCodeExpected: 403 231 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
231 }) 232 })
232 }) 233 })
233 234
@@ -239,7 +240,7 @@ describe('Test config API validators', function () {
239 path, 240 path,
240 fields: newUpdateParams, 241 fields: newUpdateParams,
241 token: server.accessToken, 242 token: server.accessToken,
242 statusCodeExpected: 400 243 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
243 }) 244 })
244 }) 245 })
245 246
@@ -255,7 +256,7 @@ describe('Test config API validators', function () {
255 path, 256 path,
256 fields: newUpdateParams, 257 fields: newUpdateParams,
257 token: server.accessToken, 258 token: server.accessToken,
258 statusCodeExpected: 400 259 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
259 }) 260 })
260 }) 261 })
261 262
@@ -274,7 +275,7 @@ describe('Test config API validators', function () {
274 path, 275 path,
275 fields: newUpdateParams, 276 fields: newUpdateParams,
276 token: server.accessToken, 277 token: server.accessToken,
277 statusCodeExpected: 400 278 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
278 }) 279 })
279 }) 280 })
280 281
@@ -295,7 +296,7 @@ describe('Test config API validators', function () {
295 path, 296 path,
296 fields: newUpdateParams, 297 fields: newUpdateParams,
297 token: server.accessToken, 298 token: server.accessToken,
298 statusCodeExpected: 400 299 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
299 }) 300 })
300 }) 301 })
301 302
@@ -305,7 +306,7 @@ describe('Test config API validators', function () {
305 path, 306 path,
306 fields: updateParams, 307 fields: updateParams,
307 token: server.accessToken, 308 token: server.accessToken,
308 statusCodeExpected: 200 309 statusCodeExpected: HttpStatusCode.OK_200
309 }) 310 })
310 }) 311 })
311 }) 312 })
@@ -315,7 +316,7 @@ describe('Test config API validators', function () {
315 await makeDeleteRequest({ 316 await makeDeleteRequest({
316 url: server.url, 317 url: server.url,
317 path, 318 path,
318 statusCodeExpected: 401 319 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
319 }) 320 })
320 }) 321 })
321 322
@@ -324,7 +325,7 @@ describe('Test config API validators', function () {
324 url: server.url, 325 url: server.url,
325 path, 326 path,
326 token: userAccessToken, 327 token: userAccessToken,
327 statusCodeExpected: 403 328 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
328 }) 329 })
329 }) 330 })
330 }) 331 })
diff --git a/server/tests/api/check-params/debug.ts b/server/tests/api/check-params/debug.ts
index 5fac73485..37bf0f99b 100644
--- a/server/tests/api/check-params/debug.ts
+++ b/server/tests/api/check-params/debug.ts
@@ -11,6 +11,7 @@ import {
11 userLogin 11 userLogin
12} from '../../../../shared/extra-utils' 12} from '../../../../shared/extra-utils'
13import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests' 13import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests'
14import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
14 15
15describe('Test debug API validators', function () { 16describe('Test debug API validators', function () {
16 const path = '/api/v1/server/debug' 17 const path = '/api/v1/server/debug'
@@ -40,7 +41,7 @@ describe('Test debug API validators', function () {
40 await makeGetRequest({ 41 await makeGetRequest({
41 url: server.url, 42 url: server.url,
42 path, 43 path,
43 statusCodeExpected: 401 44 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
44 }) 45 })
45 }) 46 })
46 47
@@ -49,7 +50,7 @@ describe('Test debug API validators', function () {
49 url: server.url, 50 url: server.url,
50 path, 51 path,
51 token: userAccessToken, 52 token: userAccessToken,
52 statusCodeExpected: 403 53 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
53 }) 54 })
54 }) 55 })
55 56
@@ -59,7 +60,7 @@ describe('Test debug API validators', function () {
59 path, 60 path,
60 token: server.accessToken, 61 token: server.accessToken,
61 query: { startDate: new Date().toISOString() }, 62 query: { startDate: new Date().toISOString() },
62 statusCodeExpected: 200 63 statusCodeExpected: HttpStatusCode.OK_200
63 }) 64 })
64 }) 65 })
65 }) 66 })
diff --git a/server/tests/api/check-params/follows.ts b/server/tests/api/check-params/follows.ts
index 2c2224a45..c03dd5c9c 100644
--- a/server/tests/api/check-params/follows.ts
+++ b/server/tests/api/check-params/follows.ts
@@ -17,6 +17,7 @@ import {
17 checkBadSortPagination, 17 checkBadSortPagination,
18 checkBadStartPagination 18 checkBadStartPagination
19} from '../../../../shared/extra-utils/requests/check-api-params' 19} from '../../../../shared/extra-utils/requests/check-api-params'
20import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
20 21
21describe('Test server follows API validators', function () { 22describe('Test server follows API validators', function () {
22 let server: ServerInfo 23 let server: ServerInfo
@@ -52,7 +53,7 @@ describe('Test server follows API validators', function () {
52 url: server.url, 53 url: server.url,
53 path, 54 path,
54 token: server.accessToken, 55 token: server.accessToken,
55 statusCodeExpected: 400 56 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
56 }) 57 })
57 }) 58 })
58 59
@@ -62,7 +63,7 @@ describe('Test server follows API validators', function () {
62 path, 63 path,
63 token: server.accessToken, 64 token: server.accessToken,
64 fields: { hosts: 'localhost:9002' }, 65 fields: { hosts: 'localhost:9002' },
65 statusCodeExpected: 400 66 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
66 }) 67 })
67 }) 68 })
68 69
@@ -72,7 +73,7 @@ describe('Test server follows API validators', function () {
72 path, 73 path,
73 fields: { hosts: [ 'localhost:9002', 'localhost:coucou' ] }, 74 fields: { hosts: [ 'localhost:9002', 'localhost:coucou' ] },
74 token: server.accessToken, 75 token: server.accessToken,
75 statusCodeExpected: 400 76 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
76 }) 77 })
77 }) 78 })
78 79
@@ -82,7 +83,7 @@ describe('Test server follows API validators', function () {
82 path, 83 path,
83 fields: { hosts: [ 'localhost:9002', 'http://localhost:9003' ] }, 84 fields: { hosts: [ 'localhost:9002', 'http://localhost:9003' ] },
84 token: server.accessToken, 85 token: server.accessToken,
85 statusCodeExpected: 400 86 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
86 }) 87 })
87 }) 88 })
88 89
@@ -92,7 +93,7 @@ describe('Test server follows API validators', function () {
92 path, 93 path,
93 fields: { urls: [ 'localhost:9002', 'localhost:9002' ] }, 94 fields: { urls: [ 'localhost:9002', 'localhost:9002' ] },
94 token: server.accessToken, 95 token: server.accessToken,
95 statusCodeExpected: 400 96 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
96 }) 97 })
97 }) 98 })
98 99
@@ -102,7 +103,7 @@ describe('Test server follows API validators', function () {
102 path, 103 path,
103 fields: { hosts: [ 'localhost:9002' ] }, 104 fields: { hosts: [ 'localhost:9002' ] },
104 token: 'fake_token', 105 token: 'fake_token',
105 statusCodeExpected: 401 106 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
106 }) 107 })
107 }) 108 })
108 109
@@ -112,7 +113,7 @@ describe('Test server follows API validators', function () {
112 path, 113 path,
113 fields: { hosts: [ 'localhost:9002' ] }, 114 fields: { hosts: [ 'localhost:9002' ] },
114 token: userAccessToken, 115 token: userAccessToken,
115 statusCodeExpected: 403 116 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
116 }) 117 })
117 }) 118 })
118 }) 119 })
@@ -156,7 +157,7 @@ describe('Test server follows API validators', function () {
156 await makeGetRequest({ 157 await makeGetRequest({
157 url: server.url, 158 url: server.url,
158 path, 159 path,
159 statusCodeExpected: 200, 160 statusCodeExpected: HttpStatusCode.OK_200,
160 query: { 161 query: {
161 state: 'accepted', 162 state: 'accepted',
162 actorType: 'Application' 163 actorType: 'Application'
@@ -205,7 +206,7 @@ describe('Test server follows API validators', function () {
205 await makeGetRequest({ 206 await makeGetRequest({
206 url: server.url, 207 url: server.url,
207 path, 208 path,
208 statusCodeExpected: 200, 209 statusCodeExpected: HttpStatusCode.OK_200,
209 query: { 210 query: {
210 state: 'accepted' 211 state: 'accepted'
211 } 212 }
@@ -221,7 +222,7 @@ describe('Test server follows API validators', function () {
221 url: server.url, 222 url: server.url,
222 path: path + '/toto@localhost:9002', 223 path: path + '/toto@localhost:9002',
223 token: 'fake_token', 224 token: 'fake_token',
224 statusCodeExpected: 401 225 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
225 }) 226 })
226 }) 227 })
227 228
@@ -230,7 +231,7 @@ describe('Test server follows API validators', function () {
230 url: server.url, 231 url: server.url,
231 path: path + '/toto@localhost:9002', 232 path: path + '/toto@localhost:9002',
232 token: userAccessToken, 233 token: userAccessToken,
233 statusCodeExpected: 403 234 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
234 }) 235 })
235 }) 236 })
236 237
@@ -239,7 +240,7 @@ describe('Test server follows API validators', function () {
239 url: server.url, 240 url: server.url,
240 path: path + '/toto', 241 path: path + '/toto',
241 token: server.accessToken, 242 token: server.accessToken,
242 statusCodeExpected: 400 243 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
243 }) 244 })
244 }) 245 })
245 246
@@ -248,7 +249,7 @@ describe('Test server follows API validators', function () {
248 url: server.url, 249 url: server.url,
249 path: path + '/toto@localhost:9003', 250 path: path + '/toto@localhost:9003',
250 token: server.accessToken, 251 token: server.accessToken,
251 statusCodeExpected: 404 252 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
252 }) 253 })
253 }) 254 })
254 }) 255 })
@@ -261,7 +262,7 @@ describe('Test server follows API validators', function () {
261 url: server.url, 262 url: server.url,
262 path: path + '/toto@localhost:9002/accept', 263 path: path + '/toto@localhost:9002/accept',
263 token: 'fake_token', 264 token: 'fake_token',
264 statusCodeExpected: 401 265 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
265 }) 266 })
266 }) 267 })
267 268
@@ -270,7 +271,7 @@ describe('Test server follows API validators', function () {
270 url: server.url, 271 url: server.url,
271 path: path + '/toto@localhost:9002/accept', 272 path: path + '/toto@localhost:9002/accept',
272 token: userAccessToken, 273 token: userAccessToken,
273 statusCodeExpected: 403 274 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
274 }) 275 })
275 }) 276 })
276 277
@@ -279,7 +280,7 @@ describe('Test server follows API validators', function () {
279 url: server.url, 280 url: server.url,
280 path: path + '/toto/accept', 281 path: path + '/toto/accept',
281 token: server.accessToken, 282 token: server.accessToken,
282 statusCodeExpected: 400 283 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
283 }) 284 })
284 }) 285 })
285 286
@@ -288,7 +289,7 @@ describe('Test server follows API validators', function () {
288 url: server.url, 289 url: server.url,
289 path: path + '/toto@localhost:9003/accept', 290 path: path + '/toto@localhost:9003/accept',
290 token: server.accessToken, 291 token: server.accessToken,
291 statusCodeExpected: 404 292 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
292 }) 293 })
293 }) 294 })
294 }) 295 })
@@ -301,7 +302,7 @@ describe('Test server follows API validators', function () {
301 url: server.url, 302 url: server.url,
302 path: path + '/toto@localhost:9002/reject', 303 path: path + '/toto@localhost:9002/reject',
303 token: 'fake_token', 304 token: 'fake_token',
304 statusCodeExpected: 401 305 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
305 }) 306 })
306 }) 307 })
307 308
@@ -310,7 +311,7 @@ describe('Test server follows API validators', function () {
310 url: server.url, 311 url: server.url,
311 path: path + '/toto@localhost:9002/reject', 312 path: path + '/toto@localhost:9002/reject',
312 token: userAccessToken, 313 token: userAccessToken,
313 statusCodeExpected: 403 314 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
314 }) 315 })
315 }) 316 })
316 317
@@ -319,7 +320,7 @@ describe('Test server follows API validators', function () {
319 url: server.url, 320 url: server.url,
320 path: path + '/toto/reject', 321 path: path + '/toto/reject',
321 token: server.accessToken, 322 token: server.accessToken,
322 statusCodeExpected: 400 323 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
323 }) 324 })
324 }) 325 })
325 326
@@ -328,7 +329,7 @@ describe('Test server follows API validators', function () {
328 url: server.url, 329 url: server.url,
329 path: path + '/toto@localhost:9003/reject', 330 path: path + '/toto@localhost:9003/reject',
330 token: server.accessToken, 331 token: server.accessToken,
331 statusCodeExpected: 404 332 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
332 }) 333 })
333 }) 334 })
334 }) 335 })
@@ -341,7 +342,7 @@ describe('Test server follows API validators', function () {
341 url: server.url, 342 url: server.url,
342 path: path + '/localhost:9002', 343 path: path + '/localhost:9002',
343 token: 'fake_token', 344 token: 'fake_token',
344 statusCodeExpected: 401 345 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
345 }) 346 })
346 }) 347 })
347 348
@@ -350,7 +351,7 @@ describe('Test server follows API validators', function () {
350 url: server.url, 351 url: server.url,
351 path: path + '/localhost:9002', 352 path: path + '/localhost:9002',
352 token: userAccessToken, 353 token: userAccessToken,
353 statusCodeExpected: 403 354 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
354 }) 355 })
355 }) 356 })
356 357
@@ -359,7 +360,7 @@ describe('Test server follows API validators', function () {
359 url: server.url, 360 url: server.url,
360 path: path + '/example.com', 361 path: path + '/example.com',
361 token: server.accessToken, 362 token: server.accessToken,
362 statusCodeExpected: 404 363 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
363 }) 364 })
364 }) 365 })
365 }) 366 })
diff --git a/server/tests/api/check-params/jobs.ts b/server/tests/api/check-params/jobs.ts
index 8f4af8d16..3c1d2049b 100644
--- a/server/tests/api/check-params/jobs.ts
+++ b/server/tests/api/check-params/jobs.ts
@@ -16,6 +16,7 @@ import {
16 checkBadStartPagination 16 checkBadStartPagination
17} from '../../../../shared/extra-utils/requests/check-api-params' 17} from '../../../../shared/extra-utils/requests/check-api-params'
18import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests' 18import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests'
19import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
19 20
20describe('Test jobs API validators', function () { 21describe('Test jobs API validators', function () {
21 const path = '/api/v1/jobs/failed' 22 const path = '/api/v1/jobs/failed'
@@ -76,7 +77,7 @@ describe('Test jobs API validators', function () {
76 await makeGetRequest({ 77 await makeGetRequest({
77 url: server.url, 78 url: server.url,
78 path, 79 path,
79 statusCodeExpected: 401 80 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
80 }) 81 })
81 }) 82 })
82 83
@@ -85,7 +86,7 @@ describe('Test jobs API validators', function () {
85 url: server.url, 86 url: server.url,
86 path, 87 path,
87 token: userAccessToken, 88 token: userAccessToken,
88 statusCodeExpected: 403 89 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
89 }) 90 })
90 }) 91 })
91 92
diff --git a/server/tests/api/check-params/live.ts b/server/tests/api/check-params/live.ts
index 055f2f295..40dca908b 100644
--- a/server/tests/api/check-params/live.ts
+++ b/server/tests/api/check-params/live.ts
@@ -24,6 +24,7 @@ import {
24 userLogin, 24 userLogin,
25 waitUntilLiveStarts 25 waitUntilLiveStarts
26} from '../../../../shared/extra-utils' 26} from '../../../../shared/extra-utils'
27import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
27 28
28describe('Test video lives API validator', function () { 29describe('Test video lives API validator', function () {
29 const path = '/api/v1/videos/live' 30 const path = '/api/v1/videos/live'
@@ -226,7 +227,7 @@ describe('Test video lives API validator', function () {
226 path, 227 path,
227 token: server.accessToken, 228 token: server.accessToken,
228 fields: baseCorrectParams, 229 fields: baseCorrectParams,
229 statusCodeExpected: 200 230 statusCodeExpected: HttpStatusCode.OK_200
230 }) 231 })
231 232
232 videoId = res.body.video.id 233 videoId = res.body.video.id
@@ -244,7 +245,7 @@ describe('Test video lives API validator', function () {
244 path, 245 path,
245 token: server.accessToken, 246 token: server.accessToken,
246 fields: baseCorrectParams, 247 fields: baseCorrectParams,
247 statusCodeExpected: 403 248 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
248 }) 249 })
249 }) 250 })
250 251
@@ -263,7 +264,7 @@ describe('Test video lives API validator', function () {
263 path, 264 path,
264 token: server.accessToken, 265 token: server.accessToken,
265 fields, 266 fields,
266 statusCodeExpected: 403 267 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
267 }) 268 })
268 }) 269 })
269 270
@@ -282,7 +283,7 @@ describe('Test video lives API validator', function () {
282 path, 283 path,
283 token: server.accessToken, 284 token: server.accessToken,
284 fields, 285 fields,
285 statusCodeExpected: 200 286 statusCodeExpected: HttpStatusCode.OK_200
286 }) 287 })
287 }) 288 })
288 289
@@ -299,7 +300,7 @@ describe('Test video lives API validator', function () {
299 path, 300 path,
300 token: server.accessToken, 301 token: server.accessToken,
301 fields: baseCorrectParams, 302 fields: baseCorrectParams,
302 statusCodeExpected: 403 303 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
303 }) 304 })
304 }) 305 })
305 306
@@ -317,7 +318,7 @@ describe('Test video lives API validator', function () {
317 path, 318 path,
318 token: server.accessToken, 319 token: server.accessToken,
319 fields: baseCorrectParams, 320 fields: baseCorrectParams,
320 statusCodeExpected: 403 321 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
321 }) 322 })
322 }) 323 })
323 }) 324 })
@@ -325,27 +326,27 @@ describe('Test video lives API validator', function () {
325 describe('When getting live information', function () { 326 describe('When getting live information', function () {
326 327
327 it('Should fail without access token', async function () { 328 it('Should fail without access token', async function () {
328 await getLive(server.url, '', videoId, 401) 329 await getLive(server.url, '', videoId, HttpStatusCode.UNAUTHORIZED_401)
329 }) 330 })
330 331
331 it('Should fail with a bad access token', async function () { 332 it('Should fail with a bad access token', async function () {
332 await getLive(server.url, 'toto', videoId, 401) 333 await getLive(server.url, 'toto', videoId, HttpStatusCode.UNAUTHORIZED_401)
333 }) 334 })
334 335
335 it('Should fail with access token of another user', async function () { 336 it('Should fail with access token of another user', async function () {
336 await getLive(server.url, userAccessToken, videoId, 403) 337 await getLive(server.url, userAccessToken, videoId, HttpStatusCode.FORBIDDEN_403)
337 }) 338 })
338 339
339 it('Should fail with a bad video id', async function () { 340 it('Should fail with a bad video id', async function () {
340 await getLive(server.url, server.accessToken, 'toto', 400) 341 await getLive(server.url, server.accessToken, 'toto', HttpStatusCode.BAD_REQUEST_400)
341 }) 342 })
342 343
343 it('Should fail with an unknown video id', async function () { 344 it('Should fail with an unknown video id', async function () {
344 await getLive(server.url, server.accessToken, 454555, 404) 345 await getLive(server.url, server.accessToken, 454555, HttpStatusCode.NOT_FOUND_404)
345 }) 346 })
346 347
347 it('Should fail with a non live video', async function () { 348 it('Should fail with a non live video', async function () {
348 await getLive(server.url, server.accessToken, videoIdNotLive, 404) 349 await getLive(server.url, server.accessToken, videoIdNotLive, HttpStatusCode.NOT_FOUND_404)
349 }) 350 })
350 351
351 it('Should succeed with the correct params', async function () { 352 it('Should succeed with the correct params', async function () {
@@ -356,33 +357,33 @@ describe('Test video lives API validator', function () {
356 describe('When updating live information', async function () { 357 describe('When updating live information', async function () {
357 358
358 it('Should fail without access token', async function () { 359 it('Should fail without access token', async function () {
359 await updateLive(server.url, '', videoId, {}, 401) 360 await updateLive(server.url, '', videoId, {}, HttpStatusCode.UNAUTHORIZED_401)
360 }) 361 })
361 362
362 it('Should fail with a bad access token', async function () { 363 it('Should fail with a bad access token', async function () {
363 await updateLive(server.url, 'toto', videoId, {}, 401) 364 await updateLive(server.url, 'toto', videoId, {}, HttpStatusCode.UNAUTHORIZED_401)
364 }) 365 })
365 366
366 it('Should fail with access token of another user', async function () { 367 it('Should fail with access token of another user', async function () {
367 await updateLive(server.url, userAccessToken, videoId, {}, 403) 368 await updateLive(server.url, userAccessToken, videoId, {}, HttpStatusCode.FORBIDDEN_403)
368 }) 369 })
369 370
370 it('Should fail with a bad video id', async function () { 371 it('Should fail with a bad video id', async function () {
371 await updateLive(server.url, server.accessToken, 'toto', {}, 400) 372 await updateLive(server.url, server.accessToken, 'toto', {}, HttpStatusCode.BAD_REQUEST_400)
372 }) 373 })
373 374
374 it('Should fail with an unknown video id', async function () { 375 it('Should fail with an unknown video id', async function () {
375 await updateLive(server.url, server.accessToken, 454555, {}, 404) 376 await updateLive(server.url, server.accessToken, 454555, {}, HttpStatusCode.NOT_FOUND_404)
376 }) 377 })
377 378
378 it('Should fail with a non live video', async function () { 379 it('Should fail with a non live video', async function () {
379 await updateLive(server.url, server.accessToken, videoIdNotLive, {}, 404) 380 await updateLive(server.url, server.accessToken, videoIdNotLive, {}, HttpStatusCode.NOT_FOUND_404)
380 }) 381 })
381 382
382 it('Should fail with save replay and permanent live set to true', async function () { 383 it('Should fail with save replay and permanent live set to true', async function () {
383 const fields = { saveReplay: true, permanentLive: true } 384 const fields = { saveReplay: true, permanentLive: true }
384 385
385 await updateLive(server.url, server.accessToken, videoId, fields, 400) 386 await updateLive(server.url, server.accessToken, videoId, fields, HttpStatusCode.BAD_REQUEST_400)
386 }) 387 })
387 388
388 it('Should succeed with the correct params', async function () { 389 it('Should succeed with the correct params', async function () {
@@ -397,7 +398,7 @@ describe('Test video lives API validator', function () {
397 } 398 }
398 }) 399 })
399 400
400 await updateLive(server.url, server.accessToken, videoId, { saveReplay: true }, 403) 401 await updateLive(server.url, server.accessToken, videoId, { saveReplay: true }, HttpStatusCode.FORBIDDEN_403)
401 }) 402 })
402 403
403 it('Should fail to update a live if it has already started', async function () { 404 it('Should fail to update a live if it has already started', async function () {
@@ -409,7 +410,7 @@ describe('Test video lives API validator', function () {
409 const command = sendRTMPStream(live.rtmpUrl, live.streamKey) 410 const command = sendRTMPStream(live.rtmpUrl, live.streamKey)
410 411
411 await waitUntilLiveStarts(server.url, server.accessToken, videoId) 412 await waitUntilLiveStarts(server.url, server.accessToken, videoId)
412 await updateLive(server.url, server.accessToken, videoId, {}, 400) 413 await updateLive(server.url, server.accessToken, videoId, {}, HttpStatusCode.BAD_REQUEST_400)
413 414
414 await stopFfmpeg(command) 415 await stopFfmpeg(command)
415 }) 416 })
diff --git a/server/tests/api/check-params/logs.ts b/server/tests/api/check-params/logs.ts
index 719da54e6..dac1e6b98 100644
--- a/server/tests/api/check-params/logs.ts
+++ b/server/tests/api/check-params/logs.ts
@@ -11,6 +11,7 @@ import {
11 userLogin 11 userLogin
12} from '../../../../shared/extra-utils' 12} from '../../../../shared/extra-utils'
13import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests' 13import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests'
14import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
14 15
15describe('Test logs API validators', function () { 16describe('Test logs API validators', function () {
16 const path = '/api/v1/server/logs' 17 const path = '/api/v1/server/logs'
@@ -40,7 +41,7 @@ describe('Test logs API validators', function () {
40 await makeGetRequest({ 41 await makeGetRequest({
41 url: server.url, 42 url: server.url,
42 path, 43 path,
43 statusCodeExpected: 401 44 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
44 }) 45 })
45 }) 46 })
46 47
@@ -49,7 +50,7 @@ describe('Test logs API validators', function () {
49 url: server.url, 50 url: server.url,
50 path, 51 path,
51 token: userAccessToken, 52 token: userAccessToken,
52 statusCodeExpected: 403 53 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
53 }) 54 })
54 }) 55 })
55 56
@@ -58,7 +59,7 @@ describe('Test logs API validators', function () {
58 url: server.url, 59 url: server.url,
59 path, 60 path,
60 token: server.accessToken, 61 token: server.accessToken,
61 statusCodeExpected: 400 62 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
62 }) 63 })
63 }) 64 })
64 65
@@ -68,7 +69,7 @@ describe('Test logs API validators', function () {
68 path, 69 path,
69 token: server.accessToken, 70 token: server.accessToken,
70 query: { startDate: 'toto' }, 71 query: { startDate: 'toto' },
71 statusCodeExpected: 400 72 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
72 }) 73 })
73 }) 74 })
74 75
@@ -78,7 +79,7 @@ describe('Test logs API validators', function () {
78 path, 79 path,
79 token: server.accessToken, 80 token: server.accessToken,
80 query: { startDate: new Date().toISOString(), endDate: 'toto' }, 81 query: { startDate: new Date().toISOString(), endDate: 'toto' },
81 statusCodeExpected: 400 82 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
82 }) 83 })
83 }) 84 })
84 85
@@ -88,7 +89,7 @@ describe('Test logs API validators', function () {
88 path, 89 path,
89 token: server.accessToken, 90 token: server.accessToken,
90 query: { startDate: new Date().toISOString(), level: 'toto' }, 91 query: { startDate: new Date().toISOString(), level: 'toto' },
91 statusCodeExpected: 400 92 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
92 }) 93 })
93 }) 94 })
94 95
@@ -98,7 +99,7 @@ describe('Test logs API validators', function () {
98 path, 99 path,
99 token: server.accessToken, 100 token: server.accessToken,
100 query: { startDate: new Date().toISOString() }, 101 query: { startDate: new Date().toISOString() },
101 statusCodeExpected: 200 102 statusCodeExpected: HttpStatusCode.OK_200
102 }) 103 })
103 }) 104 })
104 }) 105 })
diff --git a/server/tests/api/check-params/plugins.ts b/server/tests/api/check-params/plugins.ts
index 07ded26ee..6e540bcbb 100644
--- a/server/tests/api/check-params/plugins.ts
+++ b/server/tests/api/check-params/plugins.ts
@@ -18,6 +18,7 @@ import {
18} from '../../../../shared/extra-utils' 18} from '../../../../shared/extra-utils'
19import { PluginType } from '../../../../shared/models/plugins/plugin.type' 19import { PluginType } from '../../../../shared/models/plugins/plugin.type'
20import { PeerTubePlugin } from '../../../../shared/models/plugins/peertube-plugin.model' 20import { PeerTubePlugin } from '../../../../shared/models/plugins/peertube-plugin.model'
21import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
21 22
22describe('Test server plugins API validators', function () { 23describe('Test server plugins API validators', function () {
23 let server: ServerInfo 24 let server: ServerInfo
@@ -73,7 +74,7 @@ describe('Test server plugins API validators', function () {
73 ] 74 ]
74 75
75 for (const p of paths) { 76 for (const p of paths) {
76 await makeGetRequest({ url: server.url, path: p, statusCodeExpected: 404 }) 77 await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 })
77 } 78 }
78 }) 79 })
79 80
@@ -81,7 +82,7 @@ describe('Test server plugins API validators', function () {
81 await makeGetRequest({ 82 await makeGetRequest({
82 url: server.url, 83 url: server.url,
83 path: '/themes/' + pluginName + '/' + npmVersion + '/static/images/chocobo.png', 84 path: '/themes/' + pluginName + '/' + npmVersion + '/static/images/chocobo.png',
84 statusCodeExpected: 404 85 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
85 }) 86 })
86 }) 87 })
87 88
@@ -96,7 +97,7 @@ describe('Test server plugins API validators', function () {
96 ] 97 ]
97 98
98 for (const p of paths) { 99 for (const p of paths) {
99 await makeGetRequest({ url: server.url, path: p, statusCodeExpected: 400 }) 100 await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
100 } 101 }
101 }) 102 })
102 103
@@ -110,14 +111,14 @@ describe('Test server plugins API validators', function () {
110 ] 111 ]
111 112
112 for (const p of paths) { 113 for (const p of paths) {
113 await makeGetRequest({ url: server.url, path: p, statusCodeExpected: 400 }) 114 await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
114 } 115 }
115 }) 116 })
116 117
117 it('Should fail with an unknown auth name', async function () { 118 it('Should fail with an unknown auth name', async function () {
118 const path = '/plugins/' + pluginName + '/' + npmVersion + '/auth/bad-auth' 119 const path = '/plugins/' + pluginName + '/' + npmVersion + '/auth/bad-auth'
119 120
120 await makeGetRequest({ url: server.url, path, statusCodeExpected: 404 }) 121 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 })
121 }) 122 })
122 123
123 it('Should fail with an unknown static file', async function () { 124 it('Should fail with an unknown static file', async function () {
@@ -129,7 +130,7 @@ describe('Test server plugins API validators', function () {
129 ] 130 ]
130 131
131 for (const p of paths) { 132 for (const p of paths) {
132 await makeGetRequest({ url: server.url, path: p, statusCodeExpected: 404 }) 133 await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 })
133 } 134 }
134 }) 135 })
135 136
@@ -137,7 +138,7 @@ describe('Test server plugins API validators', function () {
137 await makeGetRequest({ 138 await makeGetRequest({
138 url: server.url, 139 url: server.url,
139 path: '/themes/' + themeName + '/' + themeVersion + '/css/assets/fake.css', 140 path: '/themes/' + themeName + '/' + themeVersion + '/css/assets/fake.css',
140 statusCodeExpected: 404 141 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
141 }) 142 })
142 }) 143 })
143 144
@@ -151,11 +152,11 @@ describe('Test server plugins API validators', function () {
151 ] 152 ]
152 153
153 for (const p of paths) { 154 for (const p of paths) {
154 await makeGetRequest({ url: server.url, path: p, statusCodeExpected: 200 }) 155 await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.OK_200 })
155 } 156 }
156 157
157 const authPath = '/plugins/' + pluginName + '/' + npmVersion + '/auth/fake-auth' 158 const authPath = '/plugins/' + pluginName + '/' + npmVersion + '/auth/fake-auth'
158 await makeGetRequest({ url: server.url, path: authPath, statusCodeExpected: 302 }) 159 await makeGetRequest({ url: server.url, path: authPath, statusCodeExpected: HttpStatusCode.FOUND_302 })
159 }) 160 })
160 }) 161 })
161 162
@@ -173,7 +174,7 @@ describe('Test server plugins API validators', function () {
173 path, 174 path,
174 token: 'fake_token', 175 token: 'fake_token',
175 query: baseQuery, 176 query: baseQuery,
176 statusCodeExpected: 401 177 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
177 }) 178 })
178 }) 179 })
179 180
@@ -183,7 +184,7 @@ describe('Test server plugins API validators', function () {
183 path, 184 path,
184 token: userAccessToken, 185 token: userAccessToken,
185 query: baseQuery, 186 query: baseQuery,
186 statusCodeExpected: 403 187 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
187 }) 188 })
188 }) 189 })
189 190
@@ -227,7 +228,7 @@ describe('Test server plugins API validators', function () {
227 path, 228 path,
228 token: server.accessToken, 229 token: server.accessToken,
229 query: baseQuery, 230 query: baseQuery,
230 statusCodeExpected: 200 231 statusCodeExpected: HttpStatusCode.OK_200
231 }) 232 })
232 }) 233 })
233 }) 234 })
@@ -244,7 +245,7 @@ describe('Test server plugins API validators', function () {
244 path, 245 path,
245 token: 'fake_token', 246 token: 'fake_token',
246 query: baseQuery, 247 query: baseQuery,
247 statusCodeExpected: 401 248 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
248 }) 249 })
249 }) 250 })
250 251
@@ -254,7 +255,7 @@ describe('Test server plugins API validators', function () {
254 path, 255 path,
255 token: userAccessToken, 256 token: userAccessToken,
256 query: baseQuery, 257 query: baseQuery,
257 statusCodeExpected: 403 258 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
258 }) 259 })
259 }) 260 })
260 261
@@ -287,7 +288,7 @@ describe('Test server plugins API validators', function () {
287 path, 288 path,
288 token: server.accessToken, 289 token: server.accessToken,
289 query: baseQuery, 290 query: baseQuery,
290 statusCodeExpected: 200 291 statusCodeExpected: HttpStatusCode.OK_200
291 }) 292 })
292 }) 293 })
293 }) 294 })
@@ -301,7 +302,7 @@ describe('Test server plugins API validators', function () {
301 url: server.url, 302 url: server.url,
302 path: path + suffix, 303 path: path + suffix,
303 token: 'fake_token', 304 token: 'fake_token',
304 statusCodeExpected: 401 305 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
305 }) 306 })
306 } 307 }
307 }) 308 })
@@ -312,7 +313,7 @@ describe('Test server plugins API validators', function () {
312 url: server.url, 313 url: server.url,
313 path: path + suffix, 314 path: path + suffix,
314 token: userAccessToken, 315 token: userAccessToken,
315 statusCodeExpected: 403 316 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
316 }) 317 })
317 } 318 }
318 }) 319 })
@@ -323,7 +324,7 @@ describe('Test server plugins API validators', function () {
323 url: server.url, 324 url: server.url,
324 path: path + suffix, 325 path: path + suffix,
325 token: server.accessToken, 326 token: server.accessToken,
326 statusCodeExpected: 400 327 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
327 }) 328 })
328 } 329 }
329 330
@@ -332,7 +333,7 @@ describe('Test server plugins API validators', function () {
332 url: server.url, 333 url: server.url,
333 path: path + suffix, 334 path: path + suffix,
334 token: server.accessToken, 335 token: server.accessToken,
335 statusCodeExpected: 400 336 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
336 }) 337 })
337 } 338 }
338 }) 339 })
@@ -343,7 +344,7 @@ describe('Test server plugins API validators', function () {
343 url: server.url, 344 url: server.url,
344 path: path + suffix, 345 path: path + suffix,
345 token: server.accessToken, 346 token: server.accessToken,
346 statusCodeExpected: 404 347 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
347 }) 348 })
348 } 349 }
349 }) 350 })
@@ -354,7 +355,7 @@ describe('Test server plugins API validators', function () {
354 url: server.url, 355 url: server.url,
355 path: path + suffix, 356 path: path + suffix,
356 token: server.accessToken, 357 token: server.accessToken,
357 statusCodeExpected: 200 358 statusCodeExpected: HttpStatusCode.OK_200
358 }) 359 })
359 } 360 }
360 }) 361 })
@@ -370,7 +371,7 @@ describe('Test server plugins API validators', function () {
370 path: path + npmPlugin + '/settings', 371 path: path + npmPlugin + '/settings',
371 fields: { settings }, 372 fields: { settings },
372 token: 'fake_token', 373 token: 'fake_token',
373 statusCodeExpected: 401 374 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
374 }) 375 })
375 }) 376 })
376 377
@@ -380,7 +381,7 @@ describe('Test server plugins API validators', function () {
380 path: path + npmPlugin + '/settings', 381 path: path + npmPlugin + '/settings',
381 fields: { settings }, 382 fields: { settings },
382 token: userAccessToken, 383 token: userAccessToken,
383 statusCodeExpected: 403 384 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
384 }) 385 })
385 }) 386 })
386 387
@@ -390,7 +391,7 @@ describe('Test server plugins API validators', function () {
390 path: path + 'toto/settings', 391 path: path + 'toto/settings',
391 fields: { settings }, 392 fields: { settings },
392 token: server.accessToken, 393 token: server.accessToken,
393 statusCodeExpected: 400 394 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
394 }) 395 })
395 396
396 await makePutBodyRequest({ 397 await makePutBodyRequest({
@@ -398,7 +399,7 @@ describe('Test server plugins API validators', function () {
398 path: path + 'peertube-plugin-TOTO/settings', 399 path: path + 'peertube-plugin-TOTO/settings',
399 fields: { settings }, 400 fields: { settings },
400 token: server.accessToken, 401 token: server.accessToken,
401 statusCodeExpected: 400 402 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
402 }) 403 })
403 }) 404 })
404 405
@@ -408,7 +409,7 @@ describe('Test server plugins API validators', function () {
408 path: path + 'peertube-plugin-toto/settings', 409 path: path + 'peertube-plugin-toto/settings',
409 fields: { settings }, 410 fields: { settings },
410 token: server.accessToken, 411 token: server.accessToken,
411 statusCodeExpected: 404 412 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
412 }) 413 })
413 }) 414 })
414 415
@@ -418,7 +419,7 @@ describe('Test server plugins API validators', function () {
418 path: path + npmPlugin + '/settings', 419 path: path + npmPlugin + '/settings',
419 fields: { settings }, 420 fields: { settings },
420 token: server.accessToken, 421 token: server.accessToken,
421 statusCodeExpected: 204 422 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
422 }) 423 })
423 }) 424 })
424 }) 425 })
@@ -433,7 +434,7 @@ describe('Test server plugins API validators', function () {
433 path: path + suffix, 434 path: path + suffix,
434 fields: { npmName: npmPlugin }, 435 fields: { npmName: npmPlugin },
435 token: 'fake_token', 436 token: 'fake_token',
436 statusCodeExpected: 401 437 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
437 }) 438 })
438 } 439 }
439 }) 440 })
@@ -445,7 +446,7 @@ describe('Test server plugins API validators', function () {
445 path: path + suffix, 446 path: path + suffix,
446 fields: { npmName: npmPlugin }, 447 fields: { npmName: npmPlugin },
447 token: userAccessToken, 448 token: userAccessToken,
448 statusCodeExpected: 403 449 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
449 }) 450 })
450 } 451 }
451 }) 452 })
@@ -457,7 +458,7 @@ describe('Test server plugins API validators', function () {
457 path: path + suffix, 458 path: path + suffix,
458 fields: { npmName: 'toto' }, 459 fields: { npmName: 'toto' },
459 token: server.accessToken, 460 token: server.accessToken,
460 statusCodeExpected: 400 461 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
461 }) 462 })
462 } 463 }
463 464
@@ -467,7 +468,7 @@ describe('Test server plugins API validators', function () {
467 path: path + suffix, 468 path: path + suffix,
468 fields: { npmName: 'peertube-plugin-TOTO' }, 469 fields: { npmName: 'peertube-plugin-TOTO' },
469 token: server.accessToken, 470 token: server.accessToken,
470 statusCodeExpected: 400 471 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
471 }) 472 })
472 } 473 }
473 }) 474 })
@@ -476,9 +477,9 @@ describe('Test server plugins API validators', function () {
476 this.timeout(10000) 477 this.timeout(10000)
477 478
478 const it = [ 479 const it = [
479 { suffix: 'install', status: 200 }, 480 { suffix: 'install', status: HttpStatusCode.OK_200 },
480 { suffix: 'update', status: 200 }, 481 { suffix: 'update', status: HttpStatusCode.OK_200 },
481 { suffix: 'uninstall', status: 204 } 482 { suffix: 'uninstall', status: HttpStatusCode.NO_CONTENT_204 }
482 ] 483 ]
483 484
484 for (const obj of it) { 485 for (const obj of it) {
diff --git a/server/tests/api/check-params/redundancy.ts b/server/tests/api/check-params/redundancy.ts
index cb0cc0854..3e04865ee 100644
--- a/server/tests/api/check-params/redundancy.ts
+++ b/server/tests/api/check-params/redundancy.ts
@@ -16,6 +16,7 @@ import {
16 setAccessTokensToServers, uploadVideoAndGetId, 16 setAccessTokensToServers, uploadVideoAndGetId,
17 userLogin, waitJobs, getVideoIdFromUUID 17 userLogin, waitJobs, getVideoIdFromUUID
18} from '../../../../shared/extra-utils' 18} from '../../../../shared/extra-utils'
19import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
19 20
20describe('Test server redundancy API validators', function () { 21describe('Test server redundancy API validators', function () {
21 let servers: ServerInfo[] 22 let servers: ServerInfo[]
@@ -62,11 +63,11 @@ describe('Test server redundancy API validators', function () {
62 }) 63 })
63 64
64 it('Should fail with an invalid token', async function () { 65 it('Should fail with an invalid token', async function () {
65 await makeGetRequest({ url, path, token: 'fake_token', statusCodeExpected: 401 }) 66 await makeGetRequest({ url, path, token: 'fake_token', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
66 }) 67 })
67 68
68 it('Should fail if the user is not an administrator', async function () { 69 it('Should fail if the user is not an administrator', async function () {
69 await makeGetRequest({ url, path, token: userAccessToken, statusCodeExpected: 403 }) 70 await makeGetRequest({ url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
70 }) 71 })
71 72
72 it('Should fail with a bad start pagination', async function () { 73 it('Should fail with a bad start pagination', async function () {
@@ -90,7 +91,7 @@ describe('Test server redundancy API validators', function () {
90 }) 91 })
91 92
92 it('Should succeed with the correct params', async function () { 93 it('Should succeed with the correct params', async function () {
93 await makeGetRequest({ url, path, token, query: { target: 'my-videos' }, statusCodeExpected: 200 }) 94 await makeGetRequest({ url, path, token, query: { target: 'my-videos' }, statusCodeExpected: HttpStatusCode.OK_200 })
94 }) 95 })
95 }) 96 })
96 97
@@ -106,11 +107,11 @@ describe('Test server redundancy API validators', function () {
106 }) 107 })
107 108
108 it('Should fail with an invalid token', async function () { 109 it('Should fail with an invalid token', async function () {
109 await makePostBodyRequest({ url, path, token: 'fake_token', statusCodeExpected: 401 }) 110 await makePostBodyRequest({ url, path, token: 'fake_token', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
110 }) 111 })
111 112
112 it('Should fail if the user is not an administrator', async function () { 113 it('Should fail if the user is not an administrator', async function () {
113 await makePostBodyRequest({ url, path, token: userAccessToken, statusCodeExpected: 403 }) 114 await makePostBodyRequest({ url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
114 }) 115 })
115 116
116 it('Should fail without a video id', async function () { 117 it('Should fail without a video id', async function () {
@@ -122,7 +123,7 @@ describe('Test server redundancy API validators', function () {
122 }) 123 })
123 124
124 it('Should fail with a not found video id', async function () { 125 it('Should fail with a not found video id', async function () {
125 await makePostBodyRequest({ url, path, token, fields: { videoId: 6565 }, statusCodeExpected: 404 }) 126 await makePostBodyRequest({ url, path, token, fields: { videoId: 6565 }, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 })
126 }) 127 })
127 128
128 it('Should fail with a local a video id', async function () { 129 it('Should fail with a local a video id', async function () {
@@ -130,7 +131,7 @@ describe('Test server redundancy API validators', function () {
130 }) 131 })
131 132
132 it('Should succeed with the correct params', async function () { 133 it('Should succeed with the correct params', async function () {
133 await makePostBodyRequest({ url, path, token, fields: { videoId: videoIdRemote }, statusCodeExpected: 204 }) 134 await makePostBodyRequest({ url, path, token, fields: { videoId: videoIdRemote }, statusCodeExpected: HttpStatusCode.NO_CONTENT_204 })
134 }) 135 })
135 136
136 it('Should fail if the video is already duplicated', async function () { 137 it('Should fail if the video is already duplicated', async function () {
@@ -138,7 +139,7 @@ describe('Test server redundancy API validators', function () {
138 139
139 await waitJobs(servers) 140 await waitJobs(servers)
140 141
141 await makePostBodyRequest({ url, path, token, fields: { videoId: videoIdRemote }, statusCodeExpected: 409 }) 142 await makePostBodyRequest({ url, path, token, fields: { videoId: videoIdRemote }, statusCodeExpected: HttpStatusCode.CONFLICT_409 })
142 }) 143 })
143 }) 144 })
144 145
@@ -154,11 +155,11 @@ describe('Test server redundancy API validators', function () {
154 }) 155 })
155 156
156 it('Should fail with an invalid token', async function () { 157 it('Should fail with an invalid token', async function () {
157 await makeDeleteRequest({ url, path: path + '1', token: 'fake_token', statusCodeExpected: 401 }) 158 await makeDeleteRequest({ url, path: path + '1', token: 'fake_token', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
158 }) 159 })
159 160
160 it('Should fail if the user is not an administrator', async function () { 161 it('Should fail if the user is not an administrator', async function () {
161 await makeDeleteRequest({ url, path: path + '1', token: userAccessToken, statusCodeExpected: 403 }) 162 await makeDeleteRequest({ url, path: path + '1', token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
162 }) 163 })
163 164
164 it('Should fail with an incorrect video id', async function () { 165 it('Should fail with an incorrect video id', async function () {
@@ -166,7 +167,7 @@ describe('Test server redundancy API validators', function () {
166 }) 167 })
167 168
168 it('Should fail with a not found video redundancy', async function () { 169 it('Should fail with a not found video redundancy', async function () {
169 await makeDeleteRequest({ url, path: path + '454545', token, statusCodeExpected: 404 }) 170 await makeDeleteRequest({ url, path: path + '454545', token, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 })
170 }) 171 })
171 }) 172 })
172 173
@@ -179,7 +180,7 @@ describe('Test server redundancy API validators', function () {
179 path: path + '/localhost:' + servers[1].port, 180 path: path + '/localhost:' + servers[1].port,
180 fields: { redundancyAllowed: true }, 181 fields: { redundancyAllowed: true },
181 token: 'fake_token', 182 token: 'fake_token',
182 statusCodeExpected: 401 183 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
183 }) 184 })
184 }) 185 })
185 186
@@ -189,7 +190,7 @@ describe('Test server redundancy API validators', function () {
189 path: path + '/localhost:' + servers[1].port, 190 path: path + '/localhost:' + servers[1].port,
190 fields: { redundancyAllowed: true }, 191 fields: { redundancyAllowed: true },
191 token: userAccessToken, 192 token: userAccessToken,
192 statusCodeExpected: 403 193 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
193 }) 194 })
194 }) 195 })
195 196
@@ -199,7 +200,7 @@ describe('Test server redundancy API validators', function () {
199 path: path + '/example.com', 200 path: path + '/example.com',
200 fields: { redundancyAllowed: true }, 201 fields: { redundancyAllowed: true },
201 token: servers[0].accessToken, 202 token: servers[0].accessToken,
202 statusCodeExpected: 404 203 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
203 }) 204 })
204 }) 205 })
205 206
@@ -209,7 +210,7 @@ describe('Test server redundancy API validators', function () {
209 path: path + '/localhost:' + servers[1].port, 210 path: path + '/localhost:' + servers[1].port,
210 fields: { blabla: true }, 211 fields: { blabla: true },
211 token: servers[0].accessToken, 212 token: servers[0].accessToken,
212 statusCodeExpected: 400 213 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
213 }) 214 })
214 }) 215 })
215 216
@@ -219,7 +220,7 @@ describe('Test server redundancy API validators', function () {
219 path: path + '/localhost:' + servers[1].port, 220 path: path + '/localhost:' + servers[1].port,
220 fields: { redundancyAllowed: true }, 221 fields: { redundancyAllowed: true },
221 token: servers[0].accessToken, 222 token: servers[0].accessToken,
222 statusCodeExpected: 204 223 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
223 }) 224 })
224 }) 225 })
225 }) 226 })
diff --git a/server/tests/api/check-params/search.ts b/server/tests/api/check-params/search.ts
index 1a8a7235e..8378c3a89 100644
--- a/server/tests/api/check-params/search.ts
+++ b/server/tests/api/check-params/search.ts
@@ -15,6 +15,7 @@ import {
15 checkBadSortPagination, 15 checkBadSortPagination,
16 checkBadStartPagination 16 checkBadStartPagination
17} from '../../../../shared/extra-utils/requests/check-api-params' 17} from '../../../../shared/extra-utils/requests/check-api-params'
18import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
18 19
19function updateSearchIndex (server: ServerInfo, enabled: boolean, disableLocalSearch = false) { 20function updateSearchIndex (server: ServerInfo, enabled: boolean, disableLocalSearch = false) {
20 return updateCustomSubConfig(server.url, server.accessToken, { 21 return updateCustomSubConfig(server.url, server.accessToken, {
@@ -59,83 +60,83 @@ describe('Test videos API validator', function () {
59 }) 60 })
60 61
61 it('Should success with the correct parameters', async function () { 62 it('Should success with the correct parameters', async function () {
62 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: 200 }) 63 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 })
63 }) 64 })
64 65
65 it('Should fail with an invalid category', async function () { 66 it('Should fail with an invalid category', async function () {
66 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 'aa', 'b' ] }) 67 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 'aa', 'b' ] })
67 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 }) 68 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
68 69
69 const customQuery2 = immutableAssign(query, { categoryOneOf: 'a' }) 70 const customQuery2 = immutableAssign(query, { categoryOneOf: 'a' })
70 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 }) 71 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
71 }) 72 })
72 73
73 it('Should succeed with a valid category', async function () { 74 it('Should succeed with a valid category', async function () {
74 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 1, 7 ] }) 75 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 1, 7 ] })
75 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 }) 76 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 })
76 77
77 const customQuery2 = immutableAssign(query, { categoryOneOf: 1 }) 78 const customQuery2 = immutableAssign(query, { categoryOneOf: 1 })
78 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 }) 79 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
79 }) 80 })
80 81
81 it('Should fail with an invalid licence', async function () { 82 it('Should fail with an invalid licence', async function () {
82 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 'aa', 'b' ] }) 83 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 'aa', 'b' ] })
83 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 }) 84 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
84 85
85 const customQuery2 = immutableAssign(query, { licenceOneOf: 'a' }) 86 const customQuery2 = immutableAssign(query, { licenceOneOf: 'a' })
86 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 }) 87 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
87 }) 88 })
88 89
89 it('Should succeed with a valid licence', async function () { 90 it('Should succeed with a valid licence', async function () {
90 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 1, 2 ] }) 91 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 1, 2 ] })
91 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 }) 92 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 })
92 93
93 const customQuery2 = immutableAssign(query, { licenceOneOf: 1 }) 94 const customQuery2 = immutableAssign(query, { licenceOneOf: 1 })
94 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 }) 95 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
95 }) 96 })
96 97
97 it('Should succeed with a valid language', async function () { 98 it('Should succeed with a valid language', async function () {
98 const customQuery1 = immutableAssign(query, { languageOneOf: [ 'fr', 'en' ] }) 99 const customQuery1 = immutableAssign(query, { languageOneOf: [ 'fr', 'en' ] })
99 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 }) 100 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 })
100 101
101 const customQuery2 = immutableAssign(query, { languageOneOf: 'fr' }) 102 const customQuery2 = immutableAssign(query, { languageOneOf: 'fr' })
102 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 }) 103 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
103 }) 104 })
104 105
105 it('Should succeed with valid tags', async function () { 106 it('Should succeed with valid tags', async function () {
106 const customQuery1 = immutableAssign(query, { tagsOneOf: [ 'tag1', 'tag2' ] }) 107 const customQuery1 = immutableAssign(query, { tagsOneOf: [ 'tag1', 'tag2' ] })
107 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 200 }) 108 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 })
108 109
109 const customQuery2 = immutableAssign(query, { tagsOneOf: 'tag1' }) 110 const customQuery2 = immutableAssign(query, { tagsOneOf: 'tag1' })
110 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 200 }) 111 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 })
111 112
112 const customQuery3 = immutableAssign(query, { tagsAllOf: [ 'tag1', 'tag2' ] }) 113 const customQuery3 = immutableAssign(query, { tagsAllOf: [ 'tag1', 'tag2' ] })
113 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: 200 }) 114 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.OK_200 })
114 115
115 const customQuery4 = immutableAssign(query, { tagsAllOf: 'tag1' }) 116 const customQuery4 = immutableAssign(query, { tagsAllOf: 'tag1' })
116 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: 200 }) 117 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.OK_200 })
117 }) 118 })
118 119
119 it('Should fail with invalid durations', async function () { 120 it('Should fail with invalid durations', async function () {
120 const customQuery1 = immutableAssign(query, { durationMin: 'hello' }) 121 const customQuery1 = immutableAssign(query, { durationMin: 'hello' })
121 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 }) 122 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
122 123
123 const customQuery2 = immutableAssign(query, { durationMax: 'hello' }) 124 const customQuery2 = immutableAssign(query, { durationMax: 'hello' })
124 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 }) 125 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
125 }) 126 })
126 127
127 it('Should fail with invalid dates', async function () { 128 it('Should fail with invalid dates', async function () {
128 const customQuery1 = immutableAssign(query, { startDate: 'hello' }) 129 const customQuery1 = immutableAssign(query, { startDate: 'hello' })
129 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: 400 }) 130 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
130 131
131 const customQuery2 = immutableAssign(query, { endDate: 'hello' }) 132 const customQuery2 = immutableAssign(query, { endDate: 'hello' })
132 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 }) 133 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
133 134
134 const customQuery3 = immutableAssign(query, { originallyPublishedStartDate: 'hello' }) 135 const customQuery3 = immutableAssign(query, { originallyPublishedStartDate: 'hello' })
135 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: 400 }) 136 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
136 137
137 const customQuery4 = immutableAssign(query, { originallyPublishedEndDate: 'hello' }) 138 const customQuery4 = immutableAssign(query, { originallyPublishedEndDate: 'hello' })
138 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: 400 }) 139 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
139 }) 140 })
140 }) 141 })
141 142
@@ -159,7 +160,7 @@ describe('Test videos API validator', function () {
159 }) 160 })
160 161
161 it('Should success with the correct parameters', async function () { 162 it('Should success with the correct parameters', async function () {
162 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: 200 }) 163 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 })
163 }) 164 })
164 }) 165 })
165 166
@@ -177,41 +178,41 @@ describe('Test videos API validator', function () {
177 for (const path of paths) { 178 for (const path of paths) {
178 { 179 {
179 const customQuery = immutableAssign(query, { searchTarget: 'hello' }) 180 const customQuery = immutableAssign(query, { searchTarget: 'hello' })
180 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 400 }) 181 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
181 } 182 }
182 183
183 { 184 {
184 const customQuery = immutableAssign(query, { searchTarget: undefined }) 185 const customQuery = immutableAssign(query, { searchTarget: undefined })
185 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 200 }) 186 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
186 } 187 }
187 188
188 { 189 {
189 const customQuery = immutableAssign(query, { searchTarget: 'local' }) 190 const customQuery = immutableAssign(query, { searchTarget: 'local' })
190 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 200 }) 191 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
191 } 192 }
192 193
193 { 194 {
194 const customQuery = immutableAssign(query, { searchTarget: 'search-index' }) 195 const customQuery = immutableAssign(query, { searchTarget: 'search-index' })
195 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 400 }) 196 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
196 } 197 }
197 198
198 await updateSearchIndex(server, true, true) 199 await updateSearchIndex(server, true, true)
199 200
200 { 201 {
201 const customQuery = immutableAssign(query, { searchTarget: 'local' }) 202 const customQuery = immutableAssign(query, { searchTarget: 'local' })
202 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 400 }) 203 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 })
203 } 204 }
204 205
205 { 206 {
206 const customQuery = immutableAssign(query, { searchTarget: 'search-index' }) 207 const customQuery = immutableAssign(query, { searchTarget: 'search-index' })
207 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 200 }) 208 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
208 } 209 }
209 210
210 await updateSearchIndex(server, true, false) 211 await updateSearchIndex(server, true, false)
211 212
212 { 213 {
213 const customQuery = immutableAssign(query, { searchTarget: 'local' }) 214 const customQuery = immutableAssign(query, { searchTarget: 'local' })
214 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: 200 }) 215 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 })
215 } 216 }
216 217
217 await updateSearchIndex(server, false, false) 218 await updateSearchIndex(server, false, false)
diff --git a/server/tests/api/check-params/services.ts b/server/tests/api/check-params/services.ts
index e57edd9e4..514e3da70 100644
--- a/server/tests/api/check-params/services.ts
+++ b/server/tests/api/check-params/services.ts
@@ -13,6 +13,7 @@ import {
13 setDefaultVideoChannel 13 setDefaultVideoChannel
14} from '../../../../shared/extra-utils' 14} from '../../../../shared/extra-utils'
15import { VideoPlaylistPrivacy } from '@shared/models' 15import { VideoPlaylistPrivacy } from '@shared/models'
16import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
16 17
17describe('Test services API validators', function () { 18describe('Test services API validators', function () {
18 let server: ServerInfo 19 let server: ServerInfo
@@ -66,7 +67,7 @@ describe('Test services API validators', function () {
66 67
67 it('Should fail with an unknown element', async function () { 68 it('Should fail with an unknown element', async function () {
68 const embedUrl = `http://localhost:${server.port}/videos/watch/88fc0165-d1f0-4a35-a51a-3b47f668689c` 69 const embedUrl = `http://localhost:${server.port}/videos/watch/88fc0165-d1f0-4a35-a51a-3b47f668689c`
69 await checkParamEmbed(server, embedUrl, 404) 70 await checkParamEmbed(server, embedUrl, HttpStatusCode.NOT_FOUND_404)
70 }) 71 })
71 72
72 it('Should fail with an invalid path', async function () { 73 it('Should fail with an invalid path', async function () {
@@ -78,25 +79,25 @@ describe('Test services API validators', function () {
78 it('Should fail with an invalid max height', async function () { 79 it('Should fail with an invalid max height', async function () {
79 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` 80 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
80 81
81 await checkParamEmbed(server, embedUrl, 400, { maxheight: 'hello' }) 82 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxheight: 'hello' })
82 }) 83 })
83 84
84 it('Should fail with an invalid max width', async function () { 85 it('Should fail with an invalid max width', async function () {
85 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` 86 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
86 87
87 await checkParamEmbed(server, embedUrl, 400, { maxwidth: 'hello' }) 88 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxwidth: 'hello' })
88 }) 89 })
89 90
90 it('Should fail with an invalid format', async function () { 91 it('Should fail with an invalid format', async function () {
91 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` 92 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
92 93
93 await checkParamEmbed(server, embedUrl, 400, { format: 'blabla' }) 94 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { format: 'blabla' })
94 }) 95 })
95 96
96 it('Should fail with a non supported format', async function () { 97 it('Should fail with a non supported format', async function () {
97 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` 98 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}`
98 99
99 await checkParamEmbed(server, embedUrl, 501, { format: 'xml' }) 100 await checkParamEmbed(server, embedUrl, HttpStatusCode.NOT_IMPLEMENTED_501, { format: 'xml' })
100 }) 101 })
101 102
102 it('Should succeed with the correct params with a video', async function () { 103 it('Should succeed with the correct params with a video', async function () {
@@ -107,7 +108,7 @@ describe('Test services API validators', function () {
107 maxwidth: 400 108 maxwidth: 400
108 } 109 }
109 110
110 await checkParamEmbed(server, embedUrl, 200, query) 111 await checkParamEmbed(server, embedUrl, HttpStatusCode.OK_200, query)
111 }) 112 })
112 113
113 it('Should succeed with the correct params with a playlist', async function () { 114 it('Should succeed with the correct params with a playlist', async function () {
@@ -118,7 +119,7 @@ describe('Test services API validators', function () {
118 maxwidth: 400 119 maxwidth: 400
119 } 120 }
120 121
121 await checkParamEmbed(server, embedUrl, 200, query) 122 await checkParamEmbed(server, embedUrl, HttpStatusCode.OK_200, query)
122 }) 123 })
123 }) 124 })
124 125
@@ -127,7 +128,7 @@ describe('Test services API validators', function () {
127 }) 128 })
128}) 129})
129 130
130function checkParamEmbed (server: ServerInfo, embedUrl: string, statusCodeExpected = 400, query = {}) { 131function checkParamEmbed (server: ServerInfo, embedUrl: string, statusCodeExpected = HttpStatusCode.BAD_REQUEST_400, query = {}) {
131 const path = '/services/oembed' 132 const path = '/services/oembed'
132 133
133 return makeGetRequest({ 134 return makeGetRequest({
diff --git a/server/tests/api/check-params/user-notifications.ts b/server/tests/api/check-params/user-notifications.ts
index 6fa0502be..05a78b0ad 100644
--- a/server/tests/api/check-params/user-notifications.ts
+++ b/server/tests/api/check-params/user-notifications.ts
@@ -20,6 +20,7 @@ import {
20 checkBadStartPagination 20 checkBadStartPagination
21} from '../../../../shared/extra-utils/requests/check-api-params' 21} from '../../../../shared/extra-utils/requests/check-api-params'
22import { UserNotificationSetting, UserNotificationSettingValue } from '../../../../shared/models/users' 22import { UserNotificationSetting, UserNotificationSettingValue } from '../../../../shared/models/users'
23import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
23 24
24describe('Test user notifications API validators', function () { 25describe('Test user notifications API validators', function () {
25 let server: ServerInfo 26 let server: ServerInfo
@@ -57,7 +58,7 @@ describe('Test user notifications API validators', function () {
57 unread: 'toto' 58 unread: 'toto'
58 }, 59 },
59 token: server.accessToken, 60 token: server.accessToken,
60 statusCodeExpected: 200 61 statusCodeExpected: HttpStatusCode.OK_200
61 }) 62 })
62 }) 63 })
63 64
@@ -65,7 +66,7 @@ describe('Test user notifications API validators', function () {
65 await makeGetRequest({ 66 await makeGetRequest({
66 url: server.url, 67 url: server.url,
67 path, 68 path,
68 statusCodeExpected: 401 69 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
69 }) 70 })
70 }) 71 })
71 72
@@ -74,7 +75,7 @@ describe('Test user notifications API validators', function () {
74 url: server.url, 75 url: server.url,
75 path, 76 path,
76 token: server.accessToken, 77 token: server.accessToken,
77 statusCodeExpected: 200 78 statusCodeExpected: HttpStatusCode.OK_200
78 }) 79 })
79 }) 80 })
80 }) 81 })
@@ -90,7 +91,7 @@ describe('Test user notifications API validators', function () {
90 ids: [ 'hello' ] 91 ids: [ 'hello' ]
91 }, 92 },
92 token: server.accessToken, 93 token: server.accessToken,
93 statusCodeExpected: 400 94 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
94 }) 95 })
95 96
96 await makePostBodyRequest({ 97 await makePostBodyRequest({
@@ -100,7 +101,7 @@ describe('Test user notifications API validators', function () {
100 ids: [ ] 101 ids: [ ]
101 }, 102 },
102 token: server.accessToken, 103 token: server.accessToken,
103 statusCodeExpected: 400 104 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
104 }) 105 })
105 106
106 await makePostBodyRequest({ 107 await makePostBodyRequest({
@@ -110,7 +111,7 @@ describe('Test user notifications API validators', function () {
110 ids: 5 111 ids: 5
111 }, 112 },
112 token: server.accessToken, 113 token: server.accessToken,
113 statusCodeExpected: 400 114 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
114 }) 115 })
115 }) 116 })
116 117
@@ -121,7 +122,7 @@ describe('Test user notifications API validators', function () {
121 fields: { 122 fields: {
122 ids: [ 5 ] 123 ids: [ 5 ]
123 }, 124 },
124 statusCodeExpected: 401 125 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
125 }) 126 })
126 }) 127 })
127 128
@@ -133,7 +134,7 @@ describe('Test user notifications API validators', function () {
133 ids: [ 5 ] 134 ids: [ 5 ]
134 }, 135 },
135 token: server.accessToken, 136 token: server.accessToken,
136 statusCodeExpected: 204 137 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
137 }) 138 })
138 }) 139 })
139 }) 140 })
@@ -145,7 +146,7 @@ describe('Test user notifications API validators', function () {
145 await makePostBodyRequest({ 146 await makePostBodyRequest({
146 url: server.url, 147 url: server.url,
147 path, 148 path,
148 statusCodeExpected: 401 149 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
149 }) 150 })
150 }) 151 })
151 152
@@ -154,7 +155,7 @@ describe('Test user notifications API validators', function () {
154 url: server.url, 155 url: server.url,
155 path, 156 path,
156 token: server.accessToken, 157 token: server.accessToken,
157 statusCodeExpected: 204 158 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
158 }) 159 })
159 }) 160 })
160 }) 161 })
@@ -184,7 +185,7 @@ describe('Test user notifications API validators', function () {
184 path, 185 path,
185 token: server.accessToken, 186 token: server.accessToken,
186 fields: { newVideoFromSubscription: UserNotificationSettingValue.WEB }, 187 fields: { newVideoFromSubscription: UserNotificationSettingValue.WEB },
187 statusCodeExpected: 400 188 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
188 }) 189 })
189 }) 190 })
190 191
@@ -197,7 +198,7 @@ describe('Test user notifications API validators', function () {
197 path, 198 path,
198 token: server.accessToken, 199 token: server.accessToken,
199 fields, 200 fields,
200 statusCodeExpected: 400 201 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
201 }) 202 })
202 } 203 }
203 204
@@ -209,7 +210,7 @@ describe('Test user notifications API validators', function () {
209 path, 210 path,
210 fields, 211 fields,
211 token: server.accessToken, 212 token: server.accessToken,
212 statusCodeExpected: 400 213 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
213 }) 214 })
214 } 215 }
215 }) 216 })
@@ -219,7 +220,7 @@ describe('Test user notifications API validators', function () {
219 url: server.url, 220 url: server.url,
220 path, 221 path,
221 fields: correctFields, 222 fields: correctFields,
222 statusCodeExpected: 401 223 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
223 }) 224 })
224 }) 225 })
225 226
@@ -229,7 +230,7 @@ describe('Test user notifications API validators', function () {
229 path, 230 path,
230 token: server.accessToken, 231 token: server.accessToken,
231 fields: correctFields, 232 fields: correctFields,
232 statusCodeExpected: 204 233 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
233 }) 234 })
234 }) 235 })
235 }) 236 })
diff --git a/server/tests/api/check-params/user-subscriptions.ts b/server/tests/api/check-params/user-subscriptions.ts
index 1edba4d64..538201647 100644
--- a/server/tests/api/check-params/user-subscriptions.ts
+++ b/server/tests/api/check-params/user-subscriptions.ts
@@ -20,6 +20,7 @@ import {
20 checkBadStartPagination 20 checkBadStartPagination
21} from '../../../../shared/extra-utils/requests/check-api-params' 21} from '../../../../shared/extra-utils/requests/check-api-params'
22import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 22import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
23import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
23 24
24describe('Test user subscriptions API validators', function () { 25describe('Test user subscriptions API validators', function () {
25 const path = '/api/v1/users/me/subscriptions' 26 const path = '/api/v1/users/me/subscriptions'
@@ -60,7 +61,7 @@ describe('Test user subscriptions API validators', function () {
60 await makeGetRequest({ 61 await makeGetRequest({
61 url: server.url, 62 url: server.url,
62 path, 63 path,
63 statusCodeExpected: 401 64 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
64 }) 65 })
65 }) 66 })
66 67
@@ -69,7 +70,7 @@ describe('Test user subscriptions API validators', function () {
69 url: server.url, 70 url: server.url,
70 path, 71 path,
71 token: userAccessToken, 72 token: userAccessToken,
72 statusCodeExpected: 200 73 statusCodeExpected: HttpStatusCode.OK_200
73 }) 74 })
74 }) 75 })
75 }) 76 })
@@ -93,7 +94,7 @@ describe('Test user subscriptions API validators', function () {
93 await makeGetRequest({ 94 await makeGetRequest({
94 url: server.url, 95 url: server.url,
95 path, 96 path,
96 statusCodeExpected: 401 97 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
97 }) 98 })
98 }) 99 })
99 100
@@ -102,7 +103,7 @@ describe('Test user subscriptions API validators', function () {
102 url: server.url, 103 url: server.url,
103 path, 104 path,
104 token: userAccessToken, 105 token: userAccessToken,
105 statusCodeExpected: 200 106 statusCodeExpected: HttpStatusCode.OK_200
106 }) 107 })
107 }) 108 })
108 }) 109 })
@@ -113,7 +114,7 @@ describe('Test user subscriptions API validators', function () {
113 url: server.url, 114 url: server.url,
114 path, 115 path,
115 fields: { uri: 'user1_channel@localhost:' + server.port }, 116 fields: { uri: 'user1_channel@localhost:' + server.port },
116 statusCodeExpected: 401 117 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
117 }) 118 })
118 }) 119 })
119 120
@@ -123,7 +124,7 @@ describe('Test user subscriptions API validators', function () {
123 path, 124 path,
124 token: server.accessToken, 125 token: server.accessToken,
125 fields: { uri: 'root' }, 126 fields: { uri: 'root' },
126 statusCodeExpected: 400 127 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
127 }) 128 })
128 129
129 await makePostBodyRequest({ 130 await makePostBodyRequest({
@@ -131,7 +132,7 @@ describe('Test user subscriptions API validators', function () {
131 path, 132 path,
132 token: server.accessToken, 133 token: server.accessToken,
133 fields: { uri: 'root@' }, 134 fields: { uri: 'root@' },
134 statusCodeExpected: 400 135 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
135 }) 136 })
136 137
137 await makePostBodyRequest({ 138 await makePostBodyRequest({
@@ -139,7 +140,7 @@ describe('Test user subscriptions API validators', function () {
139 path, 140 path,
140 token: server.accessToken, 141 token: server.accessToken,
141 fields: { uri: 'root@hello@' }, 142 fields: { uri: 'root@hello@' },
142 statusCodeExpected: 400 143 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
143 }) 144 })
144 }) 145 })
145 146
@@ -151,7 +152,7 @@ describe('Test user subscriptions API validators', function () {
151 path, 152 path,
152 token: server.accessToken, 153 token: server.accessToken,
153 fields: { uri: 'user1_channel@localhost:' + server.port }, 154 fields: { uri: 'user1_channel@localhost:' + server.port },
154 statusCodeExpected: 204 155 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
155 }) 156 })
156 157
157 await waitJobs([ server ]) 158 await waitJobs([ server ])
@@ -163,7 +164,7 @@ describe('Test user subscriptions API validators', function () {
163 await makeGetRequest({ 164 await makeGetRequest({
164 url: server.url, 165 url: server.url,
165 path: path + '/user1_channel@localhost:' + server.port, 166 path: path + '/user1_channel@localhost:' + server.port,
166 statusCodeExpected: 401 167 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
167 }) 168 })
168 }) 169 })
169 170
@@ -172,21 +173,21 @@ describe('Test user subscriptions API validators', function () {
172 url: server.url, 173 url: server.url,
173 path: path + '/root', 174 path: path + '/root',
174 token: server.accessToken, 175 token: server.accessToken,
175 statusCodeExpected: 400 176 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
176 }) 177 })
177 178
178 await makeGetRequest({ 179 await makeGetRequest({
179 url: server.url, 180 url: server.url,
180 path: path + '/root@', 181 path: path + '/root@',
181 token: server.accessToken, 182 token: server.accessToken,
182 statusCodeExpected: 400 183 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
183 }) 184 })
184 185
185 await makeGetRequest({ 186 await makeGetRequest({
186 url: server.url, 187 url: server.url,
187 path: path + '/root@hello@', 188 path: path + '/root@hello@',
188 token: server.accessToken, 189 token: server.accessToken,
189 statusCodeExpected: 400 190 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
190 }) 191 })
191 }) 192 })
192 193
@@ -195,7 +196,7 @@ describe('Test user subscriptions API validators', function () {
195 url: server.url, 196 url: server.url,
196 path: path + '/root1@localhost:' + server.port, 197 path: path + '/root1@localhost:' + server.port,
197 token: server.accessToken, 198 token: server.accessToken,
198 statusCodeExpected: 404 199 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
199 }) 200 })
200 }) 201 })
201 202
@@ -204,7 +205,7 @@ describe('Test user subscriptions API validators', function () {
204 url: server.url, 205 url: server.url,
205 path: path + '/user1_channel@localhost:' + server.port, 206 path: path + '/user1_channel@localhost:' + server.port,
206 token: server.accessToken, 207 token: server.accessToken,
207 statusCodeExpected: 200 208 statusCodeExpected: HttpStatusCode.OK_200
208 }) 209 })
209 }) 210 })
210 }) 211 })
@@ -216,7 +217,7 @@ describe('Test user subscriptions API validators', function () {
216 await makeGetRequest({ 217 await makeGetRequest({
217 url: server.url, 218 url: server.url,
218 path: existPath, 219 path: existPath,
219 statusCodeExpected: 401 220 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
220 }) 221 })
221 }) 222 })
222 223
@@ -226,7 +227,7 @@ describe('Test user subscriptions API validators', function () {
226 path: existPath, 227 path: existPath,
227 query: { uris: 'toto' }, 228 query: { uris: 'toto' },
228 token: server.accessToken, 229 token: server.accessToken,
229 statusCodeExpected: 400 230 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
230 }) 231 })
231 232
232 await makeGetRequest({ 233 await makeGetRequest({
@@ -234,7 +235,7 @@ describe('Test user subscriptions API validators', function () {
234 path: existPath, 235 path: existPath,
235 query: { 'uris[]': 1 }, 236 query: { 'uris[]': 1 },
236 token: server.accessToken, 237 token: server.accessToken,
237 statusCodeExpected: 400 238 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
238 }) 239 })
239 }) 240 })
240 241
@@ -244,7 +245,7 @@ describe('Test user subscriptions API validators', function () {
244 path: existPath, 245 path: existPath,
245 query: { 'uris[]': 'coucou@localhost:' + server.port }, 246 query: { 'uris[]': 'coucou@localhost:' + server.port },
246 token: server.accessToken, 247 token: server.accessToken,
247 statusCodeExpected: 200 248 statusCodeExpected: HttpStatusCode.OK_200
248 }) 249 })
249 }) 250 })
250 }) 251 })
@@ -254,7 +255,7 @@ describe('Test user subscriptions API validators', function () {
254 await makeDeleteRequest({ 255 await makeDeleteRequest({
255 url: server.url, 256 url: server.url,
256 path: path + '/user1_channel@localhost:' + server.port, 257 path: path + '/user1_channel@localhost:' + server.port,
257 statusCodeExpected: 401 258 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
258 }) 259 })
259 }) 260 })
260 261
@@ -263,21 +264,21 @@ describe('Test user subscriptions API validators', function () {
263 url: server.url, 264 url: server.url,
264 path: path + '/root', 265 path: path + '/root',
265 token: server.accessToken, 266 token: server.accessToken,
266 statusCodeExpected: 400 267 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
267 }) 268 })
268 269
269 await makeDeleteRequest({ 270 await makeDeleteRequest({
270 url: server.url, 271 url: server.url,
271 path: path + '/root@', 272 path: path + '/root@',
272 token: server.accessToken, 273 token: server.accessToken,
273 statusCodeExpected: 400 274 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
274 }) 275 })
275 276
276 await makeDeleteRequest({ 277 await makeDeleteRequest({
277 url: server.url, 278 url: server.url,
278 path: path + '/root@hello@', 279 path: path + '/root@hello@',
279 token: server.accessToken, 280 token: server.accessToken,
280 statusCodeExpected: 400 281 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
281 }) 282 })
282 }) 283 })
283 284
@@ -286,7 +287,7 @@ describe('Test user subscriptions API validators', function () {
286 url: server.url, 287 url: server.url,
287 path: path + '/root1@localhost:' + server.port, 288 path: path + '/root1@localhost:' + server.port,
288 token: server.accessToken, 289 token: server.accessToken,
289 statusCodeExpected: 404 290 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
290 }) 291 })
291 }) 292 })
292 293
@@ -295,7 +296,7 @@ describe('Test user subscriptions API validators', function () {
295 url: server.url, 296 url: server.url,
296 path: path + '/user1_channel@localhost:' + server.port, 297 path: path + '/user1_channel@localhost:' + server.port,
297 token: server.accessToken, 298 token: server.accessToken,
298 statusCodeExpected: 204 299 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
299 }) 300 })
300 }) 301 })
301 }) 302 })
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts
index da7dc9704..21ace36aa 100644
--- a/server/tests/api/check-params/users.ts
+++ b/server/tests/api/check-params/users.ts
@@ -43,6 +43,7 @@ import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
43import { getGoodVideoUrl, getMagnetURI, getMyVideoImports, importVideo } from '../../../../shared/extra-utils/videos/video-imports' 43import { getGoodVideoUrl, getMagnetURI, getMyVideoImports, importVideo } from '../../../../shared/extra-utils/videos/video-imports'
44import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' 44import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
45import { VideoPrivacy } from '../../../../shared/models/videos' 45import { VideoPrivacy } from '../../../../shared/models/videos'
46import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
46 47
47describe('Test users API validators', function () { 48describe('Test users API validators', function () {
48 const path = '/api/v1/users/' 49 const path = '/api/v1/users/'
@@ -160,7 +161,7 @@ describe('Test users API validators', function () {
160 await makeGetRequest({ 161 await makeGetRequest({
161 url: server.url, 162 url: server.url,
162 path, 163 path,
163 statusCodeExpected: 401 164 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
164 }) 165 })
165 }) 166 })
166 167
@@ -169,7 +170,7 @@ describe('Test users API validators', function () {
169 url: server.url, 170 url: server.url,
170 path, 171 path,
171 token: userAccessToken, 172 token: userAccessToken,
172 statusCodeExpected: 403 173 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
173 }) 174 })
174 }) 175 })
175 }) 176 })
@@ -263,7 +264,7 @@ describe('Test users API validators', function () {
263 path: path, 264 path: path,
264 token: server.accessToken, 265 token: server.accessToken,
265 fields, 266 fields,
266 statusCodeExpected: 200 267 statusCodeExpected: HttpStatusCode.OK_200
267 }) 268 })
268 }) 269 })
269 270
@@ -279,20 +280,32 @@ describe('Test users API validators', function () {
279 path, 280 path,
280 token: 'super token', 281 token: 'super token',
281 fields: baseCorrectParams, 282 fields: baseCorrectParams,
282 statusCodeExpected: 401 283 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
283 }) 284 })
284 }) 285 })
285 286
286 it('Should fail if we add a user with the same username', async function () { 287 it('Should fail if we add a user with the same username', async function () {
287 const fields = immutableAssign(baseCorrectParams, { username: 'user1' }) 288 const fields = immutableAssign(baseCorrectParams, { username: 'user1' })
288 289
289 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 }) 290 await makePostBodyRequest({
291 url: server.url,
292 path,
293 token: server.accessToken,
294 fields,
295 statusCodeExpected: HttpStatusCode.CONFLICT_409
296 })
290 }) 297 })
291 298
292 it('Should fail if we add a user with the same email', async function () { 299 it('Should fail if we add a user with the same email', async function () {
293 const fields = immutableAssign(baseCorrectParams, { email: 'user1@example.com' }) 300 const fields = immutableAssign(baseCorrectParams, { email: 'user1@example.com' })
294 301
295 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 }) 302 await makePostBodyRequest({
303 url: server.url,
304 path,
305 token: server.accessToken,
306 fields,
307 statusCodeExpected: HttpStatusCode.CONFLICT_409
308 })
296 }) 309 })
297 310
298 it('Should fail without a videoQuota', async function () { 311 it('Should fail without a videoQuota', async function () {
@@ -339,7 +352,7 @@ describe('Test users API validators', function () {
339 path, 352 path,
340 token: server.accessToken, 353 token: server.accessToken,
341 fields, 354 fields,
342 statusCodeExpected: 409 355 statusCodeExpected: HttpStatusCode.CONFLICT_409
343 }) 356 })
344 }) 357 })
345 358
@@ -352,7 +365,7 @@ describe('Test users API validators', function () {
352 path, 365 path,
353 token: moderatorAccessToken, 366 token: moderatorAccessToken,
354 fields, 367 fields,
355 statusCodeExpected: 403 368 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
356 }) 369 })
357 } 370 }
358 }) 371 })
@@ -365,7 +378,7 @@ describe('Test users API validators', function () {
365 path, 378 path,
366 token: moderatorAccessToken, 379 token: moderatorAccessToken,
367 fields, 380 fields,
368 statusCodeExpected: 200 381 statusCodeExpected: HttpStatusCode.OK_200
369 }) 382 })
370 }) 383 })
371 384
@@ -375,7 +388,7 @@ describe('Test users API validators', function () {
375 path, 388 path,
376 token: server.accessToken, 389 token: server.accessToken,
377 fields: baseCorrectParams, 390 fields: baseCorrectParams,
378 statusCodeExpected: 200 391 statusCodeExpected: HttpStatusCode.OK_200
379 }) 392 })
380 }) 393 })
381 394
@@ -392,7 +405,7 @@ describe('Test users API validators', function () {
392 password: 'my super password', 405 password: 'my super password',
393 videoQuota: 42000000 406 videoQuota: 42000000
394 } 407 }
395 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: 403 }) 408 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
396 }) 409 })
397 }) 410 })
398 411
@@ -438,7 +451,13 @@ describe('Test users API validators', function () {
438 password: 'super'.repeat(61) 451 password: 'super'.repeat(61)
439 } 452 }
440 453
441 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 401 }) 454 await makePutBodyRequest({
455 url: server.url,
456 path: path + 'me',
457 token: userAccessToken,
458 fields,
459 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
460 })
442 }) 461 })
443 462
444 it('Should fail with an invalid NSFW policy attribute', async function () { 463 it('Should fail with an invalid NSFW policy attribute', async function () {
@@ -479,7 +498,13 @@ describe('Test users API validators', function () {
479 password: 'my super password' 498 password: 'my super password'
480 } 499 }
481 500
482 await makePutBodyRequest({ url: server.url, path: path + 'me', token: 'super token', fields, statusCodeExpected: 401 }) 501 await makePutBodyRequest({
502 url: server.url,
503 path: path + 'me',
504 token: 'super token',
505 fields,
506 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
507 })
483 }) 508 })
484 509
485 it('Should fail with a too long description', async function () { 510 it('Should fail with a too long description', async function () {
@@ -551,7 +576,13 @@ describe('Test users API validators', function () {
551 noWelcomeModal: true 576 noWelcomeModal: true
552 } 577 }
553 578
554 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 }) 579 await makePutBodyRequest({
580 url: server.url,
581 path: path + 'me',
582 token: userAccessToken,
583 fields,
584 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
585 })
555 }) 586 })
556 587
557 it('Should succeed without password change with the correct params', async function () { 588 it('Should succeed without password change with the correct params', async function () {
@@ -560,7 +591,13 @@ describe('Test users API validators', function () {
560 autoPlayVideo: false 591 autoPlayVideo: false
561 } 592 }
562 593
563 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 }) 594 await makePutBodyRequest({
595 url: server.url,
596 path: path + 'me',
597 token: userAccessToken,
598 fields,
599 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
600 })
564 }) 601 })
565 }) 602 })
566 603
@@ -591,7 +628,7 @@ describe('Test users API validators', function () {
591 path: path + '/me/avatar/pick', 628 path: path + '/me/avatar/pick',
592 fields, 629 fields,
593 attaches, 630 attaches,
594 statusCodeExpected: 401 631 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
595 }) 632 })
596 }) 633 })
597 634
@@ -606,7 +643,7 @@ describe('Test users API validators', function () {
606 token: server.accessToken, 643 token: server.accessToken,
607 fields, 644 fields,
608 attaches, 645 attaches,
609 statusCodeExpected: 200 646 statusCodeExpected: HttpStatusCode.OK_200
610 }) 647 })
611 }) 648 })
612 }) 649 })
@@ -614,11 +651,11 @@ describe('Test users API validators', function () {
614 describe('When managing my scoped tokens', function () { 651 describe('When managing my scoped tokens', function () {
615 652
616 it('Should fail to get my scoped tokens with an non authenticated user', async function () { 653 it('Should fail to get my scoped tokens with an non authenticated user', async function () {
617 await getUserScopedTokens(server.url, null, 401) 654 await getUserScopedTokens(server.url, null, HttpStatusCode.UNAUTHORIZED_401)
618 }) 655 })
619 656
620 it('Should fail to get my scoped tokens with a bad token', async function () { 657 it('Should fail to get my scoped tokens with a bad token', async function () {
621 await getUserScopedTokens(server.url, 'bad', 401) 658 await getUserScopedTokens(server.url, 'bad', HttpStatusCode.UNAUTHORIZED_401)
622 659
623 }) 660 })
624 661
@@ -627,11 +664,11 @@ describe('Test users API validators', function () {
627 }) 664 })
628 665
629 it('Should fail to renew my scoped tokens with an non authenticated user', async function () { 666 it('Should fail to renew my scoped tokens with an non authenticated user', async function () {
630 await renewUserScopedTokens(server.url, null, 401) 667 await renewUserScopedTokens(server.url, null, HttpStatusCode.UNAUTHORIZED_401)
631 }) 668 })
632 669
633 it('Should fail to renew my scoped tokens with a bad token', async function () { 670 it('Should fail to renew my scoped tokens with a bad token', async function () {
634 await renewUserScopedTokens(server.url, 'bad', 401) 671 await renewUserScopedTokens(server.url, 'bad', HttpStatusCode.UNAUTHORIZED_401)
635 }) 672 })
636 673
637 it('Should succeed to renew my scoped tokens', async function () { 674 it('Should succeed to renew my scoped tokens', async function () {
@@ -642,15 +679,20 @@ describe('Test users API validators', function () {
642 describe('When getting a user', function () { 679 describe('When getting a user', function () {
643 680
644 it('Should fail with an non authenticated user', async function () { 681 it('Should fail with an non authenticated user', async function () {
645 await makeGetRequest({ url: server.url, path: path + userId, token: 'super token', statusCodeExpected: 401 }) 682 await makeGetRequest({
683 url: server.url,
684 path: path + userId,
685 token: 'super token',
686 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
687 })
646 }) 688 })
647 689
648 it('Should fail with a non admin user', async function () { 690 it('Should fail with a non admin user', async function () {
649 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 403 }) 691 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
650 }) 692 })
651 693
652 it('Should succeed with the correct params', async function () { 694 it('Should succeed with the correct params', async function () {
653 await makeGetRequest({ url: server.url, path: path + userId, token: server.accessToken, statusCodeExpected: 200 }) 695 await makeGetRequest({ url: server.url, path: path + userId, token: server.accessToken, statusCodeExpected: HttpStatusCode.OK_200 })
654 }) 696 })
655 }) 697 })
656 698
@@ -711,7 +753,13 @@ describe('Test users API validators', function () {
711 videoQuota: 42 753 videoQuota: 42
712 } 754 }
713 755
714 await makePutBodyRequest({ url: server.url, path: path + userId, token: 'super token', fields, statusCodeExpected: 401 }) 756 await makePutBodyRequest({
757 url: server.url,
758 path: path + userId,
759 token: 'super token',
760 fields,
761 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
762 })
715 }) 763 })
716 764
717 it('Should fail when updating root role', async function () { 765 it('Should fail when updating root role', async function () {
@@ -738,7 +786,7 @@ describe('Test users API validators', function () {
738 path: path + moderatorId, 786 path: path + moderatorId,
739 token: moderatorAccessToken, 787 token: moderatorAccessToken,
740 fields, 788 fields,
741 statusCodeExpected: 403 789 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
742 }) 790 })
743 }) 791 })
744 792
@@ -752,7 +800,7 @@ describe('Test users API validators', function () {
752 path: path + userId, 800 path: path + userId,
753 token: moderatorAccessToken, 801 token: moderatorAccessToken,
754 fields, 802 fields,
755 statusCodeExpected: 204 803 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
756 }) 804 })
757 }) 805 })
758 806
@@ -764,13 +812,19 @@ describe('Test users API validators', function () {
764 role: UserRole.USER 812 role: UserRole.USER
765 } 813 }
766 814
767 await makePutBodyRequest({ url: server.url, path: path + userId, token: server.accessToken, fields, statusCodeExpected: 204 }) 815 await makePutBodyRequest({
816 url: server.url,
817 path: path + userId,
818 token: server.accessToken,
819 fields,
820 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
821 })
768 }) 822 })
769 }) 823 })
770 824
771 describe('When getting my information', function () { 825 describe('When getting my information', function () {
772 it('Should fail with a non authenticated user', async function () { 826 it('Should fail with a non authenticated user', async function () {
773 await getMyUserInformation(server.url, 'fake_token', 401) 827 await getMyUserInformation(server.url, 'fake_token', HttpStatusCode.UNAUTHORIZED_401)
774 }) 828 })
775 829
776 it('Should success with the correct parameters', async function () { 830 it('Should success with the correct parameters', async function () {
@@ -780,15 +834,15 @@ describe('Test users API validators', function () {
780 834
781 describe('When getting my video rating', function () { 835 describe('When getting my video rating', function () {
782 it('Should fail with a non authenticated user', async function () { 836 it('Should fail with a non authenticated user', async function () {
783 await getMyUserVideoRating(server.url, 'fake_token', videoId, 401) 837 await getMyUserVideoRating(server.url, 'fake_token', videoId, HttpStatusCode.UNAUTHORIZED_401)
784 }) 838 })
785 839
786 it('Should fail with an incorrect video uuid', async function () { 840 it('Should fail with an incorrect video uuid', async function () {
787 await getMyUserVideoRating(server.url, server.accessToken, 'blabla', 400) 841 await getMyUserVideoRating(server.url, server.accessToken, 'blabla', HttpStatusCode.BAD_REQUEST_400)
788 }) 842 })
789 843
790 it('Should fail with an unknown video', async function () { 844 it('Should fail with an unknown video', async function () {
791 await getMyUserVideoRating(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404) 845 await getMyUserVideoRating(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404)
792 }) 846 })
793 847
794 it('Should succeed with the correct parameters', async function () { 848 it('Should succeed with the correct parameters', async function () {
@@ -812,51 +866,57 @@ describe('Test users API validators', function () {
812 }) 866 })
813 867
814 it('Should fail with a unauthenticated user', async function () { 868 it('Should fail with a unauthenticated user', async function () {
815 await makeGetRequest({ url: server.url, path, statusCodeExpected: 401 }) 869 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
816 }) 870 })
817 871
818 it('Should fail with a another user', async function () { 872 it('Should fail with a another user', async function () {
819 await makeGetRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 403 }) 873 await makeGetRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
820 }) 874 })
821 875
822 it('Should fail with a bad type', async function () { 876 it('Should fail with a bad type', async function () {
823 await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { rating: 'toto ' }, statusCodeExpected: 400 }) 877 await makeGetRequest({
878 url: server.url,
879 path,
880 token: userAccessToken,
881 query: { rating: 'toto ' },
882 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
883 })
824 }) 884 })
825 885
826 it('Should succeed with the correct params', async function () { 886 it('Should succeed with the correct params', async function () {
827 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 200 }) 887 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.OK_200 })
828 }) 888 })
829 }) 889 })
830 890
831 describe('When blocking/unblocking/removing user', function () { 891 describe('When blocking/unblocking/removing user', function () {
832 it('Should fail with an incorrect id', async function () { 892 it('Should fail with an incorrect id', async function () {
833 await removeUser(server.url, 'blabla', server.accessToken, 400) 893 await removeUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400)
834 await blockUser(server.url, 'blabla', server.accessToken, 400) 894 await blockUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400)
835 await unblockUser(server.url, 'blabla', server.accessToken, 400) 895 await unblockUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400)
836 }) 896 })
837 897
838 it('Should fail with the root user', async function () { 898 it('Should fail with the root user', async function () {
839 await removeUser(server.url, rootId, server.accessToken, 400) 899 await removeUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400)
840 await blockUser(server.url, rootId, server.accessToken, 400) 900 await blockUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400)
841 await unblockUser(server.url, rootId, server.accessToken, 400) 901 await unblockUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400)
842 }) 902 })
843 903
844 it('Should return 404 with a non existing id', async function () { 904 it('Should return 404 with a non existing id', async function () {
845 await removeUser(server.url, 4545454, server.accessToken, 404) 905 await removeUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404)
846 await blockUser(server.url, 4545454, server.accessToken, 404) 906 await blockUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404)
847 await unblockUser(server.url, 4545454, server.accessToken, 404) 907 await unblockUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404)
848 }) 908 })
849 909
850 it('Should fail with a non admin user', async function () { 910 it('Should fail with a non admin user', async function () {
851 await removeUser(server.url, userId, userAccessToken, 403) 911 await removeUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403)
852 await blockUser(server.url, userId, userAccessToken, 403) 912 await blockUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403)
853 await unblockUser(server.url, userId, userAccessToken, 403) 913 await unblockUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403)
854 }) 914 })
855 915
856 it('Should fail on a moderator with a moderator', async function () { 916 it('Should fail on a moderator with a moderator', async function () {
857 await removeUser(server.url, moderatorId, moderatorAccessToken, 403) 917 await removeUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403)
858 await blockUser(server.url, moderatorId, moderatorAccessToken, 403) 918 await blockUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403)
859 await unblockUser(server.url, moderatorId, moderatorAccessToken, 403) 919 await unblockUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403)
860 }) 920 })
861 921
862 it('Should succeed on a user with a moderator', async function () { 922 it('Should succeed on a user with a moderator', async function () {
@@ -867,7 +927,7 @@ describe('Test users API validators', function () {
867 927
868 describe('When deleting our account', function () { 928 describe('When deleting our account', function () {
869 it('Should fail with with the root account', async function () { 929 it('Should fail with with the root account', async function () {
870 await deleteMe(server.url, server.accessToken, 400) 930 await deleteMe(server.url, server.accessToken, HttpStatusCode.BAD_REQUEST_400)
871 }) 931 })
872 }) 932 })
873 933
@@ -930,7 +990,7 @@ describe('Test users API validators', function () {
930 path: registrationPath, 990 path: registrationPath,
931 token: server.accessToken, 991 token: server.accessToken,
932 fields, 992 fields,
933 statusCodeExpected: 409 993 statusCodeExpected: HttpStatusCode.CONFLICT_409
934 }) 994 })
935 }) 995 })
936 996
@@ -942,7 +1002,7 @@ describe('Test users API validators', function () {
942 path: registrationPath, 1002 path: registrationPath,
943 token: server.accessToken, 1003 token: server.accessToken,
944 fields, 1004 fields,
945 statusCodeExpected: 409 1005 statusCodeExpected: HttpStatusCode.CONFLICT_409
946 }) 1006 })
947 }) 1007 })
948 1008
@@ -954,7 +1014,7 @@ describe('Test users API validators', function () {
954 path: registrationPath, 1014 path: registrationPath,
955 token: server.accessToken, 1015 token: server.accessToken,
956 fields, 1016 fields,
957 statusCodeExpected: 409 1017 statusCodeExpected: HttpStatusCode.CONFLICT_409
958 }) 1018 })
959 }) 1019 })
960 1020
@@ -989,7 +1049,13 @@ describe('Test users API validators', function () {
989 1049
990 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'existing_channel', displayName: 'toto' } }) 1050 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'existing_channel', displayName: 'toto' } })
991 1051
992 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields, statusCodeExpected: 409 }) 1052 await makePostBodyRequest({
1053 url: server.url,
1054 path: registrationPath,
1055 token: server.accessToken,
1056 fields,
1057 statusCodeExpected: HttpStatusCode.CONFLICT_409
1058 })
993 }) 1059 })
994 1060
995 it('Should succeed with the correct params', async function () { 1061 it('Should succeed with the correct params', async function () {
@@ -1000,7 +1066,7 @@ describe('Test users API validators', function () {
1000 path: registrationPath, 1066 path: registrationPath,
1001 token: server.accessToken, 1067 token: server.accessToken,
1002 fields: fields, 1068 fields: fields,
1003 statusCodeExpected: 204 1069 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
1004 }) 1070 })
1005 }) 1071 })
1006 1072
@@ -1016,14 +1082,14 @@ describe('Test users API validators', function () {
1016 path: registrationPath, 1082 path: registrationPath,
1017 token: serverWithRegistrationDisabled.accessToken, 1083 token: serverWithRegistrationDisabled.accessToken,
1018 fields, 1084 fields,
1019 statusCodeExpected: 403 1085 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
1020 }) 1086 })
1021 }) 1087 })
1022 }) 1088 })
1023 1089
1024 describe('When registering multiple users on a server with users limit', function () { 1090 describe('When registering multiple users on a server with users limit', function () {
1025 it('Should fail when after 3 registrations', async function () { 1091 it('Should fail when after 3 registrations', async function () {
1026 await registerUser(server.url, 'user42', 'super password', 403) 1092 await registerUser(server.url, 'user42', 'super password', HttpStatusCode.FORBIDDEN_403)
1027 }) 1093 })
1028 }) 1094 })
1029 1095
@@ -1036,7 +1102,7 @@ describe('Test users API validators', function () {
1036 videoQuota: 42 1102 videoQuota: 42
1037 }) 1103 })
1038 1104
1039 await uploadVideo(server.url, server.accessToken, {}, 403) 1105 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.FORBIDDEN_403)
1040 }) 1106 })
1041 1107
1042 it('Should fail with a registered user having too many videos', async function () { 1108 it('Should fail with a registered user having too many videos', async function () {
@@ -1054,7 +1120,7 @@ describe('Test users API validators', function () {
1054 await uploadVideo(server.url, userAccessToken, videoAttributes) 1120 await uploadVideo(server.url, userAccessToken, videoAttributes)
1055 await uploadVideo(server.url, userAccessToken, videoAttributes) 1121 await uploadVideo(server.url, userAccessToken, videoAttributes)
1056 await uploadVideo(server.url, userAccessToken, videoAttributes) 1122 await uploadVideo(server.url, userAccessToken, videoAttributes)
1057 await uploadVideo(server.url, userAccessToken, videoAttributes, 403) 1123 await uploadVideo(server.url, userAccessToken, videoAttributes, HttpStatusCode.FORBIDDEN_403)
1058 }) 1124 })
1059 1125
1060 it('Should fail to import with HTTP/Torrent/magnet', async function () { 1126 it('Should fail to import with HTTP/Torrent/magnet', async function () {
@@ -1093,7 +1159,7 @@ describe('Test users API validators', function () {
1093 videoQuotaDaily: 42 1159 videoQuotaDaily: 42
1094 }) 1160 })
1095 1161
1096 await uploadVideo(server.url, server.accessToken, {}, 403) 1162 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.FORBIDDEN_403)
1097 }) 1163 })
1098 }) 1164 })
1099 1165
@@ -1107,7 +1173,7 @@ describe('Test users API validators', function () {
1107 videoQuotaDaily: 1024 * 1024 * 1024 1173 videoQuotaDaily: 1024 * 1024 * 1024
1108 }) 1174 })
1109 1175
1110 await uploadVideo(server.url, server.accessToken, {}, 403) 1176 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.FORBIDDEN_403)
1111 }) 1177 })
1112 1178
1113 it('Should fail if exceeding daily quota', async function () { 1179 it('Should fail if exceeding daily quota', async function () {
@@ -1119,7 +1185,7 @@ describe('Test users API validators', function () {
1119 videoQuotaDaily: 42 1185 videoQuotaDaily: 42
1120 }) 1186 })
1121 1187
1122 await uploadVideo(server.url, server.accessToken, {}, 403) 1188 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.FORBIDDEN_403)
1123 }) 1189 })
1124 }) 1190 })
1125 1191
@@ -1141,7 +1207,13 @@ describe('Test users API validators', function () {
1141 it('Should success with the correct params', async function () { 1207 it('Should success with the correct params', async function () {
1142 const fields = { email: 'admin@example.com' } 1208 const fields = { email: 'admin@example.com' }
1143 1209
1144 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 }) 1210 await makePostBodyRequest({
1211 url: server.url,
1212 path,
1213 token: server.accessToken,
1214 fields,
1215 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
1216 })
1145 }) 1217 })
1146 }) 1218 })
1147 1219
@@ -1163,7 +1235,13 @@ describe('Test users API validators', function () {
1163 it('Should succeed with the correct params', async function () { 1235 it('Should succeed with the correct params', async function () {
1164 const fields = { email: 'admin@example.com' } 1236 const fields = { email: 'admin@example.com' }
1165 1237
1166 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 204 }) 1238 await makePostBodyRequest({
1239 url: server.url,
1240 path,
1241 token: server.accessToken,
1242 fields,
1243 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
1244 })
1167 }) 1245 })
1168 }) 1246 })
1169 1247
diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts
index 145f43980..3d4837d58 100644
--- a/server/tests/api/check-params/video-blacklist.ts
+++ b/server/tests/api/check-params/video-blacklist.ts
@@ -26,6 +26,7 @@ import {
26} from '../../../../shared/extra-utils/requests/check-api-params' 26} from '../../../../shared/extra-utils/requests/check-api-params'
27import { VideoBlacklistType, VideoDetails } from '../../../../shared/models/videos' 27import { VideoBlacklistType, VideoDetails } from '../../../../shared/models/videos'
28import { expect } from 'chai' 28import { expect } from 'chai'
29import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
29 30
30describe('Test video blacklist API validators', function () { 31describe('Test video blacklist API validators', function () {
31 let servers: ServerInfo[] 32 let servers: ServerInfo[]
@@ -94,13 +95,19 @@ describe('Test video blacklist API validators', function () {
94 it('Should fail with a non authenticated user', async function () { 95 it('Should fail with a non authenticated user', async function () {
95 const path = basePath + servers[0].video + '/blacklist' 96 const path = basePath + servers[0].video + '/blacklist'
96 const fields = {} 97 const fields = {}
97 await makePostBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: 401 }) 98 await makePostBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
98 }) 99 })
99 100
100 it('Should fail with a non admin user', async function () { 101 it('Should fail with a non admin user', async function () {
101 const path = basePath + servers[0].video + '/blacklist' 102 const path = basePath + servers[0].video + '/blacklist'
102 const fields = {} 103 const fields = {}
103 await makePostBodyRequest({ url: servers[0].url, path, token: userAccessToken2, fields, statusCodeExpected: 403 }) 104 await makePostBodyRequest({
105 url: servers[0].url,
106 path,
107 token: userAccessToken2,
108 fields,
109 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
110 })
104 }) 111 })
105 112
106 it('Should fail with an invalid reason', async function () { 113 it('Should fail with an invalid reason', async function () {
@@ -114,14 +121,26 @@ describe('Test video blacklist API validators', function () {
114 const path = basePath + remoteVideoUUID + '/blacklist' 121 const path = basePath + remoteVideoUUID + '/blacklist'
115 const fields = { unfederate: true } 122 const fields = { unfederate: true }
116 123
117 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 409 }) 124 await makePostBodyRequest({
125 url: servers[0].url,
126 path,
127 token: servers[0].accessToken,
128 fields,
129 statusCodeExpected: HttpStatusCode.CONFLICT_409
130 })
118 }) 131 })
119 132
120 it('Should succeed with the correct params', async function () { 133 it('Should succeed with the correct params', async function () {
121 const path = basePath + servers[0].video.uuid + '/blacklist' 134 const path = basePath + servers[0].video.uuid + '/blacklist'
122 const fields = {} 135 const fields = {}
123 136
124 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 204 }) 137 await makePostBodyRequest({
138 url: servers[0].url,
139 path,
140 token: servers[0].accessToken,
141 fields,
142 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
143 })
125 }) 144 })
126 }) 145 })
127 146
@@ -137,19 +156,31 @@ describe('Test video blacklist API validators', function () {
137 it('Should fail with a video not blacklisted', async function () { 156 it('Should fail with a video not blacklisted', async function () {
138 const path = '/api/v1/videos/' + notBlacklistedVideoId + '/blacklist' 157 const path = '/api/v1/videos/' + notBlacklistedVideoId + '/blacklist'
139 const fields = {} 158 const fields = {}
140 await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 404 }) 159 await makePutBodyRequest({
160 url: servers[0].url,
161 path,
162 token: servers[0].accessToken,
163 fields,
164 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
165 })
141 }) 166 })
142 167
143 it('Should fail with a non authenticated user', async function () { 168 it('Should fail with a non authenticated user', async function () {
144 const path = basePath + servers[0].video + '/blacklist' 169 const path = basePath + servers[0].video + '/blacklist'
145 const fields = {} 170 const fields = {}
146 await makePutBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: 401 }) 171 await makePutBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
147 }) 172 })
148 173
149 it('Should fail with a non admin user', async function () { 174 it('Should fail with a non admin user', async function () {
150 const path = basePath + servers[0].video + '/blacklist' 175 const path = basePath + servers[0].video + '/blacklist'
151 const fields = {} 176 const fields = {}
152 await makePutBodyRequest({ url: servers[0].url, path, token: userAccessToken2, fields, statusCodeExpected: 403 }) 177 await makePutBodyRequest({
178 url: servers[0].url,
179 path,
180 token: userAccessToken2,
181 fields,
182 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
183 })
153 }) 184 })
154 185
155 it('Should fail with an invalid reason', async function () { 186 it('Should fail with an invalid reason', async function () {
@@ -163,29 +194,35 @@ describe('Test video blacklist API validators', function () {
163 const path = basePath + servers[0].video.uuid + '/blacklist' 194 const path = basePath + servers[0].video.uuid + '/blacklist'
164 const fields = { reason: 'hello' } 195 const fields = { reason: 'hello' }
165 196
166 await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields, statusCodeExpected: 204 }) 197 await makePutBodyRequest({
198 url: servers[0].url,
199 path,
200 token: servers[0].accessToken,
201 fields,
202 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
203 })
167 }) 204 })
168 }) 205 })
169 206
170 describe('When getting blacklisted video', function () { 207 describe('When getting blacklisted video', function () {
171 208
172 it('Should fail with a non authenticated user', async function () { 209 it('Should fail with a non authenticated user', async function () {
173 await getVideo(servers[0].url, servers[0].video.uuid, 401) 210 await getVideo(servers[0].url, servers[0].video.uuid, HttpStatusCode.UNAUTHORIZED_401)
174 }) 211 })
175 212
176 it('Should fail with another user', async function () { 213 it('Should fail with another user', async function () {
177 await getVideoWithToken(servers[0].url, userAccessToken2, servers[0].video.uuid, 403) 214 await getVideoWithToken(servers[0].url, userAccessToken2, servers[0].video.uuid, HttpStatusCode.FORBIDDEN_403)
178 }) 215 })
179 216
180 it('Should succeed with the owner authenticated user', async function () { 217 it('Should succeed with the owner authenticated user', async function () {
181 const res = await getVideoWithToken(servers[0].url, userAccessToken1, servers[0].video.uuid, 200) 218 const res = await getVideoWithToken(servers[0].url, userAccessToken1, servers[0].video.uuid, HttpStatusCode.OK_200)
182 const video: VideoDetails = res.body 219 const video: VideoDetails = res.body
183 220
184 expect(video.blacklisted).to.be.true 221 expect(video.blacklisted).to.be.true
185 }) 222 })
186 223
187 it('Should succeed with an admin', async function () { 224 it('Should succeed with an admin', async function () {
188 const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, servers[0].video.uuid, 200) 225 const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, servers[0].video.uuid, HttpStatusCode.OK_200)
189 const video: VideoDetails = res.body 226 const video: VideoDetails = res.body
190 227
191 expect(video.blacklisted).to.be.true 228 expect(video.blacklisted).to.be.true
@@ -194,24 +231,24 @@ describe('Test video blacklist API validators', function () {
194 231
195 describe('When removing a video in blacklist', function () { 232 describe('When removing a video in blacklist', function () {
196 it('Should fail with a non authenticated user', async function () { 233 it('Should fail with a non authenticated user', async function () {
197 await removeVideoFromBlacklist(servers[0].url, 'fake token', servers[0].video.uuid, 401) 234 await removeVideoFromBlacklist(servers[0].url, 'fake token', servers[0].video.uuid, HttpStatusCode.UNAUTHORIZED_401)
198 }) 235 })
199 236
200 it('Should fail with a non admin user', async function () { 237 it('Should fail with a non admin user', async function () {
201 await removeVideoFromBlacklist(servers[0].url, userAccessToken2, servers[0].video.uuid, 403) 238 await removeVideoFromBlacklist(servers[0].url, userAccessToken2, servers[0].video.uuid, HttpStatusCode.FORBIDDEN_403)
202 }) 239 })
203 240
204 it('Should fail with an incorrect id', async function () { 241 it('Should fail with an incorrect id', async function () {
205 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, 'hello', 400) 242 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400)
206 }) 243 })
207 244
208 it('Should fail with a not blacklisted video', async function () { 245 it('Should fail with a not blacklisted video', async function () {
209 // The video was not added to the blacklist so it should fail 246 // The video was not added to the blacklist so it should fail
210 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, notBlacklistedVideoId, 404) 247 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, notBlacklistedVideoId, HttpStatusCode.NOT_FOUND_404)
211 }) 248 })
212 249
213 it('Should succeed with the correct params', async function () { 250 it('Should succeed with the correct params', async function () {
214 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, servers[0].video.uuid, 204) 251 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, servers[0].video.uuid, HttpStatusCode.NO_CONTENT_204)
215 }) 252 })
216 }) 253 })
217 254
@@ -219,11 +256,11 @@ describe('Test video blacklist API validators', function () {
219 const basePath = '/api/v1/videos/blacklist/' 256 const basePath = '/api/v1/videos/blacklist/'
220 257
221 it('Should fail with a non authenticated user', async function () { 258 it('Should fail with a non authenticated user', async function () {
222 await getBlacklistedVideosList({ url: servers[0].url, token: 'fake token', specialStatus: 401 }) 259 await getBlacklistedVideosList({ url: servers[0].url, token: 'fake token', specialStatus: HttpStatusCode.UNAUTHORIZED_401 })
223 }) 260 })
224 261
225 it('Should fail with a non admin user', async function () { 262 it('Should fail with a non admin user', async function () {
226 await getBlacklistedVideosList({ url: servers[0].url, token: userAccessToken2, specialStatus: 403 }) 263 await getBlacklistedVideosList({ url: servers[0].url, token: userAccessToken2, specialStatus: HttpStatusCode.FORBIDDEN_403 })
227 }) 264 })
228 265
229 it('Should fail with a bad start pagination', async function () { 266 it('Should fail with a bad start pagination', async function () {
@@ -239,7 +276,12 @@ describe('Test video blacklist API validators', function () {
239 }) 276 })
240 277
241 it('Should fail with an invalid type', async function () { 278 it('Should fail with an invalid type', async function () {
242 await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, type: 0, specialStatus: 400 }) 279 await getBlacklistedVideosList({
280 url: servers[0].url,
281 token: servers[0].accessToken,
282 type: 0,
283 specialStatus: HttpStatusCode.BAD_REQUEST_400
284 })
243 }) 285 })
244 286
245 it('Should succeed with the correct parameters', async function () { 287 it('Should succeed with the correct parameters', async function () {
diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts
index a5f5c3322..e42e8db81 100644
--- a/server/tests/api/check-params/video-captions.ts
+++ b/server/tests/api/check-params/video-captions.ts
@@ -15,6 +15,7 @@ import {
15} from '../../../../shared/extra-utils' 15} from '../../../../shared/extra-utils'
16import { join } from 'path' 16import { join } from 'path'
17import { createVideoCaption } from '../../../../shared/extra-utils/videos/video-captions' 17import { createVideoCaption } from '../../../../shared/extra-utils/videos/video-captions'
18import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
18 19
19describe('Test video captions API validator', function () { 20describe('Test video captions API validator', function () {
20 const path = '/api/v1/videos/' 21 const path = '/api/v1/videos/'
@@ -107,7 +108,7 @@ describe('Test video captions API validator', function () {
107 path: captionPath, 108 path: captionPath,
108 fields, 109 fields,
109 attaches, 110 attaches,
110 statusCodeExpected: 401 111 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
111 }) 112 })
112 }) 113 })
113 114
@@ -120,7 +121,7 @@ describe('Test video captions API validator', function () {
120 token: 'blabla', 121 token: 'blabla',
121 fields, 122 fields,
122 attaches, 123 attaches,
123 statusCodeExpected: 401 124 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
124 }) 125 })
125 }) 126 })
126 127
@@ -138,7 +139,7 @@ describe('Test video captions API validator', function () {
138 // token: server.accessToken, 139 // token: server.accessToken,
139 // fields, 140 // fields,
140 // attaches, 141 // attaches,
141 // statusCodeExpected: 400 142 // statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
142 // }) 143 // })
143 // }) 144 // })
144 145
@@ -151,7 +152,7 @@ describe('Test video captions API validator', function () {
151 // videoId: videoUUID, 152 // videoId: videoUUID,
152 // fixture: 'subtitle-bad.txt', 153 // fixture: 'subtitle-bad.txt',
153 // mimeType: 'application/octet-stream', 154 // mimeType: 'application/octet-stream',
154 // statusCodeExpected: 400 155 // statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
155 // }) 156 // })
156 // }) 157 // })
157 158
@@ -180,7 +181,7 @@ describe('Test video captions API validator', function () {
180 // token: server.accessToken, 181 // token: server.accessToken,
181 // fields, 182 // fields,
182 // attaches, 183 // attaches,
183 // statusCodeExpected: 500 184 // statusCodeExpected: HttpStatusCode.INTERNAL_SERVER_ERROR_500
184 // }) 185 // })
185 // }) 186 // })
186 187
@@ -193,7 +194,7 @@ describe('Test video captions API validator', function () {
193 token: server.accessToken, 194 token: server.accessToken,
194 fields, 195 fields,
195 attaches, 196 attaches,
196 statusCodeExpected: 204 197 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
197 }) 198 })
198 }) 199 })
199 }) 200 })
@@ -204,11 +205,15 @@ describe('Test video captions API validator', function () {
204 }) 205 })
205 206
206 it('Should fail with an unknown id', async function () { 207 it('Should fail with an unknown id', async function () {
207 await makeGetRequest({ url: server.url, path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions', statusCodeExpected: 404 }) 208 await makeGetRequest({
209 url: server.url,
210 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions',
211 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
212 })
208 }) 213 })
209 214
210 it('Should success with the correct parameters', async function () { 215 it('Should success with the correct parameters', async function () {
211 await makeGetRequest({ url: server.url, path: path + videoUUID + '/captions', statusCodeExpected: 200 }) 216 await makeGetRequest({ url: server.url, path: path + videoUUID + '/captions', statusCodeExpected: HttpStatusCode.OK_200 })
212 }) 217 })
213 }) 218 })
214 219
@@ -226,7 +231,7 @@ describe('Test video captions API validator', function () {
226 url: server.url, 231 url: server.url,
227 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr', 232 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
228 token: server.accessToken, 233 token: server.accessToken,
229 statusCodeExpected: 404 234 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
230 }) 235 })
231 }) 236 })
232 237
@@ -250,22 +255,32 @@ describe('Test video captions API validator', function () {
250 255
251 it('Should fail without access token', async function () { 256 it('Should fail without access token', async function () {
252 const captionPath = path + videoUUID + '/captions/fr' 257 const captionPath = path + videoUUID + '/captions/fr'
253 await makeDeleteRequest({ url: server.url, path: captionPath, statusCodeExpected: 401 }) 258 await makeDeleteRequest({ url: server.url, path: captionPath, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
254 }) 259 })
255 260
256 it('Should fail with a bad access token', async function () { 261 it('Should fail with a bad access token', async function () {
257 const captionPath = path + videoUUID + '/captions/fr' 262 const captionPath = path + videoUUID + '/captions/fr'
258 await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', statusCodeExpected: 401 }) 263 await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
259 }) 264 })
260 265
261 it('Should fail with another user', async function () { 266 it('Should fail with another user', async function () {
262 const captionPath = path + videoUUID + '/captions/fr' 267 const captionPath = path + videoUUID + '/captions/fr'
263 await makeDeleteRequest({ url: server.url, path: captionPath, token: userAccessToken, statusCodeExpected: 403 }) 268 await makeDeleteRequest({
269 url: server.url,
270 path: captionPath,
271 token: userAccessToken,
272 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
273 })
264 }) 274 })
265 275
266 it('Should success with the correct parameters', async function () { 276 it('Should success with the correct parameters', async function () {
267 const captionPath = path + videoUUID + '/captions/fr' 277 const captionPath = path + videoUUID + '/captions/fr'
268 await makeDeleteRequest({ url: server.url, path: captionPath, token: server.accessToken, statusCodeExpected: 204 }) 278 await makeDeleteRequest({
279 url: server.url,
280 path: captionPath,
281 token: server.accessToken,
282 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
283 })
269 }) 284 })
270 }) 285 })
271 286
diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts
index 2795ad7d5..0dd436426 100644
--- a/server/tests/api/check-params/video-channels.ts
+++ b/server/tests/api/check-params/video-channels.ts
@@ -25,6 +25,7 @@ import {
25} from '../../../../shared/extra-utils/requests/check-api-params' 25} from '../../../../shared/extra-utils/requests/check-api-params'
26import { join } from 'path' 26import { join } from 'path'
27import { VideoChannelUpdate } from '../../../../shared/models/videos' 27import { VideoChannelUpdate } from '../../../../shared/models/videos'
28import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
28 29
29const expect = chai.expect 30const expect = chai.expect
30 31
@@ -83,14 +84,14 @@ describe('Test video channels API validator', function () {
83 }) 84 })
84 85
85 it('Should fail with a unknown account', async function () { 86 it('Should fail with a unknown account', async function () {
86 await getAccountVideoChannelsList({ url: server.url, accountName: 'unknown', specialStatus: 404 }) 87 await getAccountVideoChannelsList({ url: server.url, accountName: 'unknown', specialStatus: HttpStatusCode.NOT_FOUND_404 })
87 }) 88 })
88 89
89 it('Should succeed with the correct parameters', async function () { 90 it('Should succeed with the correct parameters', async function () {
90 await makeGetRequest({ 91 await makeGetRequest({
91 url: server.url, 92 url: server.url,
92 path: accountChannelPath, 93 path: accountChannelPath,
93 statusCodeExpected: 200 94 statusCodeExpected: HttpStatusCode.OK_200
94 }) 95 })
95 }) 96 })
96 }) 97 })
@@ -109,7 +110,7 @@ describe('Test video channels API validator', function () {
109 path: videoChannelPath, 110 path: videoChannelPath,
110 token: 'none', 111 token: 'none',
111 fields: baseCorrectParams, 112 fields: baseCorrectParams,
112 statusCodeExpected: 401 113 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
113 }) 114 })
114 }) 115 })
115 116
@@ -154,7 +155,7 @@ describe('Test video channels API validator', function () {
154 path: videoChannelPath, 155 path: videoChannelPath,
155 token: server.accessToken, 156 token: server.accessToken,
156 fields: baseCorrectParams, 157 fields: baseCorrectParams,
157 statusCodeExpected: 200 158 statusCodeExpected: HttpStatusCode.OK_200
158 }) 159 })
159 }) 160 })
160 161
@@ -164,7 +165,7 @@ describe('Test video channels API validator', function () {
164 path: videoChannelPath, 165 path: videoChannelPath,
165 token: server.accessToken, 166 token: server.accessToken,
166 fields: baseCorrectParams, 167 fields: baseCorrectParams,
167 statusCodeExpected: 409 168 statusCodeExpected: HttpStatusCode.CONFLICT_409
168 }) 169 })
169 }) 170 })
170 }) 171 })
@@ -188,7 +189,7 @@ describe('Test video channels API validator', function () {
188 path, 189 path,
189 token: 'hi', 190 token: 'hi',
190 fields: baseCorrectParams, 191 fields: baseCorrectParams,
191 statusCodeExpected: 401 192 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
192 }) 193 })
193 }) 194 })
194 195
@@ -198,7 +199,7 @@ describe('Test video channels API validator', function () {
198 path, 199 path,
199 token: accessTokenUser, 200 token: accessTokenUser,
200 fields: baseCorrectParams, 201 fields: baseCorrectParams,
201 statusCodeExpected: 403 202 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
202 }) 203 })
203 }) 204 })
204 205
@@ -228,7 +229,7 @@ describe('Test video channels API validator', function () {
228 path, 229 path,
229 token: server.accessToken, 230 token: server.accessToken,
230 fields: baseCorrectParams, 231 fields: baseCorrectParams,
231 statusCodeExpected: 204 232 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
232 }) 233 })
233 }) 234 })
234 }) 235 })
@@ -266,7 +267,7 @@ describe('Test video channels API validator', function () {
266 path: path + '/avatar/pick', 267 path: path + '/avatar/pick',
267 fields, 268 fields,
268 attaches, 269 attaches,
269 statusCodeExpected: 401 270 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
270 }) 271 })
271 }) 272 })
272 273
@@ -281,7 +282,7 @@ describe('Test video channels API validator', function () {
281 token: server.accessToken, 282 token: server.accessToken,
282 fields, 283 fields,
283 attaches, 284 attaches,
284 statusCodeExpected: 200 285 statusCodeExpected: HttpStatusCode.OK_200
285 }) 286 })
286 }) 287 })
287 }) 288 })
@@ -291,7 +292,7 @@ describe('Test video channels API validator', function () {
291 const res = await makeGetRequest({ 292 const res = await makeGetRequest({
292 url: server.url, 293 url: server.url,
293 path: videoChannelPath, 294 path: videoChannelPath,
294 statusCodeExpected: 200 295 statusCodeExpected: HttpStatusCode.OK_200
295 }) 296 })
296 297
297 expect(res.body.data).to.be.an('array') 298 expect(res.body.data).to.be.an('array')
@@ -301,7 +302,7 @@ describe('Test video channels API validator', function () {
301 await makeGetRequest({ 302 await makeGetRequest({
302 url: server.url, 303 url: server.url,
303 path: videoChannelPath + '/super_channel2', 304 path: videoChannelPath + '/super_channel2',
304 statusCodeExpected: 404 305 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
305 }) 306 })
306 }) 307 })
307 308
@@ -309,22 +310,22 @@ describe('Test video channels API validator', function () {
309 await makeGetRequest({ 310 await makeGetRequest({
310 url: server.url, 311 url: server.url,
311 path: videoChannelPath + '/super_channel', 312 path: videoChannelPath + '/super_channel',
312 statusCodeExpected: 200 313 statusCodeExpected: HttpStatusCode.OK_200
313 }) 314 })
314 }) 315 })
315 }) 316 })
316 317
317 describe('When deleting a video channel', function () { 318 describe('When deleting a video channel', function () {
318 it('Should fail with a non authenticated user', async function () { 319 it('Should fail with a non authenticated user', async function () {
319 await deleteVideoChannel(server.url, 'coucou', 'super_channel', 401) 320 await deleteVideoChannel(server.url, 'coucou', 'super_channel', HttpStatusCode.UNAUTHORIZED_401)
320 }) 321 })
321 322
322 it('Should fail with another authenticated user', async function () { 323 it('Should fail with another authenticated user', async function () {
323 await deleteVideoChannel(server.url, accessTokenUser, 'super_channel', 403) 324 await deleteVideoChannel(server.url, accessTokenUser, 'super_channel', HttpStatusCode.FORBIDDEN_403)
324 }) 325 })
325 326
326 it('Should fail with an unknown video channel id', async function () { 327 it('Should fail with an unknown video channel id', async function () {
327 await deleteVideoChannel(server.url, server.accessToken, 'super_channel2', 404) 328 await deleteVideoChannel(server.url, server.accessToken, 'super_channel2', HttpStatusCode.NOT_FOUND_404)
328 }) 329 })
329 330
330 it('Should succeed with the correct parameters', async function () { 331 it('Should succeed with the correct parameters', async function () {
@@ -332,7 +333,7 @@ describe('Test video channels API validator', function () {
332 }) 333 })
333 334
334 it('Should fail to delete the last user video channel', async function () { 335 it('Should fail to delete the last user video channel', async function () {
335 await deleteVideoChannel(server.url, server.accessToken, 'root_channel', 409) 336 await deleteVideoChannel(server.url, server.accessToken, 'root_channel', HttpStatusCode.CONFLICT_409)
336 }) 337 })
337 }) 338 })
338 339
diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts
index 662d4a70d..659a10c41 100644
--- a/server/tests/api/check-params/video-comments.ts
+++ b/server/tests/api/check-params/video-comments.ts
@@ -20,6 +20,7 @@ import {
20 checkBadStartPagination 20 checkBadStartPagination
21} from '../../../../shared/extra-utils/requests/check-api-params' 21} from '../../../../shared/extra-utils/requests/check-api-params'
22import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments' 22import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
23import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
23 24
24const expect = chai.expect 25const expect = chai.expect
25 26
@@ -83,7 +84,7 @@ describe('Test video comments API validator', function () {
83 await makeGetRequest({ 84 await makeGetRequest({
84 url: server.url, 85 url: server.url,
85 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads', 86 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads',
86 statusCodeExpected: 404 87 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
87 }) 88 })
88 }) 89 })
89 }) 90 })
@@ -93,7 +94,7 @@ describe('Test video comments API validator', function () {
93 await makeGetRequest({ 94 await makeGetRequest({
94 url: server.url, 95 url: server.url,
95 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads/' + commentId, 96 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads/' + commentId,
96 statusCodeExpected: 404 97 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
97 }) 98 })
98 }) 99 })
99 100
@@ -101,7 +102,7 @@ describe('Test video comments API validator', function () {
101 await makeGetRequest({ 102 await makeGetRequest({
102 url: server.url, 103 url: server.url,
103 path: '/api/v1/videos/' + videoUUID + '/comment-threads/156', 104 path: '/api/v1/videos/' + videoUUID + '/comment-threads/156',
104 statusCodeExpected: 404 105 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
105 }) 106 })
106 }) 107 })
107 108
@@ -109,7 +110,7 @@ describe('Test video comments API validator', function () {
109 await makeGetRequest({ 110 await makeGetRequest({
110 url: server.url, 111 url: server.url,
111 path: '/api/v1/videos/' + videoUUID + '/comment-threads/' + commentId, 112 path: '/api/v1/videos/' + videoUUID + '/comment-threads/' + commentId,
112 statusCodeExpected: 200 113 statusCodeExpected: HttpStatusCode.OK_200
113 }) 114 })
114 }) 115 })
115 }) 116 })
@@ -120,7 +121,13 @@ describe('Test video comments API validator', function () {
120 const fields = { 121 const fields = {
121 text: 'text' 122 text: 'text'
122 } 123 }
123 await makePostBodyRequest({ url: server.url, path: pathThread, token: 'none', fields, statusCodeExpected: 401 }) 124 await makePostBodyRequest({
125 url: server.url,
126 path: pathThread,
127 token: 'none',
128 fields,
129 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
130 })
124 }) 131 })
125 132
126 it('Should fail with nothing', async function () { 133 it('Should fail with nothing', async function () {
@@ -147,14 +154,26 @@ describe('Test video comments API validator', function () {
147 const fields = { 154 const fields = {
148 text: 'super comment' 155 text: 'super comment'
149 } 156 }
150 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 }) 157 await makePostBodyRequest({
158 url: server.url,
159 path,
160 token: server.accessToken,
161 fields,
162 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
163 })
151 }) 164 })
152 165
153 it('Should succeed with the correct parameters', async function () { 166 it('Should succeed with the correct parameters', async function () {
154 const fields = { 167 const fields = {
155 text: 'super comment' 168 text: 'super comment'
156 } 169 }
157 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields, statusCodeExpected: 200 }) 170 await makePostBodyRequest({
171 url: server.url,
172 path: pathThread,
173 token: server.accessToken,
174 fields,
175 statusCodeExpected: HttpStatusCode.OK_200
176 })
158 }) 177 })
159 }) 178 })
160 179
@@ -163,7 +182,13 @@ describe('Test video comments API validator', function () {
163 const fields = { 182 const fields = {
164 text: 'text' 183 text: 'text'
165 } 184 }
166 await makePostBodyRequest({ url: server.url, path: pathComment, token: 'none', fields, statusCodeExpected: 401 }) 185 await makePostBodyRequest({
186 url: server.url,
187 path: pathComment,
188 token: 'none',
189 fields,
190 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
191 })
167 }) 192 })
168 193
169 it('Should fail with nothing', async function () { 194 it('Should fail with nothing', async function () {
@@ -190,7 +215,13 @@ describe('Test video comments API validator', function () {
190 const fields = { 215 const fields = {
191 text: 'super comment' 216 text: 'super comment'
192 } 217 }
193 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 }) 218 await makePostBodyRequest({
219 url: server.url,
220 path,
221 token: server.accessToken,
222 fields,
223 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
224 })
194 }) 225 })
195 226
196 it('Should fail with an incorrect comment', async function () { 227 it('Should fail with an incorrect comment', async function () {
@@ -198,34 +229,51 @@ describe('Test video comments API validator', function () {
198 const fields = { 229 const fields = {
199 text: 'super comment' 230 text: 'super comment'
200 } 231 }
201 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 404 }) 232 await makePostBodyRequest({
233 url: server.url,
234 path,
235 token: server.accessToken,
236 fields,
237 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
238 })
202 }) 239 })
203 240
204 it('Should succeed with the correct parameters', async function () { 241 it('Should succeed with the correct parameters', async function () {
205 const fields = { 242 const fields = {
206 text: 'super comment' 243 text: 'super comment'
207 } 244 }
208 await makePostBodyRequest({ url: server.url, path: pathComment, token: server.accessToken, fields, statusCodeExpected: 200 }) 245 await makePostBodyRequest({
246 url: server.url,
247 path: pathComment,
248 token: server.accessToken,
249 fields,
250 statusCodeExpected: HttpStatusCode.OK_200
251 })
209 }) 252 })
210 }) 253 })
211 254
212 describe('When removing video comments', function () { 255 describe('When removing video comments', function () {
213 it('Should fail with a non authenticated user', async function () { 256 it('Should fail with a non authenticated user', async function () {
214 await makeDeleteRequest({ url: server.url, path: pathComment, token: 'none', statusCodeExpected: 401 }) 257 await makeDeleteRequest({ url: server.url, path: pathComment, token: 'none', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
215 }) 258 })
216 259
217 it('Should fail with another user', async function () { 260 it('Should fail with another user', async function () {
218 await makeDeleteRequest({ url: server.url, path: pathComment, token: userAccessToken, statusCodeExpected: 403 }) 261 await makeDeleteRequest({
262 url: server.url,
263 path: pathComment,
264 token: userAccessToken,
265 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
266 })
219 }) 267 })
220 268
221 it('Should fail with an incorrect video', async function () { 269 it('Should fail with an incorrect video', async function () {
222 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId 270 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId
223 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 404 }) 271 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 })
224 }) 272 })
225 273
226 it('Should fail with an incorrect comment', async function () { 274 it('Should fail with an incorrect comment', async function () {
227 const path = '/api/v1/videos/' + videoUUID + '/comments/124' 275 const path = '/api/v1/videos/' + videoUUID + '/comments/124'
228 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: 404 }) 276 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 })
229 }) 277 })
230 278
231 it('Should succeed with the same user', async function () { 279 it('Should succeed with the same user', async function () {
@@ -238,8 +286,8 @@ describe('Test video comments API validator', function () {
238 286
239 const path = '/api/v1/videos/' + videoUUID + '/comments/' + commentToDelete 287 const path = '/api/v1/videos/' + videoUUID + '/comments/' + commentToDelete
240 288
241 await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, statusCodeExpected: 403 }) 289 await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
242 await makeDeleteRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 204 }) 290 await makeDeleteRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.NO_CONTENT_204 })
243 }) 291 })
244 292
245 it('Should succeed with the owner of the video', async function () { 293 it('Should succeed with the owner of the video', async function () {
@@ -258,12 +306,17 @@ describe('Test video comments API validator', function () {
258 306
259 const path = '/api/v1/videos/' + anotherVideoUUID + '/comments/' + commentToDelete 307 const path = '/api/v1/videos/' + anotherVideoUUID + '/comments/' + commentToDelete
260 308
261 await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, statusCodeExpected: 403 }) 309 await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 })
262 await makeDeleteRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: 204 }) 310 await makeDeleteRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.NO_CONTENT_204 })
263 }) 311 })
264 312
265 it('Should succeed with the correct parameters', async function () { 313 it('Should succeed with the correct parameters', async function () {
266 await makeDeleteRequest({ url: server.url, path: pathComment, token: server.accessToken, statusCodeExpected: 204 }) 314 await makeDeleteRequest({
315 url: server.url,
316 path: pathComment,
317 token: server.accessToken,
318 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
319 })
267 }) 320 })
268 }) 321 })
269 322
@@ -278,7 +331,7 @@ describe('Test video comments API validator', function () {
278 const res = await makeGetRequest({ 331 const res = await makeGetRequest({
279 url: server.url, 332 url: server.url,
280 path: pathThread, 333 path: pathThread,
281 statusCodeExpected: 200 334 statusCodeExpected: HttpStatusCode.OK_200
282 }) 335 })
283 expect(res.body.total).to.equal(0) 336 expect(res.body.total).to.equal(0)
284 expect(res.body.data).to.have.lengthOf(0) 337 expect(res.body.data).to.have.lengthOf(0)
@@ -290,7 +343,13 @@ describe('Test video comments API validator', function () {
290 const fields = { 343 const fields = {
291 text: 'super comment' 344 text: 'super comment'
292 } 345 }
293 await makePostBodyRequest({ url: server.url, path: pathThread, token: server.accessToken, fields, statusCodeExpected: 409 }) 346 await makePostBodyRequest({
347 url: server.url,
348 path: pathThread,
349 token: server.accessToken,
350 fields,
351 statusCodeExpected: HttpStatusCode.CONFLICT_409
352 })
294 }) 353 })
295 354
296 it('Should return conflict on comment thread add') 355 it('Should return conflict on comment thread add')
@@ -315,7 +374,7 @@ describe('Test video comments API validator', function () {
315 await makeGetRequest({ 374 await makeGetRequest({
316 url: server.url, 375 url: server.url,
317 path, 376 path,
318 statusCodeExpected: 401 377 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
319 }) 378 })
320 }) 379 })
321 380
@@ -324,7 +383,7 @@ describe('Test video comments API validator', function () {
324 url: server.url, 383 url: server.url,
325 path, 384 path,
326 token: userAccessToken, 385 token: userAccessToken,
327 statusCodeExpected: 403 386 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
328 }) 387 })
329 }) 388 })
330 389
@@ -339,7 +398,7 @@ describe('Test video comments API validator', function () {
339 searchAccount: 'toto', 398 searchAccount: 'toto',
340 searchVideo: 'toto' 399 searchVideo: 'toto'
341 }, 400 },
342 statusCodeExpected: 200 401 statusCodeExpected: HttpStatusCode.OK_200
343 }) 402 })
344 }) 403 })
345 }) 404 })
diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts
index f954ba089..49ff96117 100644
--- a/server/tests/api/check-params/video-imports.ts
+++ b/server/tests/api/check-params/video-imports.ts
@@ -24,6 +24,7 @@ import {
24} from '../../../../shared/extra-utils/requests/check-api-params' 24} from '../../../../shared/extra-utils/requests/check-api-params'
25import { getMagnetURI, getGoodVideoUrl } from '../../../../shared/extra-utils/videos/video-imports' 25import { getMagnetURI, getGoodVideoUrl } from '../../../../shared/extra-utils/videos/video-imports'
26import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' 26import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
27import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
27 28
28describe('Test video imports API validator', function () { 29describe('Test video imports API validator', function () {
29 const path = '/api/v1/videos/imports' 30 const path = '/api/v1/videos/imports'
@@ -67,7 +68,7 @@ describe('Test video imports API validator', function () {
67 }) 68 })
68 69
69 it('Should success with the correct parameters', async function () { 70 it('Should success with the correct parameters', async function () {
70 await makeGetRequest({ url: server.url, path: myPath, statusCodeExpected: 200, token: server.accessToken }) 71 await makeGetRequest({ url: server.url, path: myPath, statusCodeExpected: HttpStatusCode.OK_200, token: server.accessToken })
71 }) 72 })
72 }) 73 })
73 74
@@ -100,7 +101,13 @@ describe('Test video imports API validator', function () {
100 101
101 it('Should fail without a target url', async function () { 102 it('Should fail without a target url', async function () {
102 const fields = omit(baseCorrectParams, 'targetUrl') 103 const fields = omit(baseCorrectParams, 'targetUrl')
103 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 400 }) 104 await makePostBodyRequest({
105 url: server.url,
106 path,
107 token: server.accessToken,
108 fields,
109 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
110 })
104 }) 111 })
105 112
106 it('Should fail with a bad target url', async function () { 113 it('Should fail with a bad target url', async function () {
@@ -251,7 +258,7 @@ describe('Test video imports API validator', function () {
251 path, 258 path,
252 token: server.accessToken, 259 token: server.accessToken,
253 fields: baseCorrectParams, 260 fields: baseCorrectParams,
254 statusCodeExpected: 200 261 statusCodeExpected: HttpStatusCode.OK_200
255 }) 262 })
256 }) 263 })
257 264
@@ -274,7 +281,7 @@ describe('Test video imports API validator', function () {
274 path, 281 path,
275 token: server.accessToken, 282 token: server.accessToken,
276 fields: baseCorrectParams, 283 fields: baseCorrectParams,
277 statusCodeExpected: 409 284 statusCodeExpected: HttpStatusCode.CONFLICT_409
278 }) 285 })
279 }) 286 })
280 287
@@ -295,14 +302,27 @@ describe('Test video imports API validator', function () {
295 let fields = omit(baseCorrectParams, 'targetUrl') 302 let fields = omit(baseCorrectParams, 'targetUrl')
296 fields = immutableAssign(fields, { magnetUri: getMagnetURI() }) 303 fields = immutableAssign(fields, { magnetUri: getMagnetURI() })
297 304
298 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 }) 305 await makePostBodyRequest({
306 url: server.url,
307 path,
308 token: server.accessToken,
309 fields,
310 statusCodeExpected: HttpStatusCode.CONFLICT_409
311 })
299 312
300 fields = omit(fields, 'magnetUri') 313 fields = omit(fields, 'magnetUri')
301 const attaches = { 314 const attaches = {
302 torrentfile: join(__dirname, '..', '..', 'fixtures', 'video-720p.torrent') 315 torrentfile: join(__dirname, '..', '..', 'fixtures', 'video-720p.torrent')
303 } 316 }
304 317
305 await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches, statusCodeExpected: 409 }) 318 await makeUploadRequest({
319 url: server.url,
320 path,
321 token: server.accessToken,
322 fields,
323 attaches,
324 statusCodeExpected: HttpStatusCode.CONFLICT_409
325 })
306 }) 326 })
307 }) 327 })
308 328
diff --git a/server/tests/api/check-params/video-playlists.ts b/server/tests/api/check-params/video-playlists.ts
index 179ae9201..418af05d1 100644
--- a/server/tests/api/check-params/video-playlists.ts
+++ b/server/tests/api/check-params/video-playlists.ts
@@ -28,6 +28,7 @@ import {
28} from '../../../../shared/extra-utils/requests/check-api-params' 28} from '../../../../shared/extra-utils/requests/check-api-params'
29import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model' 29import { VideoPlaylistPrivacy } from '../../../../shared/models/videos/playlist/video-playlist-privacy.model'
30import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model' 30import { VideoPlaylistType } from '../../../../shared/models/videos/playlist/video-playlist-type.model'
31import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
31 32
32describe('Test video playlists API validator', function () { 33describe('Test video playlists API validator', function () {
33 let server: ServerInfo 34 let server: ServerInfo
@@ -114,19 +115,34 @@ describe('Test video playlists API validator', function () {
114 it('Should fail with a bad account parameter', async function () { 115 it('Should fail with a bad account parameter', async function () {
115 const accountPath = '/api/v1/accounts/root2/video-playlists' 116 const accountPath = '/api/v1/accounts/root2/video-playlists'
116 117
117 await makeGetRequest({ url: server.url, path: accountPath, statusCodeExpected: 404, token: server.accessToken }) 118 await makeGetRequest({
119 url: server.url,
120 path: accountPath,
121 statusCodeExpected: HttpStatusCode.NOT_FOUND_404,
122 token: server.accessToken
123 })
118 }) 124 })
119 125
120 it('Should fail with a bad video channel parameter', async function () { 126 it('Should fail with a bad video channel parameter', async function () {
121 const accountPath = '/api/v1/video-channels/bad_channel/video-playlists' 127 const accountPath = '/api/v1/video-channels/bad_channel/video-playlists'
122 128
123 await makeGetRequest({ url: server.url, path: accountPath, statusCodeExpected: 404, token: server.accessToken }) 129 await makeGetRequest({
130 url: server.url,
131 path: accountPath,
132 statusCodeExpected: HttpStatusCode.NOT_FOUND_404,
133 token: server.accessToken
134 })
124 }) 135 })
125 136
126 it('Should success with the correct parameters', async function () { 137 it('Should success with the correct parameters', async function () {
127 await makeGetRequest({ url: server.url, path: globalPath, statusCodeExpected: 200, token: server.accessToken }) 138 await makeGetRequest({ url: server.url, path: globalPath, statusCodeExpected: HttpStatusCode.OK_200, token: server.accessToken })
128 await makeGetRequest({ url: server.url, path: accountPath, statusCodeExpected: 200, token: server.accessToken }) 139 await makeGetRequest({ url: server.url, path: accountPath, statusCodeExpected: HttpStatusCode.OK_200, token: server.accessToken })
129 await makeGetRequest({ url: server.url, path: videoChannelPath, statusCodeExpected: 200, token: server.accessToken }) 140 await makeGetRequest({
141 url: server.url,
142 path: videoChannelPath,
143 statusCodeExpected: HttpStatusCode.OK_200,
144 token: server.accessToken
145 })
130 }) 146 })
131 }) 147 })
132 148
@@ -142,17 +158,17 @@ describe('Test video playlists API validator', function () {
142 }) 158 })
143 159
144 it('Should success with the correct parameters', async function () { 160 it('Should success with the correct parameters', async function () {
145 await makeGetRequest({ url: server.url, path: path + playlistUUID + '/videos', statusCodeExpected: 200 }) 161 await makeGetRequest({ url: server.url, path: path + playlistUUID + '/videos', statusCodeExpected: HttpStatusCode.OK_200 })
146 }) 162 })
147 }) 163 })
148 164
149 describe('When getting a video playlist', function () { 165 describe('When getting a video playlist', function () {
150 it('Should fail with a bad id or uuid', async function () { 166 it('Should fail with a bad id or uuid', async function () {
151 await getVideoPlaylist(server.url, 'toto', 400) 167 await getVideoPlaylist(server.url, 'toto', HttpStatusCode.BAD_REQUEST_400)
152 }) 168 })
153 169
154 it('Should fail with an unknown playlist', async function () { 170 it('Should fail with an unknown playlist', async function () {
155 await getVideoPlaylist(server.url, 42, 404) 171 await getVideoPlaylist(server.url, 42, HttpStatusCode.NOT_FOUND_404)
156 }) 172 })
157 173
158 it('Should fail to get an unlisted playlist with the number id', async function () { 174 it('Should fail to get an unlisted playlist with the number id', async function () {
@@ -166,19 +182,19 @@ describe('Test video playlists API validator', function () {
166 }) 182 })
167 const playlist = res.body.videoPlaylist 183 const playlist = res.body.videoPlaylist
168 184
169 await getVideoPlaylist(server.url, playlist.id, 404) 185 await getVideoPlaylist(server.url, playlist.id, HttpStatusCode.NOT_FOUND_404)
170 await getVideoPlaylist(server.url, playlist.uuid, 200) 186 await getVideoPlaylist(server.url, playlist.uuid, HttpStatusCode.OK_200)
171 }) 187 })
172 188
173 it('Should succeed with the correct params', async function () { 189 it('Should succeed with the correct params', async function () {
174 await getVideoPlaylist(server.url, playlistUUID, 200) 190 await getVideoPlaylist(server.url, playlistUUID, HttpStatusCode.OK_200)
175 }) 191 })
176 }) 192 })
177 193
178 describe('When creating/updating a video playlist', function () { 194 describe('When creating/updating a video playlist', function () {
179 const getBase = (playlistAttrs: any = {}, wrapper: any = {}) => { 195 const getBase = (playlistAttrs: any = {}, wrapper: any = {}) => {
180 return Object.assign({ 196 return Object.assign({
181 expectedStatus: 400, 197 expectedStatus: HttpStatusCode.BAD_REQUEST_400,
182 url: server.url, 198 url: server.url,
183 token: server.accessToken, 199 token: server.accessToken,
184 playlistAttrs: Object.assign({ 200 playlistAttrs: Object.assign({
@@ -194,7 +210,7 @@ describe('Test video playlists API validator', function () {
194 } 210 }
195 211
196 it('Should fail with an unauthenticated user', async function () { 212 it('Should fail with an unauthenticated user', async function () {
197 const params = getBase({}, { token: null, expectedStatus: 401 }) 213 const params = getBase({}, { token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
198 214
199 await createVideoPlaylist(params) 215 await createVideoPlaylist(params)
200 await updateVideoPlaylist(getUpdate(params, playlistUUID)) 216 await updateVideoPlaylist(getUpdate(params, playlistUUID))
@@ -228,7 +244,7 @@ describe('Test video playlists API validator', function () {
228 }) 244 })
229 245
230 it('Should fail with an unknown video channel id', async function () { 246 it('Should fail with an unknown video channel id', async function () {
231 const params = getBase({ videoChannelId: 42 }, { expectedStatus: 404 }) 247 const params = getBase({ videoChannelId: 42 }, { expectedStatus: HttpStatusCode.NOT_FOUND_404 })
232 248
233 await createVideoPlaylist(params) 249 await createVideoPlaylist(params)
234 await updateVideoPlaylist(getUpdate(params, playlistUUID)) 250 await updateVideoPlaylist(getUpdate(params, playlistUUID))
@@ -255,33 +271,33 @@ describe('Test video playlists API validator', function () {
255 271
256 it('Should fail with an unknown playlist to update', async function () { 272 it('Should fail with an unknown playlist to update', async function () {
257 await updateVideoPlaylist(getUpdate( 273 await updateVideoPlaylist(getUpdate(
258 getBase({}, { expectedStatus: 404 }), 274 getBase({}, { expectedStatus: HttpStatusCode.NOT_FOUND_404 }),
259 42 275 42
260 )) 276 ))
261 }) 277 })
262 278
263 it('Should fail to update a playlist of another user', async function () { 279 it('Should fail to update a playlist of another user', async function () {
264 await updateVideoPlaylist(getUpdate( 280 await updateVideoPlaylist(getUpdate(
265 getBase({}, { token: userAccessToken, expectedStatus: 403 }), 281 getBase({}, { token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }),
266 playlistUUID 282 playlistUUID
267 )) 283 ))
268 }) 284 })
269 285
270 it('Should fail to update the watch later playlist', async function () { 286 it('Should fail to update the watch later playlist', async function () {
271 await updateVideoPlaylist(getUpdate( 287 await updateVideoPlaylist(getUpdate(
272 getBase({}, { expectedStatus: 400 }), 288 getBase({}, { expectedStatus: HttpStatusCode.BAD_REQUEST_400 }),
273 watchLaterPlaylistId 289 watchLaterPlaylistId
274 )) 290 ))
275 }) 291 })
276 292
277 it('Should succeed with the correct params', async function () { 293 it('Should succeed with the correct params', async function () {
278 { 294 {
279 const params = getBase({}, { expectedStatus: 200 }) 295 const params = getBase({}, { expectedStatus: HttpStatusCode.OK_200 })
280 await createVideoPlaylist(params) 296 await createVideoPlaylist(params)
281 } 297 }
282 298
283 { 299 {
284 const params = getBase({}, { expectedStatus: 204 }) 300 const params = getBase({}, { expectedStatus: HttpStatusCode.NO_CONTENT_204 })
285 await updateVideoPlaylist(getUpdate(params, playlistUUID)) 301 await updateVideoPlaylist(getUpdate(params, playlistUUID))
286 } 302 }
287 }) 303 })
@@ -290,7 +306,7 @@ describe('Test video playlists API validator', function () {
290 describe('When adding an element in a playlist', function () { 306 describe('When adding an element in a playlist', function () {
291 const getBase = (elementAttrs: any = {}, wrapper: any = {}) => { 307 const getBase = (elementAttrs: any = {}, wrapper: any = {}) => {
292 return Object.assign({ 308 return Object.assign({
293 expectedStatus: 400, 309 expectedStatus: HttpStatusCode.BAD_REQUEST_400,
294 url: server.url, 310 url: server.url,
295 token: server.accessToken, 311 token: server.accessToken,
296 playlistId: playlistUUID, 312 playlistId: playlistUUID,
@@ -303,12 +319,12 @@ describe('Test video playlists API validator', function () {
303 } 319 }
304 320
305 it('Should fail with an unauthenticated user', async function () { 321 it('Should fail with an unauthenticated user', async function () {
306 const params = getBase({}, { token: null, expectedStatus: 401 }) 322 const params = getBase({}, { token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
307 await addVideoInPlaylist(params) 323 await addVideoInPlaylist(params)
308 }) 324 })
309 325
310 it('Should fail with the playlist of another user', async function () { 326 it('Should fail with the playlist of another user', async function () {
311 const params = getBase({}, { token: userAccessToken, expectedStatus: 403 }) 327 const params = getBase({}, { token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
312 await addVideoInPlaylist(params) 328 await addVideoInPlaylist(params)
313 }) 329 })
314 330
@@ -319,13 +335,13 @@ describe('Test video playlists API validator', function () {
319 } 335 }
320 336
321 { 337 {
322 const params = getBase({}, { playlistId: 42, expectedStatus: 404 }) 338 const params = getBase({}, { playlistId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
323 await addVideoInPlaylist(params) 339 await addVideoInPlaylist(params)
324 } 340 }
325 }) 341 })
326 342
327 it('Should fail with an unknown or incorrect video id', async function () { 343 it('Should fail with an unknown or incorrect video id', async function () {
328 const params = getBase({ videoId: 42 }, { expectedStatus: 404 }) 344 const params = getBase({ videoId: 42 }, { expectedStatus: HttpStatusCode.NOT_FOUND_404 })
329 await addVideoInPlaylist(params) 345 await addVideoInPlaylist(params)
330 }) 346 })
331 347
@@ -342,7 +358,7 @@ describe('Test video playlists API validator', function () {
342 }) 358 })
343 359
344 it('Succeed with the correct params', async function () { 360 it('Succeed with the correct params', async function () {
345 const params = getBase({}, { expectedStatus: 200 }) 361 const params = getBase({}, { expectedStatus: HttpStatusCode.OK_200 })
346 const res = await addVideoInPlaylist(params) 362 const res = await addVideoInPlaylist(params)
347 playlistElementId = res.body.videoPlaylistElement.id 363 playlistElementId = res.body.videoPlaylistElement.id
348 }) 364 })
@@ -359,17 +375,17 @@ describe('Test video playlists API validator', function () {
359 }, elementAttrs), 375 }, elementAttrs),
360 playlistElementId, 376 playlistElementId,
361 playlistId: playlistUUID, 377 playlistId: playlistUUID,
362 expectedStatus: 400 378 expectedStatus: HttpStatusCode.BAD_REQUEST_400
363 }, wrapper) 379 }, wrapper)
364 } 380 }
365 381
366 it('Should fail with an unauthenticated user', async function () { 382 it('Should fail with an unauthenticated user', async function () {
367 const params = getBase({}, { token: null, expectedStatus: 401 }) 383 const params = getBase({}, { token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
368 await updateVideoPlaylistElement(params) 384 await updateVideoPlaylistElement(params)
369 }) 385 })
370 386
371 it('Should fail with the playlist of another user', async function () { 387 it('Should fail with the playlist of another user', async function () {
372 const params = getBase({}, { token: userAccessToken, expectedStatus: 403 }) 388 const params = getBase({}, { token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
373 await updateVideoPlaylistElement(params) 389 await updateVideoPlaylistElement(params)
374 }) 390 })
375 391
@@ -380,7 +396,7 @@ describe('Test video playlists API validator', function () {
380 } 396 }
381 397
382 { 398 {
383 const params = getBase({}, { playlistId: 42, expectedStatus: 404 }) 399 const params = getBase({}, { playlistId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
384 await updateVideoPlaylistElement(params) 400 await updateVideoPlaylistElement(params)
385 } 401 }
386 }) 402 })
@@ -392,7 +408,7 @@ describe('Test video playlists API validator', function () {
392 } 408 }
393 409
394 { 410 {
395 const params = getBase({}, { playlistElementId: 42, expectedStatus: 404 }) 411 const params = getBase({}, { playlistElementId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
396 await updateVideoPlaylistElement(params) 412 await updateVideoPlaylistElement(params)
397 } 413 }
398 }) 414 })
@@ -410,12 +426,12 @@ describe('Test video playlists API validator', function () {
410 }) 426 })
411 427
412 it('Should fail with an unknown element', async function () { 428 it('Should fail with an unknown element', async function () {
413 const params = getBase({}, { playlistElementId: 888, expectedStatus: 404 }) 429 const params = getBase({}, { playlistElementId: 888, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
414 await updateVideoPlaylistElement(params) 430 await updateVideoPlaylistElement(params)
415 }) 431 })
416 432
417 it('Succeed with the correct params', async function () { 433 it('Succeed with the correct params', async function () {
418 const params = getBase({}, { expectedStatus: 204 }) 434 const params = getBase({}, { expectedStatus: HttpStatusCode.NO_CONTENT_204 })
419 await updateVideoPlaylistElement(params) 435 await updateVideoPlaylistElement(params)
420 }) 436 })
421 }) 437 })
@@ -434,7 +450,7 @@ describe('Test video playlists API validator', function () {
434 insertAfterPosition: 2, 450 insertAfterPosition: 2,
435 reorderLength: 3 451 reorderLength: 3
436 }, elementAttrs), 452 }, elementAttrs),
437 expectedStatus: 400 453 expectedStatus: HttpStatusCode.BAD_REQUEST_400
438 }, wrapper) 454 }, wrapper)
439 } 455 }
440 456
@@ -453,12 +469,12 @@ describe('Test video playlists API validator', function () {
453 }) 469 })
454 470
455 it('Should fail with an unauthenticated user', async function () { 471 it('Should fail with an unauthenticated user', async function () {
456 const params = getBase({}, { token: null, expectedStatus: 401 }) 472 const params = getBase({}, { token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
457 await reorderVideosPlaylist(params) 473 await reorderVideosPlaylist(params)
458 }) 474 })
459 475
460 it('Should fail with the playlist of another user', async function () { 476 it('Should fail with the playlist of another user', async function () {
461 const params = getBase({}, { token: userAccessToken, expectedStatus: 403 }) 477 const params = getBase({}, { token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
462 await reorderVideosPlaylist(params) 478 await reorderVideosPlaylist(params)
463 }) 479 })
464 480
@@ -469,7 +485,7 @@ describe('Test video playlists API validator', function () {
469 } 485 }
470 486
471 { 487 {
472 const params = getBase({}, { playlistId: 42, expectedStatus: 404 }) 488 const params = getBase({}, { playlistId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
473 await reorderVideosPlaylist(params) 489 await reorderVideosPlaylist(params)
474 } 490 }
475 }) 491 })
@@ -526,7 +542,7 @@ describe('Test video playlists API validator', function () {
526 }) 542 })
527 543
528 it('Succeed with the correct params', async function () { 544 it('Succeed with the correct params', async function () {
529 const params = getBase({}, { expectedStatus: 204 }) 545 const params = getBase({}, { expectedStatus: HttpStatusCode.NO_CONTENT_204 })
530 await reorderVideosPlaylist(params) 546 await reorderVideosPlaylist(params)
531 }) 547 })
532 }) 548 })
@@ -539,7 +555,7 @@ describe('Test video playlists API validator', function () {
539 url: server.url, 555 url: server.url,
540 path, 556 path,
541 query: { videoIds: [ 1, 2 ] }, 557 query: { videoIds: [ 1, 2 ] },
542 statusCodeExpected: 401 558 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
543 }) 559 })
544 }) 560 })
545 561
@@ -572,7 +588,7 @@ describe('Test video playlists API validator', function () {
572 token: server.accessToken, 588 token: server.accessToken,
573 path, 589 path,
574 query: { videoIds: [ 1, 2 ] }, 590 query: { videoIds: [ 1, 2 ] },
575 statusCodeExpected: 200 591 statusCodeExpected: HttpStatusCode.OK_200
576 }) 592 })
577 }) 593 })
578 }) 594 })
@@ -584,17 +600,17 @@ describe('Test video playlists API validator', function () {
584 token: server.accessToken, 600 token: server.accessToken,
585 playlistElementId, 601 playlistElementId,
586 playlistId: playlistUUID, 602 playlistId: playlistUUID,
587 expectedStatus: 400 603 expectedStatus: HttpStatusCode.BAD_REQUEST_400
588 }, wrapper) 604 }, wrapper)
589 } 605 }
590 606
591 it('Should fail with an unauthenticated user', async function () { 607 it('Should fail with an unauthenticated user', async function () {
592 const params = getBase({ token: null, expectedStatus: 401 }) 608 const params = getBase({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
593 await removeVideoFromPlaylist(params) 609 await removeVideoFromPlaylist(params)
594 }) 610 })
595 611
596 it('Should fail with the playlist of another user', async function () { 612 it('Should fail with the playlist of another user', async function () {
597 const params = getBase({ token: userAccessToken, expectedStatus: 403 }) 613 const params = getBase({ token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
598 await removeVideoFromPlaylist(params) 614 await removeVideoFromPlaylist(params)
599 }) 615 })
600 616
@@ -605,7 +621,7 @@ describe('Test video playlists API validator', function () {
605 } 621 }
606 622
607 { 623 {
608 const params = getBase({ playlistId: 42, expectedStatus: 404 }) 624 const params = getBase({ playlistId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
609 await removeVideoFromPlaylist(params) 625 await removeVideoFromPlaylist(params)
610 } 626 }
611 }) 627 })
@@ -617,33 +633,33 @@ describe('Test video playlists API validator', function () {
617 } 633 }
618 634
619 { 635 {
620 const params = getBase({ playlistElementId: 42, expectedStatus: 404 }) 636 const params = getBase({ playlistElementId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
621 await removeVideoFromPlaylist(params) 637 await removeVideoFromPlaylist(params)
622 } 638 }
623 }) 639 })
624 640
625 it('Should fail with an unknown element', async function () { 641 it('Should fail with an unknown element', async function () {
626 const params = getBase({ playlistElementId: 888, expectedStatus: 404 }) 642 const params = getBase({ playlistElementId: 888, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
627 await removeVideoFromPlaylist(params) 643 await removeVideoFromPlaylist(params)
628 }) 644 })
629 645
630 it('Succeed with the correct params', async function () { 646 it('Succeed with the correct params', async function () {
631 const params = getBase({ expectedStatus: 204 }) 647 const params = getBase({ expectedStatus: HttpStatusCode.NO_CONTENT_204 })
632 await removeVideoFromPlaylist(params) 648 await removeVideoFromPlaylist(params)
633 }) 649 })
634 }) 650 })
635 651
636 describe('When deleting a playlist', function () { 652 describe('When deleting a playlist', function () {
637 it('Should fail with an unknown playlist', async function () { 653 it('Should fail with an unknown playlist', async function () {
638 await deleteVideoPlaylist(server.url, server.accessToken, 42, 404) 654 await deleteVideoPlaylist(server.url, server.accessToken, 42, HttpStatusCode.NOT_FOUND_404)
639 }) 655 })
640 656
641 it('Should fail with a playlist of another user', async function () { 657 it('Should fail with a playlist of another user', async function () {
642 await deleteVideoPlaylist(server.url, userAccessToken, playlistUUID, 403) 658 await deleteVideoPlaylist(server.url, userAccessToken, playlistUUID, HttpStatusCode.FORBIDDEN_403)
643 }) 659 })
644 660
645 it('Should fail with the watch later playlist', async function () { 661 it('Should fail with the watch later playlist', async function () {
646 await deleteVideoPlaylist(server.url, server.accessToken, watchLaterPlaylistId, 400) 662 await deleteVideoPlaylist(server.url, server.accessToken, watchLaterPlaylistId, HttpStatusCode.BAD_REQUEST_400)
647 }) 663 })
648 664
649 it('Should succeed with the correct params', async function () { 665 it('Should succeed with the correct params', async function () {
diff --git a/server/tests/api/check-params/videos-filter.ts b/server/tests/api/check-params/videos-filter.ts
index bf8248b0e..2391584a7 100644
--- a/server/tests/api/check-params/videos-filter.ts
+++ b/server/tests/api/check-params/videos-filter.ts
@@ -12,8 +12,9 @@ import {
12 userLogin 12 userLogin
13} from '../../../../shared/extra-utils' 13} from '../../../../shared/extra-utils'
14import { UserRole } from '../../../../shared/models/users' 14import { UserRole } from '../../../../shared/models/users'
15import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
15 16
16async function testEndpoints (server: ServerInfo, token: string, filter: string, statusCodeExpected: number) { 17async function testEndpoints (server: ServerInfo, token: string, filter: string, statusCodeExpected: HttpStatusCode) {
17 const paths = [ 18 const paths = [
18 '/api/v1/video-channels/root_channel/videos', 19 '/api/v1/video-channels/root_channel/videos',
19 '/api/v1/accounts/root/videos', 20 '/api/v1/accounts/root/videos',
@@ -71,26 +72,26 @@ describe('Test videos filters', function () {
71 describe('When setting a video filter', function () { 72 describe('When setting a video filter', function () {
72 73
73 it('Should fail with a bad filter', async function () { 74 it('Should fail with a bad filter', async function () {
74 await testEndpoints(server, server.accessToken, 'bad-filter', 400) 75 await testEndpoints(server, server.accessToken, 'bad-filter', HttpStatusCode.BAD_REQUEST_400)
75 }) 76 })
76 77
77 it('Should succeed with a good filter', async function () { 78 it('Should succeed with a good filter', async function () {
78 await testEndpoints(server, server.accessToken, 'local', 200) 79 await testEndpoints(server, server.accessToken, 'local', HttpStatusCode.OK_200)
79 }) 80 })
80 81
81 it('Should fail to list all-local/all with a simple user', async function () { 82 it('Should fail to list all-local/all with a simple user', async function () {
82 await testEndpoints(server, userAccessToken, 'all-local', 401) 83 await testEndpoints(server, userAccessToken, 'all-local', HttpStatusCode.UNAUTHORIZED_401)
83 await testEndpoints(server, userAccessToken, 'all', 401) 84 await testEndpoints(server, userAccessToken, 'all', HttpStatusCode.UNAUTHORIZED_401)
84 }) 85 })
85 86
86 it('Should succeed to list all-local/all with a moderator', async function () { 87 it('Should succeed to list all-local/all with a moderator', async function () {
87 await testEndpoints(server, moderatorAccessToken, 'all-local', 200) 88 await testEndpoints(server, moderatorAccessToken, 'all-local', HttpStatusCode.OK_200)
88 await testEndpoints(server, moderatorAccessToken, 'all', 200) 89 await testEndpoints(server, moderatorAccessToken, 'all', HttpStatusCode.OK_200)
89 }) 90 })
90 91
91 it('Should succeed to list all-local/all with an admin', async function () { 92 it('Should succeed to list all-local/all with an admin', async function () {
92 await testEndpoints(server, server.accessToken, 'all-local', 200) 93 await testEndpoints(server, server.accessToken, 'all-local', HttpStatusCode.OK_200)
93 await testEndpoints(server, server.accessToken, 'all', 200) 94 await testEndpoints(server, server.accessToken, 'all', HttpStatusCode.OK_200)
94 }) 95 })
95 96
96 // Because we cannot authenticate the user on the RSS endpoint 97 // Because we cannot authenticate the user on the RSS endpoint
@@ -99,7 +100,7 @@ describe('Test videos filters', function () {
99 await makeGetRequest({ 100 await makeGetRequest({
100 url: server.url, 101 url: server.url,
101 path: '/feeds/videos.json', 102 path: '/feeds/videos.json',
102 statusCodeExpected: 401, 103 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401,
103 query: { 104 query: {
104 filter 105 filter
105 } 106 }
@@ -111,7 +112,7 @@ describe('Test videos filters', function () {
111 await makeGetRequest({ 112 await makeGetRequest({
112 url: server.url, 113 url: server.url,
113 path: '/feeds/videos.json', 114 path: '/feeds/videos.json',
114 statusCodeExpected: 200, 115 statusCodeExpected: HttpStatusCode.OK_200,
115 query: { 116 query: {
116 filter: 'local' 117 filter: 'local'
117 } 118 }
diff --git a/server/tests/api/check-params/videos-history.ts b/server/tests/api/check-params/videos-history.ts
index 941f62654..0e91fe0a8 100644
--- a/server/tests/api/check-params/videos-history.ts
+++ b/server/tests/api/check-params/videos-history.ts
@@ -13,6 +13,7 @@ import {
13 setAccessTokensToServers, 13 setAccessTokensToServers,
14 uploadVideo 14 uploadVideo
15} from '../../../../shared/extra-utils' 15} from '../../../../shared/extra-utils'
16import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
16 17
17describe('Test videos history API validator', function () { 18describe('Test videos history API validator', function () {
18 const myHistoryPath = '/api/v1/users/me/history/videos' 19 const myHistoryPath = '/api/v1/users/me/history/videos'
@@ -39,31 +40,55 @@ describe('Test videos history API validator', function () {
39 40
40 it('Should fail with an unauthenticated user', async function () { 41 it('Should fail with an unauthenticated user', async function () {
41 const fields = { currentTime: 5 } 42 const fields = { currentTime: 5 }
42 await makePutBodyRequest({ url: server.url, path: watchingPath, fields, statusCodeExpected: 401 }) 43 await makePutBodyRequest({ url: server.url, path: watchingPath, fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
43 }) 44 })
44 45
45 it('Should fail with an incorrect video id', async function () { 46 it('Should fail with an incorrect video id', async function () {
46 const fields = { currentTime: 5 } 47 const fields = { currentTime: 5 }
47 const path = '/api/v1/videos/blabla/watching' 48 const path = '/api/v1/videos/blabla/watching'
48 await makePutBodyRequest({ url: server.url, path, fields, token: server.accessToken, statusCodeExpected: 400 }) 49 await makePutBodyRequest({
50 url: server.url,
51 path,
52 fields,
53 token: server.accessToken,
54 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
55 })
49 }) 56 })
50 57
51 it('Should fail with an unknown video', async function () { 58 it('Should fail with an unknown video', async function () {
52 const fields = { currentTime: 5 } 59 const fields = { currentTime: 5 }
53 const path = '/api/v1/videos/d91fff41-c24d-4508-8e13-3bd5902c3b02/watching' 60 const path = '/api/v1/videos/d91fff41-c24d-4508-8e13-3bd5902c3b02/watching'
54 61
55 await makePutBodyRequest({ url: server.url, path, fields, token: server.accessToken, statusCodeExpected: 404 }) 62 await makePutBodyRequest({
63 url: server.url,
64 path,
65 fields,
66 token: server.accessToken,
67 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
68 })
56 }) 69 })
57 70
58 it('Should fail with a bad current time', async function () { 71 it('Should fail with a bad current time', async function () {
59 const fields = { currentTime: 'hello' } 72 const fields = { currentTime: 'hello' }
60 await makePutBodyRequest({ url: server.url, path: watchingPath, fields, token: server.accessToken, statusCodeExpected: 400 }) 73 await makePutBodyRequest({
74 url: server.url,
75 path: watchingPath,
76 fields,
77 token: server.accessToken,
78 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
79 })
61 }) 80 })
62 81
63 it('Should succeed with the correct parameters', async function () { 82 it('Should succeed with the correct parameters', async function () {
64 const fields = { currentTime: 5 } 83 const fields = { currentTime: 5 }
65 84
66 await makePutBodyRequest({ url: server.url, path: watchingPath, fields, token: server.accessToken, statusCodeExpected: 204 }) 85 await makePutBodyRequest({
86 url: server.url,
87 path: watchingPath,
88 fields,
89 token: server.accessToken,
90 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
91 })
67 }) 92 })
68 }) 93 })
69 94
@@ -77,17 +102,17 @@ describe('Test videos history API validator', function () {
77 }) 102 })
78 103
79 it('Should fail with an unauthenticated user', async function () { 104 it('Should fail with an unauthenticated user', async function () {
80 await makeGetRequest({ url: server.url, path: myHistoryPath, statusCodeExpected: 401 }) 105 await makeGetRequest({ url: server.url, path: myHistoryPath, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
81 }) 106 })
82 107
83 it('Should succeed with the correct params', async function () { 108 it('Should succeed with the correct params', async function () {
84 await makeGetRequest({ url: server.url, token: server.accessToken, path: myHistoryPath, statusCodeExpected: 200 }) 109 await makeGetRequest({ url: server.url, token: server.accessToken, path: myHistoryPath, statusCodeExpected: HttpStatusCode.OK_200 })
85 }) 110 })
86 }) 111 })
87 112
88 describe('When removing user videos history', function () { 113 describe('When removing user videos history', function () {
89 it('Should fail with an unauthenticated user', async function () { 114 it('Should fail with an unauthenticated user', async function () {
90 await makePostBodyRequest({ url: server.url, path: myHistoryPath + '/remove', statusCodeExpected: 401 }) 115 await makePostBodyRequest({ url: server.url, path: myHistoryPath + '/remove', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 })
91 }) 116 })
92 117
93 it('Should fail with a bad beforeDate parameter', async function () { 118 it('Should fail with a bad beforeDate parameter', async function () {
@@ -97,7 +122,7 @@ describe('Test videos history API validator', function () {
97 token: server.accessToken, 122 token: server.accessToken,
98 path: myHistoryRemove, 123 path: myHistoryRemove,
99 fields: body, 124 fields: body,
100 statusCodeExpected: 400 125 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
101 }) 126 })
102 }) 127 })
103 128
@@ -108,7 +133,7 @@ describe('Test videos history API validator', function () {
108 token: server.accessToken, 133 token: server.accessToken,
109 path: myHistoryRemove, 134 path: myHistoryRemove,
110 fields: body, 135 fields: body,
111 statusCodeExpected: 204 136 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
112 }) 137 })
113 }) 138 })
114 139
@@ -117,7 +142,7 @@ describe('Test videos history API validator', function () {
117 url: server.url, 142 url: server.url,
118 token: server.accessToken, 143 token: server.accessToken,
119 path: myHistoryRemove, 144 path: myHistoryRemove,
120 statusCodeExpected: 204 145 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
121 }) 146 })
122 }) 147 })
123 }) 148 })
diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts
index 0d4665954..d60546917 100644
--- a/server/tests/api/check-params/videos.ts
+++ b/server/tests/api/check-params/videos.ts
@@ -28,6 +28,7 @@ import {
28 checkBadSortPagination, 28 checkBadSortPagination,
29 checkBadStartPagination 29 checkBadStartPagination
30} from '../../../../shared/extra-utils/requests/check-api-params' 30} from '../../../../shared/extra-utils/requests/check-api-params'
31import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
31 32
32const expect = chai.expect 33const expect = chai.expect
33 34
@@ -76,11 +77,11 @@ describe('Test videos API validator', function () {
76 }) 77 })
77 78
78 it('Should fail with a bad skipVideos query', async function () { 79 it('Should fail with a bad skipVideos query', async function () {
79 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200, query: { skipCount: 'toto' } }) 80 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200, query: { skipCount: 'toto' } })
80 }) 81 })
81 82
82 it('Should success with the correct parameters', async function () { 83 it('Should success with the correct parameters', async function () {
83 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200, query: { skipCount: false } }) 84 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200, query: { skipCount: false } })
84 }) 85 })
85 }) 86 })
86 87
@@ -90,7 +91,7 @@ describe('Test videos API validator', function () {
90 await makeGetRequest({ 91 await makeGetRequest({
91 url: server.url, 92 url: server.url,
92 path: join(path, 'search'), 93 path: join(path, 'search'),
93 statusCodeExpected: 400 94 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
94 }) 95 })
95 }) 96 })
96 97
@@ -107,7 +108,7 @@ describe('Test videos API validator', function () {
107 }) 108 })
108 109
109 it('Should success with the correct parameters', async function () { 110 it('Should success with the correct parameters', async function () {
110 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 }) 111 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 })
111 }) 112 })
112 }) 113 })
113 114
@@ -127,7 +128,7 @@ describe('Test videos API validator', function () {
127 }) 128 })
128 129
129 it('Should success with the correct parameters', async function () { 130 it('Should success with the correct parameters', async function () {
130 await makeGetRequest({ url: server.url, token: server.accessToken, path, statusCodeExpected: 200 }) 131 await makeGetRequest({ url: server.url, token: server.accessToken, path, statusCodeExpected: HttpStatusCode.OK_200 })
131 }) 132 })
132 }) 133 })
133 134
@@ -151,7 +152,7 @@ describe('Test videos API validator', function () {
151 }) 152 })
152 153
153 it('Should success with the correct parameters', async function () { 154 it('Should success with the correct parameters', async function () {
154 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 }) 155 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 })
155 }) 156 })
156 }) 157 })
157 158
@@ -175,7 +176,7 @@ describe('Test videos API validator', function () {
175 }) 176 })
176 177
177 it('Should success with the correct parameters', async function () { 178 it('Should success with the correct parameters', async function () {
178 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 }) 179 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 })
179 }) 180 })
180 }) 181 })
181 182
@@ -408,7 +409,7 @@ describe('Test videos API validator', function () {
408 token: server.accessToken, 409 token: server.accessToken,
409 fields, 410 fields,
410 attaches, 411 attaches,
411 statusCodeExpected: 200 412 statusCodeExpected: HttpStatusCode.OK_200
412 }) 413 })
413 } 414 }
414 415
@@ -423,7 +424,7 @@ describe('Test videos API validator', function () {
423 token: server.accessToken, 424 token: server.accessToken,
424 fields, 425 fields,
425 attaches, 426 attaches,
426 statusCodeExpected: 200 427 statusCodeExpected: HttpStatusCode.OK_200
427 }) 428 })
428 } 429 }
429 430
@@ -438,7 +439,7 @@ describe('Test videos API validator', function () {
438 token: server.accessToken, 439 token: server.accessToken,
439 fields, 440 fields,
440 attaches, 441 attaches,
441 statusCodeExpected: 200 442 statusCodeExpected: HttpStatusCode.OK_200
442 }) 443 })
443 } 444 }
444 }) 445 })
@@ -481,7 +482,7 @@ describe('Test videos API validator', function () {
481 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06', 482 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
482 token: server.accessToken, 483 token: server.accessToken,
483 fields, 484 fields,
484 statusCodeExpected: 404 485 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
485 }) 486 })
486 }) 487 })
487 488
@@ -630,7 +631,13 @@ describe('Test videos API validator', function () {
630 it('Should fail with a video of another user without the appropriate right', async function () { 631 it('Should fail with a video of another user without the appropriate right', async function () {
631 const fields = baseCorrectParams 632 const fields = baseCorrectParams
632 633
633 await makePutBodyRequest({ url: server.url, path: path + videoId, token: userAccessToken, fields, statusCodeExpected: 403 }) 634 await makePutBodyRequest({
635 url: server.url,
636 path: path + videoId,
637 token: userAccessToken,
638 fields,
639 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
640 })
634 }) 641 })
635 642
636 it('Should fail with a video of another server') 643 it('Should fail with a video of another server')
@@ -638,7 +645,13 @@ describe('Test videos API validator', function () {
638 it('Should succeed with the correct parameters', async function () { 645 it('Should succeed with the correct parameters', async function () {
639 const fields = baseCorrectParams 646 const fields = baseCorrectParams
640 647
641 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields, statusCodeExpected: 204 }) 648 await makePutBodyRequest({
649 url: server.url,
650 path: path + videoId,
651 token: server.accessToken,
652 fields,
653 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
654 })
642 }) 655 })
643 }) 656 })
644 657
@@ -647,7 +660,7 @@ describe('Test videos API validator', function () {
647 const res = await makeGetRequest({ 660 const res = await makeGetRequest({
648 url: server.url, 661 url: server.url,
649 path, 662 path,
650 statusCodeExpected: 200 663 statusCodeExpected: HttpStatusCode.OK_200
651 }) 664 })
652 665
653 expect(res.body.data).to.be.an('array') 666 expect(res.body.data).to.be.an('array')
@@ -655,11 +668,11 @@ describe('Test videos API validator', function () {
655 }) 668 })
656 669
657 it('Should fail without a correct uuid', async function () { 670 it('Should fail without a correct uuid', async function () {
658 await getVideo(server.url, 'coucou', 400) 671 await getVideo(server.url, 'coucou', HttpStatusCode.BAD_REQUEST_400)
659 }) 672 })
660 673
661 it('Should return 404 with an incorrect video', async function () { 674 it('Should return 404 with an incorrect video', async function () {
662 await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', 404) 675 await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404)
663 }) 676 })
664 677
665 it('Should succeed with the correct parameters', async function () { 678 it('Should succeed with the correct parameters', async function () {
@@ -691,7 +704,7 @@ describe('Test videos API validator', function () {
691 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate', 704 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
692 token: server.accessToken, 705 token: server.accessToken,
693 fields, 706 fields,
694 statusCodeExpected: 404 707 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
695 }) 708 })
696 }) 709 })
697 710
@@ -711,7 +724,7 @@ describe('Test videos API validator', function () {
711 path: path + videoId + '/rate', 724 path: path + videoId + '/rate',
712 token: server.accessToken, 725 token: server.accessToken,
713 fields, 726 fields,
714 statusCodeExpected: 204 727 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
715 }) 728 })
716 }) 729 })
717 }) 730 })
@@ -721,20 +734,20 @@ describe('Test videos API validator', function () {
721 await makeDeleteRequest({ 734 await makeDeleteRequest({
722 url: server.url, 735 url: server.url,
723 path, 736 path,
724 statusCodeExpected: 400 737 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
725 }) 738 })
726 }) 739 })
727 740
728 it('Should fail without a correct uuid', async function () { 741 it('Should fail without a correct uuid', async function () {
729 await removeVideo(server.url, server.accessToken, 'hello', 400) 742 await removeVideo(server.url, server.accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400)
730 }) 743 })
731 744
732 it('Should fail with a video which does not exist', async function () { 745 it('Should fail with a video which does not exist', async function () {
733 await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404) 746 await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404)
734 }) 747 })
735 748
736 it('Should fail with a video of another user without the appropriate right', async function () { 749 it('Should fail with a video of another user without the appropriate right', async function () {
737 await removeVideo(server.url, userAccessToken, videoId, 403) 750 await removeVideo(server.url, userAccessToken, videoId, HttpStatusCode.FORBIDDEN_403)
738 }) 751 })
739 752
740 it('Should fail with a video of another server') 753 it('Should fail with a video of another server')
diff --git a/server/tests/api/redundancy/redundancy.ts b/server/tests/api/redundancy/redundancy.ts
index c5037a541..7cfcf70e1 100644
--- a/server/tests/api/redundancy/redundancy.ts
+++ b/server/tests/api/redundancy/redundancy.ts
@@ -41,6 +41,7 @@ import { join } from 'path'
41import { VideoRedundancy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '../../../../shared/models/redundancy' 41import { VideoRedundancy, VideoRedundancyStrategy, VideoRedundancyStrategyWithManual } from '../../../../shared/models/redundancy'
42import { getStats } from '../../../../shared/extra-utils/server/stats' 42import { getStats } from '../../../../shared/extra-utils/server/stats'
43import { ServerStats } from '../../../../shared/models/server/server-stats.model' 43import { ServerStats } from '../../../../shared/models/server/server-stats.model'
44import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
44 45
45const expect = chai.expect 46const expect = chai.expect
46 47
@@ -147,13 +148,13 @@ async function check2Webseeds (videoUUID?: string) {
147 148
148 await makeGetRequest({ 149 await makeGetRequest({
149 url: servers[0].url, 150 url: servers[0].url,
150 statusCodeExpected: 200, 151 statusCodeExpected: HttpStatusCode.OK_200,
151 path: '/static/redundancy/' + `${videoUUID}-${file.resolution.id}.mp4`, 152 path: '/static/redundancy/' + `${videoUUID}-${file.resolution.id}.mp4`,
152 contentType: null 153 contentType: null
153 }) 154 })
154 await makeGetRequest({ 155 await makeGetRequest({
155 url: servers[1].url, 156 url: servers[1].url,
156 statusCodeExpected: 200, 157 statusCodeExpected: HttpStatusCode.OK_200,
157 path: `/static/webseed/${videoUUID}-${file.resolution.id}.mp4`, 158 path: `/static/webseed/${videoUUID}-${file.resolution.id}.mp4`,
158 contentType: null 159 contentType: null
159 }) 160 })
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts
index fe83ca041..cd928b980 100644
--- a/server/tests/api/users/users.ts
+++ b/server/tests/api/users/users.ts
@@ -47,6 +47,7 @@ import { follow } from '../../../../shared/extra-utils/server/follows'
47import { logout, serverLogin, setAccessTokensToServers } from '../../../../shared/extra-utils/users/login' 47import { logout, serverLogin, setAccessTokensToServers } from '../../../../shared/extra-utils/users/login'
48import { getMyVideos } from '../../../../shared/extra-utils/videos/videos' 48import { getMyVideos } from '../../../../shared/extra-utils/videos/videos'
49import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' 49import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
50import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
50 51
51const expect = chai.expect 52const expect = chai.expect
52 53
@@ -86,14 +87,14 @@ describe('Test users', function () {
86 87
87 it('Should not login with an invalid client id', async function () { 88 it('Should not login with an invalid client id', async function () {
88 const client = { id: 'client', secret: server.client.secret } 89 const client = { id: 'client', secret: server.client.secret }
89 const res = await login(server.url, client, server.user, 400) 90 const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400)
90 91
91 expect(res.body.error).to.contain('client is invalid') 92 expect(res.body.error).to.contain('client is invalid')
92 }) 93 })
93 94
94 it('Should not login with an invalid client secret', async function () { 95 it('Should not login with an invalid client secret', async function () {
95 const client = { id: server.client.id, secret: 'coucou' } 96 const client = { id: server.client.id, secret: 'coucou' }
96 const res = await login(server.url, client, server.user, 400) 97 const res = await login(server.url, client, server.user, HttpStatusCode.BAD_REQUEST_400)
97 98
98 expect(res.body.error).to.contain('client is invalid') 99 expect(res.body.error).to.contain('client is invalid')
99 }) 100 })
@@ -103,14 +104,14 @@ describe('Test users', function () {
103 104
104 it('Should not login with an invalid username', async function () { 105 it('Should not login with an invalid username', async function () {
105 const user = { username: 'captain crochet', password: server.user.password } 106 const user = { username: 'captain crochet', password: server.user.password }
106 const res = await login(server.url, server.client, user, 400) 107 const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400)
107 108
108 expect(res.body.error).to.contain('credentials are invalid') 109 expect(res.body.error).to.contain('credentials are invalid')
109 }) 110 })
110 111
111 it('Should not login with an invalid password', async function () { 112 it('Should not login with an invalid password', async function () {
112 const user = { username: server.user.username, password: 'mew_three' } 113 const user = { username: server.user.username, password: 'mew_three' }
113 const res = await login(server.url, server.client, user, 400) 114 const res = await login(server.url, server.client, user, HttpStatusCode.BAD_REQUEST_400)
114 115
115 expect(res.body.error).to.contain('credentials are invalid') 116 expect(res.body.error).to.contain('credentials are invalid')
116 }) 117 })
@@ -119,31 +120,31 @@ describe('Test users', function () {
119 accessToken = 'my_super_token' 120 accessToken = 'my_super_token'
120 121
121 const videoAttributes = {} 122 const videoAttributes = {}
122 await uploadVideo(server.url, accessToken, videoAttributes, 401) 123 await uploadVideo(server.url, accessToken, videoAttributes, HttpStatusCode.UNAUTHORIZED_401)
123 }) 124 })
124 125
125 it('Should not be able to follow', async function () { 126 it('Should not be able to follow', async function () {
126 accessToken = 'my_super_token' 127 accessToken = 'my_super_token'
127 await follow(server.url, [ 'http://example.com' ], accessToken, 401) 128 await follow(server.url, [ 'http://example.com' ], accessToken, HttpStatusCode.UNAUTHORIZED_401)
128 }) 129 })
129 130
130 it('Should not be able to unfollow') 131 it('Should not be able to unfollow')
131 132
132 it('Should be able to login', async function () { 133 it('Should be able to login', async function () {
133 const res = await login(server.url, server.client, server.user, 200) 134 const res = await login(server.url, server.client, server.user, HttpStatusCode.OK_200)
134 135
135 accessToken = res.body.access_token 136 accessToken = res.body.access_token
136 }) 137 })
137 138
138 it('Should be able to login with an insensitive username', async function () { 139 it('Should be able to login with an insensitive username', async function () {
139 const user = { username: 'RoOt', password: server.user.password } 140 const user = { username: 'RoOt', password: server.user.password }
140 await login(server.url, server.client, user, 200) 141 await login(server.url, server.client, user, HttpStatusCode.OK_200)
141 142
142 const user2 = { username: 'rOoT', password: server.user.password } 143 const user2 = { username: 'rOoT', password: server.user.password }
143 await login(server.url, server.client, user2, 200) 144 await login(server.url, server.client, user2, HttpStatusCode.OK_200)
144 145
145 const user3 = { username: 'ROOt', password: server.user.password } 146 const user3 = { username: 'ROOt', password: server.user.password }
146 await login(server.url, server.client, user3, 200) 147 await login(server.url, server.client, user3, HttpStatusCode.OK_200)
147 }) 148 })
148 }) 149 })
149 150
@@ -179,7 +180,7 @@ describe('Test users', function () {
179 it('Should retrieve ratings list', async function () { 180 it('Should retrieve ratings list', async function () {
180 await rateVideo(server.url, accessToken, videoId, 'like') 181 await rateVideo(server.url, accessToken, videoId, 'like')
181 182
182 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, 200) 183 const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, HttpStatusCode.OK_200)
183 const ratings = res.body 184 const ratings = res.body
184 185
185 expect(ratings.total).to.equal(1) 186 expect(ratings.total).to.equal(1)
@@ -204,7 +205,7 @@ describe('Test users', function () {
204 205
205 describe('Remove video', function () { 206 describe('Remove video', function () {
206 it('Should not be able to remove the video with an incorrect token', async function () { 207 it('Should not be able to remove the video with an incorrect token', async function () {
207 await removeVideo(server.url, 'bad_token', videoId, 401) 208 await removeVideo(server.url, 'bad_token', videoId, HttpStatusCode.UNAUTHORIZED_401)
208 }) 209 })
209 210
210 it('Should not be able to remove the video with the token of another account') 211 it('Should not be able to remove the video with the token of another account')
@@ -220,11 +221,11 @@ describe('Test users', function () {
220 }) 221 })
221 222
222 it('Should not be able to get the user information', async function () { 223 it('Should not be able to get the user information', async function () {
223 await getMyUserInformation(server.url, server.accessToken, 401) 224 await getMyUserInformation(server.url, server.accessToken, HttpStatusCode.UNAUTHORIZED_401)
224 }) 225 })
225 226
226 it('Should not be able to upload a video', async function () { 227 it('Should not be able to upload a video', async function () {
227 await uploadVideo(server.url, server.accessToken, { name: 'video' }, 401) 228 await uploadVideo(server.url, server.accessToken, { name: 'video' }, HttpStatusCode.UNAUTHORIZED_401)
228 }) 229 })
229 230
230 it('Should not be able to rate a video', async function () { 231 it('Should not be able to rate a video', async function () {
@@ -238,7 +239,7 @@ describe('Test users', function () {
238 path: path + videoId, 239 path: path + videoId,
239 token: 'wrong token', 240 token: 'wrong token',
240 fields: data, 241 fields: data,
241 statusCodeExpected: 401 242 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
242 } 243 }
243 await makePutBodyRequest(options) 244 await makePutBodyRequest(options)
244 }) 245 })
@@ -534,7 +535,7 @@ describe('Test users', function () {
534 }) 535 })
535 user.password = 'new password' 536 user.password = 'new password'
536 537
537 await userLogin(server, user, 200) 538 await userLogin(server, user, HttpStatusCode.OK_200)
538 }) 539 })
539 540
540 it('Should be able to change the NSFW display attribute', async function () { 541 it('Should be able to change the NSFW display attribute', async function () {
@@ -732,7 +733,7 @@ describe('Test users', function () {
732 }) 733 })
733 734
734 it('Should have removed the user token', async function () { 735 it('Should have removed the user token', async function () {
735 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401) 736 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401)
736 737
737 accessTokenUser = await userLogin(server, user) 738 accessTokenUser = await userLogin(server, user)
738 }) 739 })
@@ -745,9 +746,9 @@ describe('Test users', function () {
745 password: 'password updated' 746 password: 'password updated'
746 }) 747 })
747 748
748 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401) 749 await getMyUserVideoQuotaUsed(server.url, accessTokenUser, HttpStatusCode.UNAUTHORIZED_401)
749 750
750 await userLogin(server, user, 400) 751 await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400)
751 752
752 user.password = 'password updated' 753 user.password = 'password updated'
753 accessTokenUser = await userLogin(server, user) 754 accessTokenUser = await userLogin(server, user)
@@ -766,7 +767,7 @@ describe('Test users', function () {
766 }) 767 })
767 768
768 it('Should not be able to login with this user', async function () { 769 it('Should not be able to login with this user', async function () {
769 await userLogin(server, user, 400) 770 await userLogin(server, user, HttpStatusCode.BAD_REQUEST_400)
770 }) 771 })
771 772
772 it('Should not have videos of this user', async function () { 773 it('Should not have videos of this user', async function () {
@@ -852,11 +853,11 @@ describe('Test users', function () {
852 853
853 user16AccessToken = await userLogin(server, user16) 854 user16AccessToken = await userLogin(server, user16)
854 855
855 await getMyUserInformation(server.url, user16AccessToken, 200) 856 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200)
856 await blockUser(server.url, user16Id, server.accessToken) 857 await blockUser(server.url, user16Id, server.accessToken)
857 858
858 await getMyUserInformation(server.url, user16AccessToken, 401) 859 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.UNAUTHORIZED_401)
859 await userLogin(server, user16, 400) 860 await userLogin(server, user16, HttpStatusCode.BAD_REQUEST_400)
860 }) 861 })
861 862
862 it('Should search user by banned status', async function () { 863 it('Should search user by banned status', async function () {
@@ -884,7 +885,7 @@ describe('Test users', function () {
884 it('Should unblock a user', async function () { 885 it('Should unblock a user', async function () {
885 await unblockUser(server.url, user16Id, server.accessToken) 886 await unblockUser(server.url, user16Id, server.accessToken)
886 user16AccessToken = await userLogin(server, user16) 887 user16AccessToken = await userLogin(server, user16)
887 await getMyUserInformation(server.url, user16AccessToken, 200) 888 await getMyUserInformation(server.url, user16AccessToken, HttpStatusCode.OK_200)
888 }) 889 })
889 }) 890 })
890 891
diff --git a/server/tests/api/videos/video-transcoder.ts b/server/tests/api/videos/video-transcoder.ts
index f9500d617..f88c59f0d 100644
--- a/server/tests/api/videos/video-transcoder.ts
+++ b/server/tests/api/videos/video-transcoder.ts
@@ -37,6 +37,7 @@ import {
37 getVideoFileFPS, 37 getVideoFileFPS,
38 getVideoFileResolution 38 getVideoFileResolution
39} from '../../../helpers/ffprobe-utils' 39} from '../../../helpers/ffprobe-utils'
40import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
40 41
41const expect = chai.expect 42const expect = chai.expect
42 43
@@ -280,7 +281,7 @@ describe('Test video transcoding', function () {
280 expect(videoToFindInList).to.be.undefined 281 expect(videoToFindInList).to.be.undefined
281 282
282 // Server 1 should not have the video yet 283 // Server 1 should not have the video yet
283 await getVideo(servers[0].url, videoId, 404) 284 await getVideo(servers[0].url, videoId, HttpStatusCode.NOT_FOUND_404)
284 } 285 }
285 286
286 await waitJobs(servers) 287 await waitJobs(servers)
@@ -400,8 +401,8 @@ describe('Test video transcoding', function () {
400 401
401 expect(videoDetails.files).to.have.lengthOf(1) 402 expect(videoDetails.files).to.have.lengthOf(1)
402 403
403 await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: 200 }) 404 await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: HttpStatusCode.OK_200 })
404 await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: 200 }) 405 await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: HttpStatusCode.OK_200 })
405 406
406 const magnetUri = videoDetails.files[0].magnetUri 407 const magnetUri = videoDetails.files[0].magnetUri
407 expect(magnetUri).to.contain('.mp4') 408 expect(magnetUri).to.contain('.mp4')
@@ -425,8 +426,8 @@ describe('Test video transcoding', function () {
425 426
426 expect(videoDetails.files).to.have.lengthOf(1) 427 expect(videoDetails.files).to.have.lengthOf(1)
427 428
428 await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: 200 }) 429 await makeGetRequest({ url: server.url, path: videoDetails.thumbnailPath, statusCodeExpected: HttpStatusCode.OK_200 })
429 await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: 200 }) 430 await makeGetRequest({ url: server.url, path: videoDetails.previewPath, statusCodeExpected: HttpStatusCode.OK_200 })
430 431
431 const magnetUri = videoDetails.files[0].magnetUri 432 const magnetUri = videoDetails.files[0].magnetUri
432 expect(magnetUri).to.contain('.mp4') 433 expect(magnetUri).to.contain('.mp4')
diff --git a/server/tests/api/videos/videos-filter.ts b/server/tests/api/videos/videos-filter.ts
index 6b9a4b6d4..2961c8e78 100644
--- a/server/tests/api/videos/videos-filter.ts
+++ b/server/tests/api/videos/videos-filter.ts
@@ -15,10 +15,11 @@ import {
15} from '../../../../shared/extra-utils' 15} from '../../../../shared/extra-utils'
16import { Video, VideoPrivacy } from '../../../../shared/models/videos' 16import { Video, VideoPrivacy } from '../../../../shared/models/videos'
17import { UserRole } from '../../../../shared/models/users' 17import { UserRole } from '../../../../shared/models/users'
18import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
18 19
19const expect = chai.expect 20const expect = chai.expect
20 21
21async function getVideosNames (server: ServerInfo, token: string, filter: string, statusCodeExpected = 200) { 22async function getVideosNames (server: ServerInfo, token: string, filter: string, statusCodeExpected = HttpStatusCode.OK_200) {
22 const paths = [ 23 const paths = [
23 '/api/v1/video-channels/root_channel/videos', 24 '/api/v1/video-channels/root_channel/videos',
24 '/api/v1/accounts/root/videos', 25 '/api/v1/accounts/root/videos',
diff --git a/server/tests/cli/prune-storage.ts b/server/tests/cli/prune-storage.ts
index 052a5f91e..591ed217f 100644
--- a/server/tests/cli/prune-storage.ts
+++ b/server/tests/cli/prune-storage.ts
@@ -24,6 +24,7 @@ import { Account, VideoPlaylistPrivacy } from '../../../shared/models'
24import { createFile, readdir } from 'fs-extra' 24import { createFile, readdir } from 'fs-extra'
25import { v4 as uuidv4 } from 'uuid' 25import { v4 as uuidv4 } from 'uuid'
26import { join } from 'path' 26import { join } from 'path'
27import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
27 28
28const expect = chai.expect 29const expect = chai.expect
29 30
@@ -98,7 +99,7 @@ describe('Test prune storage scripts', function () {
98 await makeGetRequest({ 99 await makeGetRequest({
99 url: servers[0].url, 100 url: servers[0].url,
100 path: account.avatar.path, 101 path: account.avatar.path,
101 statusCodeExpected: 200 102 statusCodeExpected: HttpStatusCode.OK_200
102 }) 103 })
103 } 104 }
104 105
@@ -108,7 +109,7 @@ describe('Test prune storage scripts', function () {
108 await makeGetRequest({ 109 await makeGetRequest({
109 url: servers[1].url, 110 url: servers[1].url,
110 path: account.avatar.path, 111 path: account.avatar.path,
111 statusCodeExpected: 200 112 statusCodeExpected: HttpStatusCode.OK_200
112 }) 113 })
113 } 114 }
114 115
diff --git a/server/tests/client.ts b/server/tests/client.ts
index 96821eb6f..6dd4b7cf6 100644
--- a/server/tests/client.ts
+++ b/server/tests/client.ts
@@ -22,6 +22,7 @@ import {
22 updateMyUser, 22 updateMyUser,
23 updateVideoChannel 23 updateVideoChannel
24} from '../../shared/extra-utils' 24} from '../../shared/extra-utils'
25import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
25 26
26const expect = chai.expect 27const expect = chai.expect
27 28
@@ -100,7 +101,7 @@ describe('Test a client controllers', function () {
100 const res = await request(server.url) 101 const res = await request(server.url)
101 .get(path) 102 .get(path)
102 .set('Accept', 'text/html') 103 .set('Accept', 'text/html')
103 .expect(200) 104 .expect(HttpStatusCode.OK_200)
104 105
105 const port = server.port 106 const port = server.port
106 107
@@ -115,7 +116,7 @@ describe('Test a client controllers', function () {
115 const res = await request(server.url) 116 const res = await request(server.url)
116 .get('/videos/watch/playlist/' + playlistUUID) 117 .get('/videos/watch/playlist/' + playlistUUID)
117 .set('Accept', 'text/html') 118 .set('Accept', 'text/html')
118 .expect(200) 119 .expect(HttpStatusCode.OK_200)
119 120
120 const port = server.port 121 const port = server.port
121 122
@@ -133,7 +134,7 @@ describe('Test a client controllers', function () {
133 const res = await request(server.url) 134 const res = await request(server.url)
134 .get('/accounts/' + server.user.username) 135 .get('/accounts/' + server.user.username)
135 .set('Accept', 'text/html') 136 .set('Accept', 'text/html')
136 .expect(200) 137 .expect(HttpStatusCode.OK_200)
137 138
138 expect(res.text).to.contain(`<meta property="og:title" content="${account.displayName}" />`) 139 expect(res.text).to.contain(`<meta property="og:title" content="${account.displayName}" />`)
139 expect(res.text).to.contain(`<meta property="og:description" content="${account.description}" />`) 140 expect(res.text).to.contain(`<meta property="og:description" content="${account.description}" />`)
@@ -145,7 +146,7 @@ describe('Test a client controllers', function () {
145 const res = await request(server.url) 146 const res = await request(server.url)
146 .get('/video-channels/' + server.videoChannel.name) 147 .get('/video-channels/' + server.videoChannel.name)
147 .set('Accept', 'text/html') 148 .set('Accept', 'text/html')
148 .expect(200) 149 .expect(HttpStatusCode.OK_200)
149 150
150 expect(res.text).to.contain(`<meta property="og:title" content="${server.videoChannel.displayName}" />`) 151 expect(res.text).to.contain(`<meta property="og:title" content="${server.videoChannel.displayName}" />`)
151 expect(res.text).to.contain(`<meta property="og:description" content="${channelDescription}" />`) 152 expect(res.text).to.contain(`<meta property="og:description" content="${channelDescription}" />`)
@@ -157,7 +158,7 @@ describe('Test a client controllers', function () {
157 const res = await request(server.url) 158 const res = await request(server.url)
158 .get('/videos/watch/' + server.video.id) 159 .get('/videos/watch/' + server.video.id)
159 .set('Accept', 'text/html') 160 .set('Accept', 'text/html')
160 .expect(200) 161 .expect(HttpStatusCode.OK_200)
161 162
162 expect(res.text).to.contain(`<meta property="og:title" content="${videoName}" />`) 163 expect(res.text).to.contain(`<meta property="og:title" content="${videoName}" />`)
163 expect(res.text).to.contain(`<meta property="og:description" content="${videoDescription}" />`) 164 expect(res.text).to.contain(`<meta property="og:description" content="${videoDescription}" />`)
@@ -169,7 +170,7 @@ describe('Test a client controllers', function () {
169 const res = await request(server.url) 170 const res = await request(server.url)
170 .get('/videos/watch/' + server.video.uuid) 171 .get('/videos/watch/' + server.video.uuid)
171 .set('Accept', 'text/html') 172 .set('Accept', 'text/html')
172 .expect(200) 173 .expect(HttpStatusCode.OK_200)
173 174
174 expect(res.text).to.contain(`<meta property="og:title" content="${videoName}" />`) 175 expect(res.text).to.contain(`<meta property="og:title" content="${videoName}" />`)
175 expect(res.text).to.contain(`<meta property="og:description" content="${videoDescription}" />`) 176 expect(res.text).to.contain(`<meta property="og:description" content="${videoDescription}" />`)
@@ -181,7 +182,7 @@ describe('Test a client controllers', function () {
181 const res = await request(server.url) 182 const res = await request(server.url)
182 .get('/videos/watch/playlist/' + playlistUUID) 183 .get('/videos/watch/playlist/' + playlistUUID)
183 .set('Accept', 'text/html') 184 .set('Accept', 'text/html')
184 .expect(200) 185 .expect(HttpStatusCode.OK_200)
185 186
186 expect(res.text).to.contain(`<meta property="og:title" content="${playlistName}" />`) 187 expect(res.text).to.contain(`<meta property="og:title" content="${playlistName}" />`)
187 expect(res.text).to.contain(`<meta property="og:description" content="${playlistDescription}" />`) 188 expect(res.text).to.contain(`<meta property="og:description" content="${playlistDescription}" />`)
@@ -196,7 +197,7 @@ describe('Test a client controllers', function () {
196 const res = await request(server.url) 197 const res = await request(server.url)
197 .get('/videos/watch/' + server.video.uuid) 198 .get('/videos/watch/' + server.video.uuid)
198 .set('Accept', 'text/html') 199 .set('Accept', 'text/html')
199 .expect(200) 200 .expect(HttpStatusCode.OK_200)
200 201
201 expect(res.text).to.contain('<meta property="twitter:card" content="summary_large_image" />') 202 expect(res.text).to.contain('<meta property="twitter:card" content="summary_large_image" />')
202 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') 203 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
@@ -208,7 +209,7 @@ describe('Test a client controllers', function () {
208 const res = await request(server.url) 209 const res = await request(server.url)
209 .get('/videos/watch/playlist/' + playlistUUID) 210 .get('/videos/watch/playlist/' + playlistUUID)
210 .set('Accept', 'text/html') 211 .set('Accept', 'text/html')
211 .expect(200) 212 .expect(HttpStatusCode.OK_200)
212 213
213 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />') 214 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />')
214 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') 215 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
@@ -220,7 +221,7 @@ describe('Test a client controllers', function () {
220 const res = await request(server.url) 221 const res = await request(server.url)
221 .get('/accounts/' + account.name) 222 .get('/accounts/' + account.name)
222 .set('Accept', 'text/html') 223 .set('Accept', 'text/html')
223 .expect(200) 224 .expect(HttpStatusCode.OK_200)
224 225
225 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />') 226 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />')
226 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') 227 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
@@ -232,7 +233,7 @@ describe('Test a client controllers', function () {
232 const res = await request(server.url) 233 const res = await request(server.url)
233 .get('/video-channels/' + server.videoChannel.name) 234 .get('/video-channels/' + server.videoChannel.name)
234 .set('Accept', 'text/html') 235 .set('Accept', 'text/html')
235 .expect(200) 236 .expect(HttpStatusCode.OK_200)
236 237
237 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />') 238 expect(res.text).to.contain('<meta property="twitter:card" content="summary" />')
238 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />') 239 expect(res.text).to.contain('<meta property="twitter:site" content="@Chocobozzz" />')
@@ -252,7 +253,7 @@ describe('Test a client controllers', function () {
252 const resVideoRequest = await request(server.url) 253 const resVideoRequest = await request(server.url)
253 .get('/videos/watch/' + server.video.uuid) 254 .get('/videos/watch/' + server.video.uuid)
254 .set('Accept', 'text/html') 255 .set('Accept', 'text/html')
255 .expect(200) 256 .expect(HttpStatusCode.OK_200)
256 257
257 expect(resVideoRequest.text).to.contain('<meta property="twitter:card" content="player" />') 258 expect(resVideoRequest.text).to.contain('<meta property="twitter:card" content="player" />')
258 expect(resVideoRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />') 259 expect(resVideoRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
@@ -260,7 +261,7 @@ describe('Test a client controllers', function () {
260 const resVideoPlaylistRequest = await request(server.url) 261 const resVideoPlaylistRequest = await request(server.url)
261 .get('/videos/watch/playlist/' + playlistUUID) 262 .get('/videos/watch/playlist/' + playlistUUID)
262 .set('Accept', 'text/html') 263 .set('Accept', 'text/html')
263 .expect(200) 264 .expect(HttpStatusCode.OK_200)
264 265
265 expect(resVideoPlaylistRequest.text).to.contain('<meta property="twitter:card" content="player" />') 266 expect(resVideoPlaylistRequest.text).to.contain('<meta property="twitter:card" content="player" />')
266 expect(resVideoPlaylistRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />') 267 expect(resVideoPlaylistRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
@@ -268,7 +269,7 @@ describe('Test a client controllers', function () {
268 const resAccountRequest = await request(server.url) 269 const resAccountRequest = await request(server.url)
269 .get('/accounts/' + account.name) 270 .get('/accounts/' + account.name)
270 .set('Accept', 'text/html') 271 .set('Accept', 'text/html')
271 .expect(200) 272 .expect(HttpStatusCode.OK_200)
272 273
273 expect(resAccountRequest.text).to.contain('<meta property="twitter:card" content="summary" />') 274 expect(resAccountRequest.text).to.contain('<meta property="twitter:card" content="summary" />')
274 expect(resAccountRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />') 275 expect(resAccountRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
@@ -276,7 +277,7 @@ describe('Test a client controllers', function () {
276 const resChannelRequest = await request(server.url) 277 const resChannelRequest = await request(server.url)
277 .get('/video-channels/' + server.videoChannel.name) 278 .get('/video-channels/' + server.videoChannel.name)
278 .set('Accept', 'text/html') 279 .set('Accept', 'text/html')
279 .expect(200) 280 .expect(HttpStatusCode.OK_200)
280 281
281 expect(resChannelRequest.text).to.contain('<meta property="twitter:card" content="summary" />') 282 expect(resChannelRequest.text).to.contain('<meta property="twitter:card" content="summary" />')
282 expect(resChannelRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />') 283 expect(resChannelRequest.text).to.contain('<meta property="twitter:site" content="@Kuja" />')
diff --git a/server/tests/external-plugins/auto-mute.ts b/server/tests/external-plugins/auto-mute.ts
index 8ead34a2b..687f56e98 100644
--- a/server/tests/external-plugins/auto-mute.ts
+++ b/server/tests/external-plugins/auto-mute.ts
@@ -25,6 +25,7 @@ import {
25 reRunServer, 25 reRunServer,
26 ServerInfo 26 ServerInfo
27} from '../../../shared/extra-utils/server/servers' 27} from '../../../shared/extra-utils/server/servers'
28import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
28 29
29describe('Official plugin auto-mute', function () { 30describe('Official plugin auto-mute', function () {
30 const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list' 31 const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list'
@@ -178,7 +179,7 @@ describe('Official plugin auto-mute', function () {
178 await makeGetRequest({ 179 await makeGetRequest({
179 url: servers[0].url, 180 url: servers[0].url,
180 path: '/plugins/auto-mute/router/api/v1/mute-list', 181 path: '/plugins/auto-mute/router/api/v1/mute-list',
181 statusCodeExpected: 403 182 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
182 }) 183 })
183 }) 184 })
184 185
@@ -197,7 +198,7 @@ describe('Official plugin auto-mute', function () {
197 await makeGetRequest({ 198 await makeGetRequest({
198 url: servers[0].url, 199 url: servers[0].url,
199 path: '/plugins/auto-mute/router/api/v1/mute-list', 200 path: '/plugins/auto-mute/router/api/v1/mute-list',
200 statusCodeExpected: 200 201 statusCodeExpected: HttpStatusCode.OK_200
201 }) 202 })
202 }) 203 })
203 204
@@ -221,7 +222,7 @@ describe('Official plugin auto-mute', function () {
221 const res = await makeGetRequest({ 222 const res = await makeGetRequest({
222 url: servers[0].url, 223 url: servers[0].url,
223 path: '/plugins/auto-mute/router/api/v1/mute-list', 224 path: '/plugins/auto-mute/router/api/v1/mute-list',
224 statusCodeExpected: 200 225 statusCodeExpected: HttpStatusCode.OK_200
225 }) 226 })
226 227
227 const data = res.body.data 228 const data = res.body.data
diff --git a/server/tests/misc-endpoints.ts b/server/tests/misc-endpoints.ts
index 3d0224323..698d83328 100644
--- a/server/tests/misc-endpoints.ts
+++ b/server/tests/misc-endpoints.ts
@@ -13,6 +13,7 @@ import {
13 uploadVideo 13 uploadVideo
14} from '../../shared/extra-utils' 14} from '../../shared/extra-utils'
15import { VideoPrivacy } from '../../shared/models/videos' 15import { VideoPrivacy } from '../../shared/models/videos'
16import { HttpStatusCode } from '@shared/core-utils'
16 17
17const expect = chai.expect 18const expect = chai.expect
18 19
@@ -32,7 +33,7 @@ describe('Test misc endpoints', function () {
32 const res = await makeGetRequest({ 33 const res = await makeGetRequest({
33 url: server.url, 34 url: server.url,
34 path: '/.well-known/security.txt', 35 path: '/.well-known/security.txt',
35 statusCodeExpected: 200 36 statusCodeExpected: HttpStatusCode.OK_200
36 }) 37 })
37 38
38 expect(res.text).to.contain('security issue') 39 expect(res.text).to.contain('security issue')
@@ -42,7 +43,7 @@ describe('Test misc endpoints', function () {
42 const res = await makeGetRequest({ 43 const res = await makeGetRequest({
43 url: server.url, 44 url: server.url,
44 path: '/.well-known/nodeinfo', 45 path: '/.well-known/nodeinfo',
45 statusCodeExpected: 200 46 statusCodeExpected: HttpStatusCode.OK_200
46 }) 47 })
47 48
48 expect(res.body.links).to.be.an('array') 49 expect(res.body.links).to.be.an('array')
@@ -54,7 +55,7 @@ describe('Test misc endpoints', function () {
54 const res = await makeGetRequest({ 55 const res = await makeGetRequest({
55 url: server.url, 56 url: server.url,
56 path: '/.well-known/dnt-policy.txt', 57 path: '/.well-known/dnt-policy.txt',
57 statusCodeExpected: 200 58 statusCodeExpected: HttpStatusCode.OK_200
58 }) 59 })
59 60
60 expect(res.text).to.contain('http://www.w3.org/TR/tracking-dnt') 61 expect(res.text).to.contain('http://www.w3.org/TR/tracking-dnt')
@@ -64,7 +65,7 @@ describe('Test misc endpoints', function () {
64 const res = await makeGetRequest({ 65 const res = await makeGetRequest({
65 url: server.url, 66 url: server.url,
66 path: '/.well-known/dnt', 67 path: '/.well-known/dnt',
67 statusCodeExpected: 200 68 statusCodeExpected: HttpStatusCode.OK_200
68 }) 69 })
69 70
70 expect(res.body.tracking).to.equal('N') 71 expect(res.body.tracking).to.equal('N')
@@ -74,7 +75,7 @@ describe('Test misc endpoints', function () {
74 const res = await makeGetRequest({ 75 const res = await makeGetRequest({
75 url: server.url, 76 url: server.url,
76 path: '/.well-known/change-password', 77 path: '/.well-known/change-password',
77 statusCodeExpected: 302 78 statusCodeExpected: HttpStatusCode.FOUND_302
78 }) 79 })
79 80
80 expect(res.header.location).to.equal('/my-account/settings') 81 expect(res.header.location).to.equal('/my-account/settings')
@@ -87,7 +88,7 @@ describe('Test misc endpoints', function () {
87 const res = await makeGetRequest({ 88 const res = await makeGetRequest({
88 url: server.url, 89 url: server.url,
89 path: '/robots.txt', 90 path: '/robots.txt',
90 statusCodeExpected: 200 91 statusCodeExpected: HttpStatusCode.OK_200
91 }) 92 })
92 93
93 expect(res.text).to.contain('User-agent') 94 expect(res.text).to.contain('User-agent')
@@ -97,7 +98,7 @@ describe('Test misc endpoints', function () {
97 await makeGetRequest({ 98 await makeGetRequest({
98 url: server.url, 99 url: server.url,
99 path: '/security.txt', 100 path: '/security.txt',
100 statusCodeExpected: 301 101 statusCodeExpected: HttpStatusCode.MOVED_PERMANENTLY_301
101 }) 102 })
102 }) 103 })
103 104
@@ -105,7 +106,7 @@ describe('Test misc endpoints', function () {
105 const res = await makeGetRequest({ 106 const res = await makeGetRequest({
106 url: server.url, 107 url: server.url,
107 path: '/nodeinfo/2.0.json', 108 path: '/nodeinfo/2.0.json',
108 statusCodeExpected: 200 109 statusCodeExpected: HttpStatusCode.OK_200
109 }) 110 })
110 111
111 expect(res.body.software.name).to.equal('peertube') 112 expect(res.body.software.name).to.equal('peertube')
@@ -118,7 +119,7 @@ describe('Test misc endpoints', function () {
118 const res = await makeGetRequest({ 119 const res = await makeGetRequest({
119 url: server.url, 120 url: server.url,
120 path: '/sitemap.xml', 121 path: '/sitemap.xml',
121 statusCodeExpected: 200 122 statusCodeExpected: HttpStatusCode.OK_200
122 }) 123 })
123 124
124 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"') 125 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
@@ -129,7 +130,7 @@ describe('Test misc endpoints', function () {
129 const res = await makeGetRequest({ 130 const res = await makeGetRequest({
130 url: server.url, 131 url: server.url,
131 path: '/sitemap.xml', 132 path: '/sitemap.xml',
132 statusCodeExpected: 200 133 statusCodeExpected: HttpStatusCode.OK_200
133 }) 134 })
134 135
135 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"') 136 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
@@ -152,7 +153,7 @@ describe('Test misc endpoints', function () {
152 const res = await makeGetRequest({ 153 const res = await makeGetRequest({
153 url: server.url, 154 url: server.url,
154 path: '/sitemap.xml?t=1', // avoid using cache 155 path: '/sitemap.xml?t=1', // avoid using cache
155 statusCodeExpected: 200 156 statusCodeExpected: HttpStatusCode.OK_200
156 }) 157 })
157 158
158 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"') 159 expect(res.text).to.contain('xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"')
diff --git a/server/tests/plugins/external-auth.ts b/server/tests/plugins/external-auth.ts
index 6d907cc51..a1b5e8f5d 100644
--- a/server/tests/plugins/external-auth.ts
+++ b/server/tests/plugins/external-auth.ts
@@ -22,6 +22,7 @@ import {
22 createUser 22 createUser
23} from '../../../shared/extra-utils' 23} from '../../../shared/extra-utils'
24import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers' 24import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers'
25import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
25 26
26async function loginExternal (options: { 27async function loginExternal (options: {
27 server: ServerInfo 28 server: ServerInfo
@@ -29,8 +30,8 @@ async function loginExternal (options: {
29 authName: string 30 authName: string
30 username: string 31 username: string
31 query?: any 32 query?: any
32 statusCodeExpected?: number 33 statusCodeExpected?: HttpStatusCode
33 statusCodeExpectedStep2?: number 34 statusCodeExpectedStep2?: HttpStatusCode
34}) { 35}) {
35 const res = await getExternalAuth({ 36 const res = await getExternalAuth({
36 url: options.server.url, 37 url: options.server.url,
@@ -38,10 +39,10 @@ async function loginExternal (options: {
38 npmVersion: '0.0.1', 39 npmVersion: '0.0.1',
39 authName: options.authName, 40 authName: options.authName,
40 query: options.query, 41 query: options.query,
41 statusCodeExpected: options.statusCodeExpected || 302 42 statusCodeExpected: options.statusCodeExpected || HttpStatusCode.FOUND_302
42 }) 43 })
43 44
44 if (res.status !== 302) return 45 if (res.status !== HttpStatusCode.FOUND_302) return
45 46
46 const location = res.header.location 47 const location = res.header.location
47 const { externalAuthToken } = decodeQueryString(location) 48 const { externalAuthToken } = decodeQueryString(location)
@@ -105,7 +106,7 @@ describe('Test external auth plugins', function () {
105 query: { 106 query: {
106 username: 'cyan' 107 username: 'cyan'
107 }, 108 },
108 statusCodeExpected: 302 109 statusCodeExpected: HttpStatusCode.FOUND_302
109 }) 110 })
110 111
111 const location = res.header.location 112 const location = res.header.location
@@ -120,13 +121,13 @@ describe('Test external auth plugins', function () {
120 }) 121 })
121 122
122 it('Should reject auto external login with a missing or invalid token', async function () { 123 it('Should reject auto external login with a missing or invalid token', async function () {
123 await loginUsingExternalToken(server, 'cyan', '', 400) 124 await loginUsingExternalToken(server, 'cyan', '', HttpStatusCode.BAD_REQUEST_400)
124 await loginUsingExternalToken(server, 'cyan', 'blabla', 400) 125 await loginUsingExternalToken(server, 'cyan', 'blabla', HttpStatusCode.BAD_REQUEST_400)
125 }) 126 })
126 127
127 it('Should reject auto external login with a missing or invalid username', async function () { 128 it('Should reject auto external login with a missing or invalid username', async function () {
128 await loginUsingExternalToken(server, '', externalAuthToken, 400) 129 await loginUsingExternalToken(server, '', externalAuthToken, HttpStatusCode.BAD_REQUEST_400)
129 await loginUsingExternalToken(server, '', externalAuthToken, 400) 130 await loginUsingExternalToken(server, '', externalAuthToken, HttpStatusCode.BAD_REQUEST_400)
130 }) 131 })
131 132
132 it('Should reject auto external login with an expired token', async function () { 133 it('Should reject auto external login with an expired token', async function () {
@@ -134,7 +135,7 @@ describe('Test external auth plugins', function () {
134 135
135 await wait(5000) 136 await wait(5000)
136 137
137 await loginUsingExternalToken(server, 'cyan', externalAuthToken, 400) 138 await loginUsingExternalToken(server, 'cyan', externalAuthToken, HttpStatusCode.BAD_REQUEST_400)
138 139
139 await waitUntilLog(server, 'expired external auth token') 140 await waitUntilLog(server, 'expired external auth token')
140 }) 141 })
@@ -202,7 +203,7 @@ describe('Test external auth plugins', function () {
202 } 203 }
203 204
204 { 205 {
205 await refreshToken(server, kefkaRefreshToken, 400) 206 await refreshToken(server, kefkaRefreshToken, HttpStatusCode.BAD_REQUEST_400)
206 } 207 }
207 }) 208 })
208 209
@@ -228,7 +229,7 @@ describe('Test external auth plugins', function () {
228 it('Should have logged out Cyan', async function () { 229 it('Should have logged out Cyan', async function () {
229 await waitUntilLog(server, 'On logout cyan') 230 await waitUntilLog(server, 'On logout cyan')
230 231
231 await getMyUserInformation(server.url, cyanAccessToken, 401) 232 await getMyUserInformation(server.url, cyanAccessToken, HttpStatusCode.UNAUTHORIZED_401)
232 }) 233 })
233 234
234 it('Should login Cyan and keep the old existing profile', async function () { 235 it('Should login Cyan and keep the old existing profile', async function () {
@@ -261,7 +262,7 @@ describe('Test external auth plugins', function () {
261 accessToken: cyanAccessToken, 262 accessToken: cyanAccessToken,
262 email: 'toto@example.com', 263 email: 'toto@example.com',
263 currentPassword: 'toto', 264 currentPassword: 'toto',
264 statusCodeExpected: 400 265 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
265 }) 266 })
266 }) 267 })
267 268
@@ -270,7 +271,7 @@ describe('Test external auth plugins', function () {
270 271
271 await wait(5000) 272 await wait(5000)
272 273
273 await getMyUserInformation(server.url, kefkaAccessToken, 401) 274 await getMyUserInformation(server.url, kefkaAccessToken, HttpStatusCode.UNAUTHORIZED_401)
274 }) 275 })
275 276
276 it('Should unregister external-auth-2 and do not login existing Kefka', async function () { 277 it('Should unregister external-auth-2 and do not login existing Kefka', async function () {
@@ -281,7 +282,7 @@ describe('Test external auth plugins', function () {
281 settings: { disableKefka: true } 282 settings: { disableKefka: true }
282 }) 283 })
283 284
284 await userLogin(server, { username: 'kefka', password: 'fake' }, 400) 285 await userLogin(server, { username: 'kefka', password: 'fake' }, HttpStatusCode.BAD_REQUEST_400)
285 286
286 await loginExternal({ 287 await loginExternal({
287 server, 288 server,
@@ -291,7 +292,7 @@ describe('Test external auth plugins', function () {
291 username: 'kefka' 292 username: 'kefka'
292 }, 293 },
293 username: 'kefka', 294 username: 'kefka',
294 statusCodeExpected: 404 295 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
295 }) 296 })
296 }) 297 })
297 298
@@ -322,12 +323,12 @@ describe('Test external auth plugins', function () {
322 username: 'cyan' 323 username: 'cyan'
323 }, 324 },
324 username: 'cyan', 325 username: 'cyan',
325 statusCodeExpected: 404 326 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
326 }) 327 })
327 328
328 await userLogin(server, { username: 'cyan', password: null }, 400) 329 await userLogin(server, { username: 'cyan', password: null }, HttpStatusCode.BAD_REQUEST_400)
329 await userLogin(server, { username: 'cyan', password: '' }, 400) 330 await userLogin(server, { username: 'cyan', password: '' }, HttpStatusCode.BAD_REQUEST_400)
330 await userLogin(server, { username: 'cyan', password: 'fake' }, 400) 331 await userLogin(server, { username: 'cyan', password: 'fake' }, HttpStatusCode.BAD_REQUEST_400)
331 }) 332 })
332 333
333 it('Should not login kefka with another plugin', async function () { 334 it('Should not login kefka with another plugin', async function () {
@@ -336,7 +337,7 @@ describe('Test external auth plugins', function () {
336 npmName: 'test-external-auth-two', 337 npmName: 'test-external-auth-two',
337 authName: 'external-auth-4', 338 authName: 'external-auth-4',
338 username: 'kefka2', 339 username: 'kefka2',
339 statusCodeExpectedStep2: 400 340 statusCodeExpectedStep2: HttpStatusCode.BAD_REQUEST_400
340 }) 341 })
341 342
342 await loginExternal({ 343 await loginExternal({
@@ -344,7 +345,7 @@ describe('Test external auth plugins', function () {
344 npmName: 'test-external-auth-two', 345 npmName: 'test-external-auth-two',
345 authName: 'external-auth-4', 346 authName: 'external-auth-4',
346 username: 'kefka', 347 username: 'kefka',
347 statusCodeExpectedStep2: 400 348 statusCodeExpectedStep2: HttpStatusCode.BAD_REQUEST_400
348 }) 349 })
349 }) 350 })
350 351
@@ -361,7 +362,7 @@ describe('Test external auth plugins', function () {
361 npmName: 'test-external-auth-two', 362 npmName: 'test-external-auth-two',
362 authName: 'external-auth-6', 363 authName: 'external-auth-6',
363 username: 'existing_user', 364 username: 'existing_user',
364 statusCodeExpectedStep2: 400 365 statusCodeExpectedStep2: HttpStatusCode.BAD_REQUEST_400
365 }) 366 })
366 }) 367 })
367 368
diff --git a/server/tests/plugins/plugin-helpers.ts b/server/tests/plugins/plugin-helpers.ts
index e76d7917a..c0d95e1e0 100644
--- a/server/tests/plugins/plugin-helpers.ts
+++ b/server/tests/plugins/plugin-helpers.ts
@@ -16,6 +16,7 @@ import {
16} from '../../../shared/extra-utils' 16} from '../../../shared/extra-utils'
17import { cleanupTests, flushAndRunMultipleServers, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers' 17import { cleanupTests, flushAndRunMultipleServers, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers'
18import { expect } from 'chai' 18import { expect } from 'chai'
19import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
19 20
20function postCommand (server: ServerInfo, command: string, bodyArg?: object) { 21function postCommand (server: ServerInfo, command: string, bodyArg?: object) {
21 const body = { command } 22 const body = { command }
@@ -25,7 +26,7 @@ function postCommand (server: ServerInfo, command: string, bodyArg?: object) {
25 url: server.url, 26 url: server.url,
26 path: '/plugins/test-four/router/commander', 27 path: '/plugins/test-four/router/commander',
27 fields: body, 28 fields: body,
28 statusCodeExpected: 204 29 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
29 }) 30 })
30} 31}
31 32
diff --git a/server/tests/plugins/plugin-router.ts b/server/tests/plugins/plugin-router.ts
index cf4130f4b..9e78568cd 100644
--- a/server/tests/plugins/plugin-router.ts
+++ b/server/tests/plugins/plugin-router.ts
@@ -10,6 +10,7 @@ import {
10 setAccessTokensToServers, uninstallPlugin 10 setAccessTokensToServers, uninstallPlugin
11} from '../../../shared/extra-utils' 11} from '../../../shared/extra-utils'
12import { expect } from 'chai' 12import { expect } from 'chai'
13import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
13 14
14describe('Test plugin helpers', function () { 15describe('Test plugin helpers', function () {
15 let server: ServerInfo 16 let server: ServerInfo
@@ -36,7 +37,7 @@ describe('Test plugin helpers', function () {
36 const res = await makeGetRequest({ 37 const res = await makeGetRequest({
37 url: server.url, 38 url: server.url,
38 path: path + 'ping', 39 path: path + 'ping',
39 statusCodeExpected: 200 40 statusCodeExpected: HttpStatusCode.OK_200
40 }) 41 })
41 42
42 expect(res.body.message).to.equal('pong') 43 expect(res.body.message).to.equal('pong')
@@ -55,7 +56,7 @@ describe('Test plugin helpers', function () {
55 url: server.url, 56 url: server.url,
56 path: path + 'form/post/mirror', 57 path: path + 'form/post/mirror',
57 fields: body, 58 fields: body,
58 statusCodeExpected: 200 59 statusCodeExpected: HttpStatusCode.OK_200
59 }) 60 })
60 61
61 expect(res.body).to.deep.equal(body) 62 expect(res.body).to.deep.equal(body)
@@ -73,14 +74,14 @@ describe('Test plugin helpers', function () {
73 await makeGetRequest({ 74 await makeGetRequest({
74 url: server.url, 75 url: server.url,
75 path: path + 'ping', 76 path: path + 'ping',
76 statusCodeExpected: 404 77 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
77 }) 78 })
78 79
79 await makePostBodyRequest({ 80 await makePostBodyRequest({
80 url: server.url, 81 url: server.url,
81 path: path + 'ping', 82 path: path + 'ping',
82 fields: {}, 83 fields: {},
83 statusCodeExpected: 404 84 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
84 }) 85 })
85 } 86 }
86 }) 87 })