]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/utils/videos.js
Add previews cache system between pods
[github/Chocobozzz/PeerTube.git] / server / tests / utils / videos.js
index 0aa6ec5a8074963b1f50904fd7b2ede57017a37f..cb3be6897be461e8190cbe499b4a30364ea92a8d 100644 (file)
@@ -6,6 +6,8 @@ const request = require('supertest')
 
 const videosUtils = {
   getVideoCategories,
+  getVideoLicences,
+  getVideoLanguages,
   getAllVideosListBy,
   getVideo,
   getVideosList,
@@ -34,6 +36,28 @@ function getVideoCategories (url, end) {
     .end(end)
 }
 
+function getVideoLicences (url, end) {
+  const path = '/api/v1/videos/licences'
+
+  request(url)
+    .get(path)
+    .set('Accept', 'application/json')
+    .expect(200)
+    .expect('Content-Type', /json/)
+    .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'
 
@@ -171,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) {
@@ -181,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))
@@ -193,7 +217,7 @@ function testVideoImage (url, videoName, imagePath, callback) {
   }
 }
 
-function uploadVideo (url, accessToken, name, category, description, tags, fixture, specialStatus, end) {
+function uploadVideo (url, accessToken, videoAttributesArg, specialStatus, end) {
   if (!end) {
     end = specialStatus
     specialStatus = 204
@@ -201,23 +225,39 @@ function uploadVideo (url, accessToken, name, category, description, tags, fixtu
 
   const path = '/api/v1/videos'
 
+  // Default attributes
+  let attributes = {
+    name: 'my super video',
+    category: 5,
+    licence: 4,
+    language: 3,
+    nsfw: true,
+    description: 'my super description',
+    tags: [ 'tag' ],
+    fixture: 'video_short.webm'
+  }
+  attributes = Object.assign(attributes, videoAttributesArg)
+
   const req = request(url)
               .post(path)
               .set('Accept', 'application/json')
               .set('Authorization', 'Bearer ' + accessToken)
-              .field('name', name)
-              .field('category', category)
-              .field('description', description)
-
-  for (let i = 0; i < tags.length; i++) {
-    req.field('tags[' + i + ']', tags[i])
+              .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++) {
+    req.field('tags[' + i + ']', attributes.tags[i])
   }
 
   let filepath = ''
-  if (pathUtils.isAbsolute(fixture)) {
-    filepath = fixture
+  if (pathUtils.isAbsolute(attributes.fixture)) {
+    filepath = attributes.fixture
   } else {
-    filepath = pathUtils.join(__dirname, '..', 'api', 'fixtures', fixture)
+    filepath = pathUtils.join(__dirname, '..', 'api', 'fixtures', attributes.fixture)
   }
 
   req.attach('videofile', filepath)
@@ -225,30 +265,30 @@ function uploadVideo (url, accessToken, name, category, description, tags, fixtu
      .end(end)
 }
 
-function updateVideo (url, accessToken, id, name, category, description, tags, specialStatus, end) {
+function updateVideo (url, accessToken, id, attributes, specialStatus, end) {
   if (!end) {
     end = specialStatus
     specialStatus = 204
   }
 
   const path = '/api/v1/videos/' + id
+  const body = {}
 
-  const req = request(url)
-              .put(path)
-              .set('Accept', 'application/json')
-              .set('Authorization', 'Bearer ' + accessToken)
-
-  if (name) req.field('name', name)
-  if (category) req.field('category', category)
-  if (description) req.field('description', 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 (tags) {
-    for (let i = 0; i < tags.length; i++) {
-      req.field('tags[' + i + ']', 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) {