]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/utils/videos.js
Client: add support for video licences
[github/Chocobozzz/PeerTube.git] / server / tests / utils / videos.js
index 1774260761cfa55549a61497ddba6c9311b261e1..d1e0b7b14e5ad8ba50efd1e29dc86b5345bb34b8 100644 (file)
@@ -5,6 +5,8 @@ const pathUtils = require('path')
 const request = require('supertest')
 
 const videosUtils = {
+  getVideoCategories,
+  getVideoLicences,
   getAllVideosListBy,
   getVideo,
   getVideosList,
@@ -22,6 +24,28 @@ const videosUtils = {
 
 // ---------------------- Export functions --------------------
 
+function getVideoCategories (url, end) {
+  const path = '/api/v1/videos/categories'
+
+  request(url)
+    .get(path)
+    .set('Accept', 'application/json')
+    .expect(200)
+    .expect('Content-Type', /json/)
+    .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 getAllVideosListBy (url, end) {
   const path = '/api/v1/videos'
 
@@ -181,7 +205,7 @@ function testVideoImage (url, videoName, imagePath, callback) {
   }
 }
 
-function uploadVideo (url, accessToken, name, description, tags, fixture, specialStatus, end) {
+function uploadVideo (url, accessToken, videoAttributesArg, specialStatus, end) {
   if (!end) {
     end = specialStatus
     specialStatus = 204
@@ -189,22 +213,35 @@ function uploadVideo (url, accessToken, name, description, tags, fixture, specia
 
   const path = '/api/v1/videos'
 
+  // Default attributes
+  let attributes = {
+    name: 'my super video',
+    category: 5,
+    licence: 4,
+    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('description', description)
+              .field('name', attributes.name)
+              .field('category', attributes.category)
+              .field('licence', attributes.licence)
+              .field('description', attributes.description)
 
-  for (let i = 0; i < tags.length; i++) {
-    req.field('tags[' + i + ']', tags[i])
+  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)
@@ -212,7 +249,7 @@ function uploadVideo (url, accessToken, name, description, tags, fixture, specia
      .end(end)
 }
 
-function updateVideo (url, accessToken, id, name, description, tags, specialStatus, end) {
+function updateVideo (url, accessToken, id, attributes, specialStatus, end) {
   if (!end) {
     end = specialStatus
     specialStatus = 204
@@ -225,12 +262,14 @@ function updateVideo (url, accessToken, id, name, description, tags, specialStat
               .set('Accept', 'application/json')
               .set('Authorization', 'Bearer ' + accessToken)
 
-  if (name) req.field('name', name)
-  if (description) req.field('description', description)
+  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 (tags) {
-    for (let i = 0; i < tags.length; i++) {
-      req.field('tags[' + i + ']', tags[i])
+  if (attributes.tags) {
+    for (let i = 0; i < attributes.tags.length; i++) {
+      req.field('tags[' + i + ']', attributes.tags[i])
     }
   }