]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/check-params/video-imports.ts
Fix notification icon position
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / video-imports.ts
index 7f58efb744ff1965cfba8d46d1916b62ba113cde..7bf187007c90243b0e516a27f61a9586a6e9d29e 100644 (file)
@@ -16,9 +16,15 @@ import {
   runServer,
   ServerInfo,
   setAccessTokensToServers,
+  updateCustomSubConfig,
   userLogin
-} from '../../utils'
-import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
+} from '../../../../shared/utils'
+import {
+  checkBadCountPagination,
+  checkBadSortPagination,
+  checkBadStartPagination
+} from '../../../../shared/utils/requests/check-api-params'
+import { getMagnetURI, getYoutubeVideoUrl } from '../../../../shared/utils/videos/video-imports'
 
 describe('Test video imports API validator', function () {
   const path = '/api/v1/videos/imports'
@@ -26,7 +32,6 @@ describe('Test video imports API validator', function () {
   let userAccessToken = ''
   let accountName: string
   let channelId: number
-  let channelUUID: string
 
   // ---------------------------------------------------------------
 
@@ -47,7 +52,6 @@ describe('Test video imports API validator', function () {
     {
       const res = await getMyUserInformation(server.url, server.accessToken)
       channelId = res.body.videoChannels[ 0 ].id
-      channelUUID = res.body.videoChannels[ 0 ].uuid
       accountName = res.body.account.name + '@' + res.body.account.host
     }
   })
@@ -77,7 +81,7 @@ describe('Test video imports API validator', function () {
 
     before(function () {
       baseCorrectParams = {
-        targetUrl: 'https://youtu.be/msX3jv1XdvM',
+        targetUrl: getYoutubeVideoUrl(),
         name: 'my super name',
         category: 5,
         licence: 1,
@@ -98,6 +102,17 @@ describe('Test video imports API validator', function () {
       await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
     })
 
+    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 })
+    })
+
+    it('Should fail with a bad target url', async function () {
+      const fields = immutableAssign(baseCorrectParams, { targetUrl: 'htt://hello' })
+
+      await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
+    })
+
     it('Should fail with a long name', async function () {
       const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
 
@@ -129,7 +144,7 @@ describe('Test video imports API validator', function () {
     })
 
     it('Should fail with a long support text', async function () {
-      const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) })
+      const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
 
       await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
     })
@@ -216,23 +231,85 @@ describe('Test video imports API validator', function () {
       await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
     })
 
-    it('Should succeed with the correct parameters', async function () {
-      this.timeout(10000)
+    it('Should fail with an invalid torrent file', async function () {
+      const fields = omit(baseCorrectParams, 'targetUrl')
+      const attaches = {
+        'torrentfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
+      }
 
-      const fields = baseCorrectParams
+      await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
+    })
+
+    it('Should fail with an invalid magnet URI', async function () {
+      let fields = omit(baseCorrectParams, 'targetUrl')
+      fields = immutableAssign(fields, { magnetUri: 'blabla' })
+
+      await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
+    })
+
+    it('Should succeed with the correct parameters', async function () {
+      this.timeout(30000)
 
       {
         await makePostBodyRequest({
           url: server.url,
           path,
           token: server.accessToken,
-          fields,
+          fields: baseCorrectParams,
           statusCodeExpected: 200
         })
       }
     })
 
-    it('Should forbid importing')
+    it('Should forbid to import http videos', async function () {
+      await updateCustomSubConfig(server.url, server.accessToken, {
+        import: {
+          videos: {
+            http: {
+              enabled: false
+            },
+            torrent: {
+              enabled: true
+            }
+          }
+        }
+      })
+
+      await makePostBodyRequest({
+        url: server.url,
+        path,
+        token: server.accessToken,
+        fields: baseCorrectParams,
+        statusCodeExpected: 409
+      })
+    })
+
+    it('Should forbid to import torrent videos', async function () {
+      await updateCustomSubConfig(server.url, server.accessToken, {
+        import: {
+          videos: {
+            http: {
+              enabled: true
+            },
+            torrent: {
+              enabled: false
+            }
+          }
+        }
+      })
+
+      let fields = omit(baseCorrectParams, 'targetUrl')
+      fields = immutableAssign(fields, { magnetUri: getMagnetURI() })
+
+      await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields, statusCodeExpected: 409 })
+
+      fields = omit(fields, 'magnetUri')
+      const attaches = {
+        'torrentfile': join(__dirname, '..', '..', 'fixtures', 'video-720p.torrent')
+      }
+
+      await makeUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches, statusCodeExpected: 409 })
+    })
   })
 
   after(async function () {