]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/check-params/videos.ts
Merge branch 'release/3.1.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / videos.ts
index 0d4665954cdc35ed3c27decffac7a89a2e99a5d8..188d1835c17446ce4e83c3bd2767b0da818c2d34 100644 (file)
@@ -28,6 +28,7 @@ import {
   checkBadSortPagination,
   checkBadStartPagination
 } from '../../../../shared/extra-utils/requests/check-api-params'
+import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
 
 const expect = chai.expect
 
@@ -76,11 +77,11 @@ describe('Test videos API validator', function () {
     })
 
     it('Should fail with a bad skipVideos query', async function () {
-      await makeGetRequest({ url: server.url, path, statusCodeExpected: 200, query: { skipCount: 'toto' } })
+      await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200, query: { skipCount: 'toto' } })
     })
 
     it('Should success with the correct parameters', async function () {
-      await makeGetRequest({ url: server.url, path, statusCodeExpected: 200, query: { skipCount: false } })
+      await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200, query: { skipCount: false } })
     })
   })
 
@@ -90,7 +91,7 @@ describe('Test videos API validator', function () {
       await makeGetRequest({
         url: server.url,
         path: join(path, 'search'),
-        statusCodeExpected: 400
+        statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
       })
     })
 
@@ -107,7 +108,7 @@ describe('Test videos API validator', function () {
     })
 
     it('Should success with the correct parameters', async function () {
-      await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
+      await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 })
     })
   })
 
@@ -127,7 +128,7 @@ describe('Test videos API validator', function () {
     })
 
     it('Should success with the correct parameters', async function () {
-      await makeGetRequest({ url: server.url, token: server.accessToken, path, statusCodeExpected: 200 })
+      await makeGetRequest({ url: server.url, token: server.accessToken, path, statusCodeExpected: HttpStatusCode.OK_200 })
     })
   })
 
@@ -151,7 +152,7 @@ describe('Test videos API validator', function () {
     })
 
     it('Should success with the correct parameters', async function () {
-      await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
+      await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 })
     })
   })
 
@@ -175,7 +176,7 @@ describe('Test videos API validator', function () {
     })
 
     it('Should success with the correct parameters', async function () {
-      await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
+      await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 })
     })
   })
 
