]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/check-params/video-imports.ts
Add ability to search playlists
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / video-imports.ts
index f954ba0898095ca33a3657df127f1c219a7cbe9e..a27b624d0fde8ec09137d66758f2986658b39e1f 100644 (file)
@@ -2,8 +2,9 @@
 
 import 'mocha'
 import { omit } from 'lodash'
-import { join } from 'path'
+import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
 import {
+  buildAbsoluteFixturePath,
   cleanupTests,
   createUser,
   flushAndRunServer,
@@ -22,7 +23,7 @@ import {
   checkBadSortPagination,
   checkBadStartPagination
 } from '../../../../shared/extra-utils/requests/check-api-params'
-import { getMagnetURI, getGoodVideoUrl } from '../../../../shared/extra-utils/videos/video-imports'
+import { getGoodVideoUrl, getMagnetURI } from '../../../../shared/extra-utils/videos/video-imports'
 import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
 
 describe('Test video imports API validator', function () {
@@ -67,7 +68,7 @@ describe('Test video imports API validator', function () {
     })
 
     it('Should success with the correct parameters', async function () {
-      await makeGetRequest({ url: server.url, path: myPath, statusCodeExpected: 200, token: server.accessToken })
+      await makeGetRequest({ url: server.url, path: myPath, statusCodeExpected: HttpStatusCode.OK_200, token: server.accessToken })
     })
   })
 
@@ -100,7 +101,13 @@ describe('Test video imports API validator', function () {
 
     it('Should fail without a target url', async function () {
       const fields = omit(baseCorrectParams, 'targetUrl')
-      await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 400 })
+      await makePostBodyRequest({
+        url: server.url,
+        path,
+        token: server.accessToken,
+        fields,
+        statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
+      })
     })
 
     it('Should fail with a bad target url', async function () {
@@ -194,7 +201,7 @@ describe('Test video imports API validator', function () {
     it('Should fail with an incorrect thumbnail file', async function () {
       const fields = baseCorrectParams
       const attaches = {
-        thumbnailfile: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
+        thumbnailfile: buildAbsoluteFixturePath('video_short.mp4')
       }
 
       await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
@@ -203,7 +210,7 @@ describe('Test video imports API validator', function () {
     it('Should fail with a big thumbnail file', async function () {
       const fields = baseCorrectParams
       const attaches = {
-        thumbnailfile: join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
+        thumbnailfile: buildAbsoluteFixturePath('preview-big.png')
       }
 
       await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
@@ -212,7 +219,7 @@ describe('Test video imports API validator', function () {
     it('Should fail with an incorrect preview file', async function () {
       const fields = baseCorrectParams
       const attaches = {
-        previewfile: join(__dirname, '..', '..', 'fixtures', 'avatar.png')
+        previewfile: buildAbsoluteFixturePath('video_short.mp4')
       }
 
       await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
@@ -221,7 +228,7 @@ describe('Test video imports API validator', function () {
     it('Should fail with a big preview file', async function () {
       const fields = baseCorrectParams
       const attaches = {
-        previewfile: join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
+        previewfile: buildAbsoluteFixturePath('preview-big.png')
       }
 
       await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
@@ -230,7 +237,7 @@ describe('Test video imports API validator', function () {
     it('Should fail with an invalid torrent file', async function () {
       const fields = omit(baseCorrectParams, 'targetUrl')
       const attaches = {
-        torrentfile: join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
+        torrentfile: buildAbsoluteFixturePath('avatar-big.png')
       }
 
       await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
@@ -251,7 +258,7 @@ describe('Test video imports API validator', function () {
         path,
         token: server.accessToken,
         fields: baseCorrectParams,
-        statusCodeExpected: 200
+        statusCodeExpected: HttpStatusCode.OK_200
       })
     })
 
@@ -274,7 +281,7 @@ describe('Test video imports API validator', function () {
         path,
         token: server.accessToken,
         fields: baseCorrectParams,
-        statusCodeExpected: 409
+        statusCodeExpected: HttpStatusCode.CONFLICT_409
       })
     })
 
@@ -295,14 +302,27 @@ describe('Test video imports API validator', function () {
       let fields = omit(baseCorrectParams, 'targetUrl')
       fields = immutableAssign(fields, { magnetUri: getMagnetURI() })
 
-      await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 })
+      await makePostBodyRequest({
+        url: server.url,
+        path,
+        token: server.accessToken,
+        fields,
+        statusCodeExpected: HttpStatusCode.CONFLICT_409
+      })
 
       fields = omit(fields, 'magnetUri')
       const attaches = {
-        torrentfile: join(__dirname, '..', '..', 'fixtures', 'video-720p.torrent')
+        torrentfile: buildAbsoluteFixturePath('video-720p.torrent')
       }
 
-      await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches, statusCodeExpected: 409 })
+      await makeUploadRequest({
+        url: server.url,
+        path,
+        token: server.accessToken,
+        fields,
+        attaches,
+        statusCodeExpected: HttpStatusCode.CONFLICT_409
+      })
     })
   })