]> 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 51e592a15ca29967c2df0578cce69149a230ae1f..188d1835c17446ce4e83c3bd2767b0da818c2d34 100644 (file)
@@ -1,4 +1,4 @@
-/* tslint:disable:no-unused-expression */
+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
 import * as chai from 'chai'
 import { omit } from 'lodash'
@@ -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
 
@@ -56,13 +57,13 @@ describe('Test videos API validator', function () {
 
     {
       const res = await getMyUserInformation(server.url, server.accessToken)
-      channelId = res.body.videoChannels[ 0 ].id
-      channelName = res.body.videoChannels[ 0 ].name
+      channelId = res.body.videoChannels[0].id
+      channelName = res.body.videoChannels[0].name
       accountName = res.body.account.name + '@' + res.body.account.host
     }
   })
 
-  describe('When listing a video', function () {
+  describe('When listing videos', function () {
     it('Should fail with a bad start pagination', async function () {
       await checkBadStartPagination(server.url, path)
     })
@@ -75,8 +76,12 @@ describe('Test videos API validator', function () {
       await checkBadSortPagination(server.url, path)
     })
 
+    it('Should fail with a bad skipVideos query', async function () {
+      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 })
+      await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200, query: { skipCount: false } })
     })
   })
 
@@ -86,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
       })
     })
 
@@ -103,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 })
     })
   })
 
@@ -123,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 })
     })
   })
 
@@ -147,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 })
     })
   })
 
@@ -171,14 +176,14 @@ 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 })
     })
   })
 
   describe('When adding a video', function () {
     let baseCorrectParams
     const baseCorrectAttaches = {
-      'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.webm')
+      videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.webm')
     }
 
     before(function () {
@@ -326,7 +331,7 @@ describe('Test videos API validator', function () {
     })
 
     it('Should fail with a bad originally published at attribute', async function () {
-      const fields = immutableAssign(baseCorrectParams, { 'originallyPublishedAt': 'toto' })
+      const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' })
       const attaches = baseCorrectAttaches
 
       await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
@@ -341,21 +346,35 @@ describe('Test videos API validator', function () {
     it('Should fail with an incorrect input file', async function () {
       const fields = baseCorrectParams
       let attaches = {
-        'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short_fake.webm')
+        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')
+        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'),
-        'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
+        thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4'),
+        videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
       }
 
       await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
@@ -364,8 +383,8 @@ 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'),
-        'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
+        thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png'),
+        videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
       }
 
       await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
@@ -374,8 +393,8 @@ 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'),
-        'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
+        previewfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4'),
+        videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
       }
 
       await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
@@ -384,8 +403,8 @@ 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'),
-        'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
+        previewfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png'),
+        videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
       }
 
       await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
@@ -404,7 +423,7 @@ describe('Test videos API validator', function () {
           token: server.accessToken,
           fields,
           attaches,
-          statusCodeExpected: 200
+          statusCodeExpected: HttpStatusCode.OK_200
         })
       }
 
@@ -419,7 +438,7 @@ describe('Test videos API validator', function () {
           token: server.accessToken,
           fields,
           attaches,
-          statusCodeExpected: 200
+          statusCodeExpected: HttpStatusCode.OK_200
         })
       }
 
@@ -434,7 +453,7 @@ describe('Test videos API validator', function () {
           token: server.accessToken,
           fields,
           attaches,
-          statusCodeExpected: 200
+          statusCodeExpected: HttpStatusCode.OK_200
         })
       }
     })
@@ -477,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
       })
     })
 
@@ -562,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({
@@ -578,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({
@@ -594,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({
@@ -610,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({
@@ -626,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')
@@ -634,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
+      })
     })
   })
 
@@ -643,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')
@@ -651,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 () {
@@ -687,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
       })
     })
 
@@ -707,7 +738,7 @@ describe('Test videos API validator', function () {
         path: path + videoId + '/rate',
         token: server.accessToken,
         fields,
-        statusCodeExpected: 204
+        statusCodeExpected: HttpStatusCode.NO_CONTENT_204
       })
     })
   })
@@ -717,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')