]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/check-params/videos.js
Begin user quota
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / videos.js
index fac9037154a73959daec1458fb9b94ce18b36c39..ce6c495832bea3116bd2a74995b7eeeaeda80323 100644 (file)
@@ -1,3 +1,5 @@
+/* eslint-disable no-unused-expressions */
+
 'use strict'
 
 const chai = require('chai')
@@ -110,6 +112,10 @@ describe('Test videos API validator', function () {
 
     it('Should fail without name', function (done) {
       const data = {
+        category: 5,
+        licence: 1,
+        language: 6,
+        nsfw: false,
         description: 'my super description',
         tags: [ 'tag1', 'tag2' ]
       }
@@ -122,6 +128,10 @@ describe('Test videos API validator', function () {
     it('Should fail with a long name', function (done) {
       const data = {
         name: 'My very very very very very very very very very very very very very very very very long name',
+        category: 5,
+        licence: 1,
+        language: 6,
+        nsfw: false,
         description: 'my super description',
         tags: [ 'tag1', 'tag2' ]
       }
@@ -131,9 +141,13 @@ describe('Test videos API validator', function () {
       requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
     })
 
-    it('Should fail without description', function (done) {
+    it('Should fail without a category', function (done) {
       const data = {
         name: 'my super name',
+        licence: 1,
+        language: 6,
+        nsfw: false,
+        description: 'my super description',
         tags: [ 'tag1', 'tag2' ]
       }
       const attach = {
@@ -142,12 +156,14 @@ describe('Test videos API validator', function () {
       requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
     })
 
-    it('Should fail with a long description', function (done) {
+    it('Should fail with a bad category', function (done) {
       const data = {
         name: 'my super name',
-        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',
+        category: 125,
+        licence: 1,
+        language: 6,
+        nsfw: false,
+        description: 'my super description',
         tags: [ 'tag1', 'tag2' ]
       }
       const attach = {
@@ -156,10 +172,14 @@ describe('Test videos API validator', function () {
       requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
     })
 
-    it('Should fail without tags', function (done) {
+    it('Should fail without a licence', function (done) {
       const data = {
         name: 'my super name',
-        description: 'my super description'
+        category: 5,
+        language: 6,
+        nsfw: false,
+        description: 'my super description',
+        tags: [ 'tag1', 'tag2' ]
       }
       const attach = {
         'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
@@ -167,11 +187,15 @@ describe('Test videos API validator', function () {
       requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
     })
 
-    it('Should fail with too many tags', function (done) {
+    it('Should fail with a bad licence', function (done) {
       const data = {
         name: 'my super name',
+        category: 5,
+        licence: 125,
+        language: 6,
+        nsfw: false,
         description: 'my super description',
-        tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
+        tags: [ 'tag1', 'tag2' ]
       }
       const attach = {
         'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
@@ -179,11 +203,15 @@ describe('Test videos API validator', function () {
       requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
     })
 
-    it('Should fail with not enough tags', function (done) {
+    it('Should fail with a bad language', function (done) {
       const data = {
         name: 'my super name',
+        category: 5,
+        licence: 4,
+        language: 563,
+        nsfw: false,
         description: 'my super description',
-        tags: [ ]
+        tags: [ 'tag1', 'tag2' ]
       }
       const attach = {
         'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
@@ -191,11 +219,14 @@ describe('Test videos API validator', function () {
       requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
     })
 
-    it('Should fail with a tag length too low', function (done) {
+    it('Should fail without nsfw attribute', function (done) {
       const data = {
         name: 'my super name',
+        category: 5,
+        licence: 4,
+        language: 6,
         description: 'my super description',
-        tags: [ 'tag1', 't' ]
+        tags: [ 'tag1', 'tag2' ]
       }
       const attach = {
         'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
@@ -203,11 +234,80 @@ describe('Test videos API validator', function () {
       requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
     })
 
-    it('Should fail with a tag length too big', function (done) {
+    it('Should fail with a bad nsfw attribue', function (done) {
       const data = {
         name: 'my super name',
+        category: 5,
+        licence: 4,
+        language: 6,
+        nsfw: 2,
         description: 'my super description',
-        tags: [ 'mysupertagtoolong', 'tag1' ]
+        tags: [ 'tag1', 'tag2' ]
+      }
+      const attach = {
+        'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
+      }
+      requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
+    })
+
+    it('Should fail without description', function (done) {
+      const data = {
+        name: 'my super name',
+        category: 5,
+        licence: 1,
+        language: 6,
+        nsfw: false,
+        tags: [ 'tag1', 'tag2' ]
+      }
+      const attach = {
+        'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
+      }
+      requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
+    })
+
+    it('Should fail with a long description', function (done) {
+      const data = {
+        name: 'my super name',
+        category: 5,
+        licence: 1,
+        language: 6,
+        nsfw: false,
+        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' ]
+      }
+      const attach = {
+        'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
+      }
+      requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
+    })
+
+    it('Should fail with too many tags', function (done) {
+      const data = {
+        name: 'my super name',
+        category: 5,
+        licence: 1,
+        language: 6,
+        nsfw: false,
+        description: 'my super description',
+        tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
+      }
+      const attach = {
+        'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
+      }
+      requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
+    })
+
+    it('Should fail with a tag length too low', function (done) {
+      const data = {
+        name: 'my super name',
+        category: 5,
+        licence: 1,
+        language: 6,
+        nsfw: false,
+        description: 'my super description',
+        tags: [ 'tag1', 't' ]
       }
       const attach = {
         'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
@@ -215,11 +315,15 @@ describe('Test videos API validator', function () {
       requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
     })
 
-    it('Should fail with malformed tags', function (done) {
+    it('Should fail with a tag length too big', function (done) {
       const data = {
         name: 'my super name',
+        category: 5,
+        licence: 1,
+        language: 6,
+        nsfw: false,
         description: 'my super description',
-        tags: [ 'my tag' ]
+        tags: [ 'mysupertagtoolong', 'tag1' ]
       }
       const attach = {
         'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
@@ -230,6 +334,10 @@ describe('Test videos API validator', function () {
     it('Should fail without an input file', function (done) {
       const data = {
         name: 'my super name',
+        category: 5,
+        licence: 1,
+        language: 6,
+        nsfw: false,
         description: 'my super description',
         tags: [ 'tag1', 'tag2' ]
       }
@@ -240,6 +348,10 @@ describe('Test videos API validator', function () {
     it('Should fail without an incorrect input file', function (done) {
       const data = {
         name: 'my super name',
+        category: 5,
+        licence: 1,
+        language: 6,
+        nsfw: false,
         description: 'my super description',
         tags: [ 'tag1', 'tag2' ]
       }
@@ -252,6 +364,10 @@ describe('Test videos API validator', function () {
     it('Should fail with a too big duration', function (done) {
       const data = {
         name: 'my super name',
+        category: 5,
+        licence: 1,
+        language: 6,
+        nsfw: false,
         description: 'my super description',
         tags: [ 'tag1', 'tag2' ]
       }
@@ -262,14 +378,21 @@ describe('Test videos API validator', function () {
     })
 
     it('Should succeed with the correct parameters', function (done) {
+      this.timeout(10000)
+
       const data = {
         name: 'my super name',
+        category: 5,
+        licence: 1,
+        language: 6,
+        nsfw: false,
         description: 'my super description',
         tags: [ 'tag1', 'tag2' ]
       }
       const attach = {
         'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
       }
+
       requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () {
         attach.videofile = pathUtils.join(__dirname, '..', 'fixtures', 'video_short.mp4')
         requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, function () {
@@ -300,6 +423,10 @@ describe('Test videos API validator', function () {
 
     it('Should fail without a valid uuid', function (done) {
       const data = {
+        category: 5,
+        licence: 2,
+        language: 6,
+        nsfw: false,
         description: 'my super description',
         tags: [ 'tag1', 'tag2' ]
       }
@@ -308,6 +435,10 @@ describe('Test videos API validator', function () {
 
     it('Should fail with an unknown id', function (done) {
       const data = {
+        category: 5,
+        licence: 2,
+        language: 6,
+        nsfw: false,
         description: 'my super description',
         tags: [ 'tag1', 'tag2' ]
       }
@@ -317,64 +448,118 @@ describe('Test videos API validator', function () {
     it('Should fail with a long name', function (done) {
       const data = {
         name: 'My very very very very very very very very very very very very very very very very long name',
+        category: 5,
+        licence: 2,
+        language: 6,
+        nsfw: false,
         description: 'my super description',
         tags: [ 'tag1', 'tag2' ]
       }
       requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
     })
 
-    it('Should fail with a long description', function (done) {
+    it('Should fail with a bad category', function (done) {
       const data = {
         name: 'my super name',
-        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',
+        category: 128,
+        licence: 2,
+        language: 6,
+        nsfw: false,
+        description: 'my super description',
         tags: [ 'tag1', 'tag2' ]
       }
       requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
     })
 
-    it('Should fail with too many tags', function (done) {
+    it('Should fail with a bad licence', function (done) {
       const data = {
         name: 'my super name',
+        category: 5,
+        licence: 128,
+        language: 6,
+        nsfw: false,
         description: 'my super description',
-        tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
+        tags: [ 'tag1', 'tag2' ]
       }
       requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
     })
 
-    it('Should fail with not enough tags', function (done) {
+    it('Should fail with a bad language', function (done) {
       const data = {
         name: 'my super name',
+        category: 5,
+        licence: 3,
+        language: 896,
+        nsfw: false,
         description: 'my super description',
-        tags: [ ]
+        tags: [ 'tag1', 'tag2' ]
       }
       requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
     })
 
-    it('Should fail with a tag length too low', function (done) {
+    it('Should fail with a bad nsfw attribute', function (done) {
       const data = {
         name: 'my super name',
+        category: 5,
+        licence: 5,
+        language: 6,
+        nsfw: -4,
         description: 'my super description',
-        tags: [ 'tag1', 't' ]
+        tags: [ 'tag1', 'tag2' ]
       }
       requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
     })
 
-    it('Should fail with a tag length too big', function (done) {
+    it('Should fail with a long description', function (done) {
+      const data = {
+        name: 'my super name',
+        category: 5,
+        licence: 2,
+        language: 6,
+        nsfw: false,
+        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' ]
+      }
+      requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
+    })
+
+    it('Should fail with too many tags', function (done) {
       const data = {
         name: 'my super name',
+        category: 5,
+        licence: 2,
+        language: 6,
+        nsfw: false,
         description: 'my super description',
-        tags: [ 'mysupertagtoolong', 'tag1' ]
+        tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
       }
       requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
     })
 
-    it('Should fail with malformed tags', function (done) {
+    it('Should fail with a tag length too low', function (done) {
       const data = {
         name: 'my super name',
+        category: 5,
+        licence: 2,
+        language: 6,
+        nsfw: false,
         description: 'my super description',
-        tags: [ 'my tag' ]
+        tags: [ 'tag1', 't' ]
+      }
+      requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
+    })
+
+    it('Should fail with a tag length too big', function (done) {
+      const data = {
+        name: 'my super name',
+        category: 5,
+        licence: 2,
+        language: 6,
+        nsfw: false,
+        description: 'my super description',
+        tags: [ 'mysupertagtoolong', 'tag1' ]
       }
       requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
     })
@@ -418,6 +603,48 @@ describe('Test videos API validator', function () {
     it('Should succeed with the correct parameters')
   })
 
+  describe('When rating a video', function () {
+    let videoId
+
+    before(function (done) {
+      videosUtils.getVideosList(server.url, function (err, res) {
+        if (err) throw err
+
+        videoId = res.body.data[0].id
+
+        return done()
+      })
+    })
+
+    it('Should fail without a valid uuid', function (done) {
+      const data = {
+        rating: 'like'
+      }
+      requestsUtils.makePutBodyRequest(server.url, path + 'blabla/rate', server.accessToken, data, done)
+    })
+
+    it('Should fail with an unknown id', function (done) {
+      const data = {
+        rating: 'like'
+      }
+      requestsUtils.makePutBodyRequest(server.url, path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate', server.accessToken, data, done, 404)
+    })
+
+    it('Should fail with a wrong rating', function (done) {
+      const data = {
+        rating: 'likes'
+      }
+      requestsUtils.makePutBodyRequest(server.url, path + videoId + '/rate', server.accessToken, data, done)
+    })
+
+    it('Should succeed with the correct parameters', function (done) {
+      const data = {
+        rating: 'like'
+      }
+      requestsUtils.makePutBodyRequest(server.url, path + videoId + '/rate', server.accessToken, data, done, 204)
+    })
+  })
+
   describe('When removing a video', function () {
     it('Should have 404 with nothing', function (done) {
       request(server.url)