]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/check-params/videos.ts
Add channels to upload form
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / videos.ts
index 8d30769d3afff163bc04fe54cc36d871e5039c05..167b45b61ef6a519a59e6c2eac69fa3b63f9410c 100644 (file)
@@ -14,12 +14,16 @@ import {
   makePutBodyRequest,
   setAccessTokensToServers,
   killallServers,
-  makePostUploadRequest
+  makePostUploadRequest,
+  getMyUserInformation,
+  createUser,
+  getUserAccessToken
 } from '../../utils'
 
 describe('Test videos API validator', function () {
   const path = '/api/v1/videos/'
   let server: ServerInfo
+  let channelId: number
 
   // ---------------------------------------------------------------
 
@@ -31,6 +35,9 @@ describe('Test videos API validator', function () {
     server = await runServer(1)
 
     await setAccessTokensToServers([ server ])
+
+    const res = await getMyUserInformation(server.url, server.accessToken)
+    channelId = res.body.videoChannels[0].id
   })
 
   describe('When listing a video', function () {
@@ -96,7 +103,7 @@ describe('Test videos API validator', function () {
     it('Should fail with nothing', async function () {
       const fields = {}
       const attaches = {}
-      await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
+      await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
     })
 
     it('Should fail without name', async function () {
@@ -106,12 +113,13 @@ describe('Test videos API validator', function () {
         language: 6,
         nsfw: false,
         description: 'my super description',
-        tags: [ 'tag1', 'tag2' ]
+        tags: [ 'tag1', 'tag2' ],
+        channelId
       }
       const attaches = {
         'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
       }
-      await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
+      await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
     })
 
     it('Should fail with a long name', async function () {
@@ -122,12 +130,13 @@ describe('Test videos API validator', function () {
         language: 6,
         nsfw: false,
         description: 'my super description',
-        tags: [ 'tag1', 'tag2' ]
+        tags: [ 'tag1', 'tag2' ],
+        channelId
       }
       const attaches = {
         'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
       }
-      await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
+      await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
     })
 
     it('Should fail without a category', async function () {
@@ -137,12 +146,13 @@ describe('Test videos API validator', function () {
         language: 6,
         nsfw: false,
         description: 'my super description',
-        tags: [ 'tag1', 'tag2' ]
+        tags: [ 'tag1', 'tag2' ],
+        channelId
       }
       const attaches = {
         'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
       }
-      await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
+      await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
     })
 
     it('Should fail with a bad category', async function () {
@@ -153,12 +163,13 @@ describe('Test videos API validator', function () {
         language: 6,
         nsfw: false,
         description: 'my super description',
-        tags: [ 'tag1', 'tag2' ]
+        tags: [ 'tag1', 'tag2' ],
+        channelId
       }
       const attaches = {
         'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
       }
-      await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
+      await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
     })
 
     it('Should fail without a licence', async function () {
@@ -168,12 +179,13 @@ describe('Test videos API validator', function () {
         language: 6,
         nsfw: false,
         description: 'my super description',
-        tags: [ 'tag1', 'tag2' ]
+        tags: [ 'tag1', 'tag2' ],
+        channelId
       }
       const attaches = {
         'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
       }
-      await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
+      await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
     })
 
     it('Should fail with a bad licence', async function () {
@@ -184,12 +196,13 @@ describe('Test videos API validator', function () {
         language: 6,
         nsfw: false,
         description: 'my super description',
-        tags: [ 'tag1', 'tag2' ]
+        tags: [ 'tag1', 'tag2' ],
+        channelId
       }
       const attaches = {
         'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
       }
-      await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
+      await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
     })
 
     it('Should fail with a bad language', async function () {
@@ -200,12 +213,13 @@ describe('Test videos API validator', function () {
         language: 563,
         nsfw: false,
         description: 'my super description',
-        tags: [ 'tag1', 'tag2' ]
+        tags: [ 'tag1', 'tag2' ],
+        channelId
       }
       const attaches = {
         'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
       }
-      await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
+      await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
     })
 
     it('Should fail without nsfw attribute', async function () {
@@ -215,15 +229,16 @@ describe('Test videos API validator', function () {
         licence: 4,
         language: 6,
         description: 'my super description',
-        tags: [ 'tag1', 'tag2' ]
+        tags: [ 'tag1', 'tag2' ],
+        channelId
       }
       const attaches = {
         'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
       }
-      await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
+      await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
     })
 
-    it('Should fail with a bad nsfw attribue', async function () {
+    it('Should fail with a bad nsfw attribute', async function () {
       const fields = {
         name: 'my super name',
         category: 5,
@@ -231,12 +246,13 @@ describe('Test videos API validator', function () {
         language: 6,
         nsfw: 2,
         description: 'my super description',
-        tags: [ 'tag1', 'tag2' ]
+        tags: [ 'tag1', 'tag2' ],
+        channelId
       }
       const attaches = {
         'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
       }
-      await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
+      await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
     })
 
     it('Should fail without description', async function () {
@@ -246,12 +262,13 @@ describe('Test videos API validator', function () {
         licence: 1,
         language: 6,
         nsfw: false,
-        tags: [ 'tag1', 'tag2' ]
+        tags: [ 'tag1', 'tag2' ],
+        channelId
       }
       const attaches = {
         'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
       }
-      await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
+      await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
     })
 
     it('Should fail with a long description', async function () {
@@ -264,12 +281,73 @@ describe('Test videos API validator', function () {
         description: 'my super description which is very very very very very very very very very very very very very very' +
                      'very very very very very very very very very very very very very very very very very very very very very' +
                      'very very very very very very very very very very very very very very very long',
+        tags: [ 'tag1', 'tag2' ],
+        channelId
+      }
+      const attaches = {
+        'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
+      }
+      await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
+    })
+
+    it('Should fail without a channel', async function () {
+      const fields = {
+        name: 'my super name',
+        category: 5,
+        licence: 1,
+        language: 6,
+        nsfw: false,
+        description: 'my super description',
         tags: [ 'tag1', 'tag2' ]
       }
       const attaches = {
         'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
       }
-      await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
+      await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
+    })
+
+    it('Should fail with a bad channel', async function () {
+      const fields = {
+        name: 'my super name',
+        category: 5,
+        licence: 1,
+        language: 6,
+        nsfw: false,
+        description: 'my super description',
+        tags: [ 'tag1', 'tag2' ],
+        channelId: 545454
+      }
+      const attaches = {
+        'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
+      }
+      await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
+    })
+
+    it('Should fail with another user channel', async function () {
+      const user = {
+        username: 'fake',
+        password: 'fake_password'
+      }
+      await createUser(server.url, server.accessToken, user.username, user.password)
+
+      const accessTokenUser = await getUserAccessToken(server, user)
+      const res = await getMyUserInformation(server.url, accessTokenUser)
+      const channelId = res.body.videoChannels[0].id
+
+      const fields = {
+        name: 'my super name',
+        category: 5,
+        licence: 1,
+        language: 6,
+        nsfw: false,
+        description: 'my super description',
+        tags: [ 'tag1', 'tag2' ],
+        channelId
+      }
+      const attaches = {
+        'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
+      }
+      await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
     })
 
     it('Should fail with too many tags', async function () {
@@ -280,12 +358,13 @@ describe('Test videos API validator', function () {
         language: 6,
         nsfw: false,
         description: 'my super description',
-        tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
+        tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ],
+        channelId
       }
       const attaches = {
         'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
       }
-      await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
+      await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
     })
 
     it('Should fail with a tag length too low', async function () {
@@ -296,12 +375,13 @@ describe('Test videos API validator', function () {
         language: 6,
         nsfw: false,
         description: 'my super description',
-        tags: [ 'tag1', 't' ]
+        tags: [ 'tag1', 't' ],
+        channelId
       }
       const attaches = {
         'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
       }
-      await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
+      await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
     })
 
     it('Should fail with a tag length too big', async function () {
@@ -312,12 +392,13 @@ describe('Test videos API validator', function () {
         language: 6,
         nsfw: false,
         description: 'my super description',
-        tags: [ 'my_super_tag_too_long', 'tag1' ]
+        tags: [ 'my_super_tag_too_long', 'tag1' ],
+        channelId
       }
       const attaches = {
         'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
       }
-      await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
+      await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
     })
 
     it('Should fail without an input file', async function () {
@@ -328,10 +409,11 @@ describe('Test videos API validator', function () {
         language: 6,
         nsfw: false,
         description: 'my super description',
-        tags: [ 'tag1', 'tag2' ]
+        tags: [ 'tag1', 'tag2' ],
+        channelId
       }
       const attaches = {}
-      await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
+      await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
     })
 
     it('Should fail without an incorrect input file', async function () {
@@ -342,12 +424,13 @@ describe('Test videos API validator', function () {
         language: 6,
         nsfw: false,
         description: 'my super description',
-        tags: [ 'tag1', 'tag2' ]
+        tags: [ 'tag1', 'tag2' ],
+        channelId
       }
       const attaches = {
         'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
       }
-      await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
+      await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
     })
 
     it('Should fail with a too big duration', async function () {
@@ -358,12 +441,13 @@ describe('Test videos API validator', function () {
         language: 6,
         nsfw: false,
         description: 'my super description',
-        tags: [ 'tag1', 'tag2' ]
+        tags: [ 'tag1', 'tag2' ],
+        channelId
       }
       const attaches = {
         'videofile': join(__dirname, '..', 'fixtures', 'video_too_long.webm')
       }
-      await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
+      await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
     })
 
     it('Should succeed with the correct parameters', async function () {
@@ -376,19 +460,41 @@ describe('Test videos API validator', function () {
         language: 6,
         nsfw: false,
         description: 'my super description',
-        tags: [ 'tag1', 'tag2' ]
+        tags: [ 'tag1', 'tag2' ],
+        channelId
       }
       const attaches = {
         'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
       }
 
-      await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches, statusCodeExpected: 204 })
+      await makePostUploadRequest({
+        url: server.url,
+        path: path + '/upload',
+        token: server.accessToken,
+        fields,
+        attaches,
+        statusCodeExpected: 204
+      })
 
       attaches.videofile = join(__dirname, '..', 'fixtures', 'video_short.mp4')
-      await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches, statusCodeExpected: 204 })
+      await makePostUploadRequest({
+        url: server.url,
+        path: path + '/upload',
+        token: server.accessToken,
+        fields,
+        attaches,
+        statusCodeExpected: 204
+      })
 
       attaches.videofile = join(__dirname, '..', 'fixtures', 'video_short.ogv')
-      await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches, statusCodeExpected: 204 })
+      await makePostUploadRequest({
+        url: server.url,
+        path: path + '/upload',
+        token: server.accessToken,
+        fields,
+        attaches,
+        statusCodeExpected: 204
+      })
     })
   })