]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/utils/videos.js
Move video file metadata in their own table
[github/Chocobozzz/PeerTube.git] / server / tests / utils / videos.js
index d1e0b7b14e5ad8ba50efd1e29dc86b5345bb34b8..cb3be6897be461e8190cbe499b4a30364ea92a8d 100644 (file)
@@ -7,6 +7,7 @@ const request = require('supertest')
 const videosUtils = {
   getVideoCategories,
   getVideoLicences,
+  getVideoLanguages,
   getAllVideosListBy,
   getVideo,
   getVideosList,
@@ -46,6 +47,17 @@ function getVideoLicences (url, end) {
     .end(end)
 }
 
+function getVideoLanguages (url, end) {
+  const path = '/api/v1/videos/languages'
+
+  request(url)
+    .get(path)
+    .set('Accept', 'application/json')
+    .expect(200)
+    .expect('Content-Type', /json/)
+    .end(end)
+}
+
 function getAllVideosListBy (url, end) {
   const path = '/api/v1/videos'
 
@@ -183,7 +195,7 @@ function searchVideoWithSort (url, search, sort, end) {
     .end(end)
 }
 
-function testVideoImage (url, videoName, imagePath, callback) {
+function testVideoImage (url, imageName, imagePath, callback) {
   // Don't test images if the node env is not set
   // Because we need a special ffmpeg version for this test
   if (process.env.NODE_TEST_IMAGE) {
@@ -193,7 +205,7 @@ function testVideoImage (url, videoName, imagePath, callback) {
       .end(function (err, res) {
         if (err) return callback(err)
 
-        fs.readFile(pathUtils.join(__dirname, '..', 'api', 'fixtures', videoName + '.jpg'), function (err, data) {
+        fs.readFile(pathUtils.join(__dirname, '..', 'api', 'fixtures', imageName + '.jpg'), function (err, data) {
           if (err) return callback(err)
 
           callback(null, data.equals(res.body))
@@ -218,6 +230,8 @@ function uploadVideo (url, accessToken, videoAttributesArg, specialStatus, end)
     name: 'my super video',
     category: 5,
     licence: 4,
+    language: 3,
+    nsfw: true,
     description: 'my super description',
     tags: [ 'tag' ],
     fixture: 'video_short.webm'
@@ -231,6 +245,8 @@ function uploadVideo (url, accessToken, videoAttributesArg, specialStatus, end)
               .field('name', attributes.name)
               .field('category', attributes.category)
               .field('licence', attributes.licence)
+              .field('language', attributes.language)
+              .field('nsfw', attributes.nsfw)
               .field('description', attributes.description)
 
   for (let i = 0; i < attributes.tags.length; i++) {
@@ -256,24 +272,23 @@ function updateVideo (url, accessToken, id, attributes, specialStatus, end) {
   }
 
   const path = '/api/v1/videos/' + id
+  const body = {}
 
-  const req = request(url)
-              .put(path)
-              .set('Accept', 'application/json')
-              .set('Authorization', 'Bearer ' + accessToken)
-
-  if (attributes.name) req.field('name', attributes.name)
-  if (attributes.category) req.field('category', attributes.category)
-  if (attributes.licence) req.field('licence', attributes.licence)
-  if (attributes.description) req.field('description', attributes.description)
+  if (attributes.name) body.name = attributes.name
+  if (attributes.category) body.category = attributes.category
+  if (attributes.licence) body.licence = attributes.licence
+  if (attributes.language) body.language = attributes.language
+  if (attributes.nsfw) body.nsfw = attributes.nsfw
+  if (attributes.description) body.description = attributes.description
+  if (attributes.tags) body.tags = attributes.tags
 
-  if (attributes.tags) {
-    for (let i = 0; i < attributes.tags.length; i++) {
-      req.field('tags[' + i + ']', attributes.tags[i])
-    }
-  }
-
-  req.expect(specialStatus).end(end)
+  request(url)
+    .put(path)
+    .send(body)
+    .set('Accept', 'application/json')
+    .set('Authorization', 'Bearer ' + accessToken)
+    .expect(specialStatus)
+    .end(end)
 }
 
 function rateVideo (url, accessToken, id, rating, specialStatus, end) {