@@ -347,18 +348,32 @@ describe('Test videos API validator', function () {
       let attaches = {
         videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short_fake.webm')
       }
-      await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
+      await makeUploadRequest({
+        url: server.url,
+        path: path + '/upload',
+        token: server.accessToken,
+        fields,
+        attaches,
+        statusCodeExpected: HttpStatusCode.UNPROCESSABLE_ENTITY_422
+      })
 
       attaches = {
         videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mkv')
       }
-      await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
+      await makeUploadRequest({
+        url: server.url,
+        path: path + '/upload',
+        token: server.accessToken,
+        fields,
+        attaches,
+        statusCodeExpected: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415
+      })
     })
 
     it('Should fail with an incorrect thumbnail file', async function () {
       const fields = baseCorrectParams
       const attaches = {
-        thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'avatar.png'),
+        thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4'),
         videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
       }
 
@@ -368,7 +383,7 @@ describe('Test videos API validator', function () {
     it('Should fail with a big thumbnail file', async function () {
       const fields = baseCorrectParams
       const attaches = {
-        thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png'),
+        thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png'),
         videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
       }
 
@@ -378,7 +393,7 @@ describe('Test videos API validator', function () {
     it('Should fail with an incorrect preview file', async function () {
       const fields = baseCorrectParams
       const attaches = {
-        previewfile: join(root(), 'server', 'tests', 'fixtures', 'avatar.png'),
+        previewfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4'),
         videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
       }
 
@@ -388,7 +403,7 @@ describe('Test videos API validator', function () {
     it('Should fail with a big preview file', async function () {
       const fields = baseCorrectParams
       const attaches = {
-        previewfile: join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png'),
+        previewfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png'),
         videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
       }
 
@@ -408,7 +423,7 @@ describe('Test videos API validator', function () {
           token: server.accessToken,
           fields,
           attaches,
-          statusCodeExpected: 200
+          statusCodeExpected: HttpStatusCode.OK_200
         })
       }
 
@@ -423,7 +438,7 @@ describe('Test videos API validator', function () {
           token: server.accessToken,
           fields,
           attaches,
-          statusCodeExpected: 200
+          statusCodeExpected: HttpStatusCode.OK_200
         })
       }
 
@@ -438,7 +453,7 @@ describe('Test videos API validator', function () {
           token: server.accessToken,
           fields,
           attaches,
-          statusCodeExpected: 200
+          statusCodeExpected: HttpStatusCode.OK_200
         })
       }
     })
@@ -481,7 +496,7 @@ describe('Test videos API validator', function () {
         path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
         token: server.accessToken,
         fields,
-        statusCodeExpected: 404
+        statusCodeExpected: HttpStatusCode.NOT_FOUND_404
       })
     })
 
@@ -566,7 +581,7 @@ describe('Test videos API validator', function () {
     it('Should fail with an incorrect thumbnail file', async function () {
       const fields = baseCorrectParams
       const attaches = {
-        thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'avatar.png')
+        thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
       }
 
       await makeUploadRequest({
@@ -582,7 +597,7 @@ describe('Test videos API validator', function () {
     it('Should fail with a big thumbnail file', async function () {
       const fields = baseCorrectParams
       const attaches = {
-        thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png')
+        thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png')
       }
 
       await makeUploadRequest({
@@ -598,7 +613,7 @@ describe('Test videos API validator', function () {
     it('Should fail with an incorrect preview file', async function () {
       const fields = baseCorrectParams
       const attaches = {
-        previewfile: join(root(), 'server', 'tests', 'fixtures', 'avatar.png')
+        previewfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
       }
 
       await makeUploadRequest({
@@ -614,7 +629,7 @@ describe('Test videos API validator', function () {
     it('Should fail with a big preview file', async function () {
       const fields = baseCorrectParams
       const attaches = {
-        previewfile: join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png')
+        previewfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png')
       }
 
       await makeUploadRequest({
@@ -630,7 +645,13 @@ describe('Test videos API validator', function () {
     it('Should fail with a video of another user without the appropriate right', async function () {
       const fields = baseCorrectParams
 
-      await makePutBodyRequest({ url: server.url, path: path + videoId, token: userAccessToken, fields, statusCodeExpected: 403 })
+      await makePutBodyRequest({
+        url: server.url,
+        path: path + videoId,
+        token: userAccessToken,
+        fields,
+        statusCodeExpected: HttpStatusCode.FORBIDDEN_403
+      })
     })
 
     it('Should fail with a video of another server')
@@ -638,7 +659,13 @@ describe('Test videos API validator', function () {
     it('Should succeed with the correct parameters', async function () {
       const fields = baseCorrectParams
 
-      await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields, statusCodeExpected: 204 })
+      await makePutBodyRequest({
+        url: server.url,
+        path: path + videoId,
+        token: server.accessToken,
+        fields,
+        statusCodeExpected: HttpStatusCode.NO_CONTENT_204
+      })
     })
   })
 
@@ -647,7 +674,7 @@ describe('Test videos API validator', function () {
       const res = await makeGetRequest({
         url: server.url,
         path,
-        statusCodeExpected: 200
+        statusCodeExpected: HttpStatusCode.OK_200
       })
 
       expect(res.body.data).to.be.an('array')
@@ -655,11 +682,11 @@ describe('Test videos API validator', function () {
     })
 
     it('Should fail without a correct uuid', async function () {
-      await getVideo(server.url, 'coucou', 400)
+      await getVideo(server.url, 'coucou', HttpStatusCode.BAD_REQUEST_400)
     })
 
     it('Should return 404 with an incorrect video', async function () {
-      await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
+      await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404)
     })
 
     it('Should succeed with the correct parameters', async function () {
@@ -691,7 +718,7 @@ describe('Test videos API validator', function () {
         path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
         token: server.accessToken,
         fields,
-        statusCodeExpected: 404
+        statusCodeExpected: HttpStatusCode.NOT_FOUND_404
       })
     })
 
@@ -711,7 +738,7 @@ describe('Test videos API validator', function () {
         path: path + videoId + '/rate',
         token: server.accessToken,
         fields,
-        statusCodeExpected: 204
+        statusCodeExpected: HttpStatusCode.NO_CONTENT_204
       })
     })
   })
@@ -721,20 +748,20 @@ describe('Test videos API validator', function () {
       await makeDeleteRequest({
         url: server.url,
         path,
-        statusCodeExpected: 400
+        statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
       })
     })
 
     it('Should fail without a correct uuid', async function () {
-      await removeVideo(server.url, server.accessToken, 'hello', 400)
+      await removeVideo(server.url, server.accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400)
     })
 
     it('Should fail with a video which does not exist', async function () {
-      await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
+      await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404)
     })
 
     it('Should fail with a video of another user without the appropriate right', async function () {
-      await removeVideo(server.url, userAccessToken, videoId, 403)
+      await removeVideo(server.url, userAccessToken, videoId, HttpStatusCode.FORBIDDEN_403)
     })
 
     it('Should fail with a video of another server')