]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/utils/videos.ts
Design second video upload step
[github/Chocobozzz/PeerTube.git] / server / tests / utils / videos.ts
index 08fa48da6ce4caf10cd574310c3640ce75ab003c..bdf3368ac87d460401348eaead2596c7287f6d2a 100644 (file)
@@ -7,6 +7,7 @@ import { makeGetRequest } from './requests'
 import { readFilePromise } from './miscs'
 import { ServerInfo } from './servers'
 import { getMyUserInformation } from './users'
+import { VideoPrivacy } from '../../../shared'
 
 type VideoAttributes = {
   name?: string
@@ -17,6 +18,7 @@ type VideoAttributes = {
   description?: string
   tags?: string[]
   channelId?: number
+  privacy?: VideoPrivacy
   fixture?: string
 }
 
@@ -38,27 +40,46 @@ function getVideoLanguages (url: string) {
   return makeGetRequest(url, path)
 }
 
-function getAllVideosListBy (url: string) {
-  const path = '/api/v1/videos'
+function getVideoPrivacies (url: string) {
+  const path = '/api/v1/videos/privacies'
+
+  return makeGetRequest(url, path)
+}
+
+function getVideo (url: string, id: number | string, expectedStatus = 200) {
+  const path = '/api/v1/videos/' + id
 
   return request(url)
           .get(path)
-          .query({ sort: 'createdAt' })
-          .query({ start: 0 })
-          .query({ count: 10000 })
           .set('Accept', 'application/json')
-          .expect(200)
-          .expect('Content-Type', /json/)
+          .expect(expectedStatus)
 }
 
-function getVideo (url: string, id: number | string) {
+function viewVideo (url: string, id: number | string, expectedStatus = 204) {
+  const path = '/api/v1/videos/' + id + '/views'
+
+  return request(url)
+    .post(path)
+    .set('Accept', 'application/json')
+    .expect(expectedStatus)
+}
+
+function getVideoWithToken (url: string, token: string, id: number | string, expectedStatus = 200) {
   const path = '/api/v1/videos/' + id
 
   return request(url)
-          .get(path)
-          .set('Accept', 'application/json')
-          .expect(200)
-          .expect('Content-Type', /json/)
+    .get(path)
+    .set('Authorization', 'Bearer ' + token)
+    .set('Accept', 'application/json')
+    .expect(expectedStatus)
+}
+
+function getVideoDescription (url: string, descriptionPath: string) {
+  return request(url)
+    .get(descriptionPath)
+    .set('Accept', 'application/json')
+    .expect(200)
+    .expect('Content-Type', /json/)
 }
 
 function getVideosList (url: string) {
@@ -72,6 +93,22 @@ function getVideosList (url: string) {
           .expect('Content-Type', /json/)
 }
 
+function getMyVideos (url: string, accessToken: string, start: number, count: number, sort?: string) {
+  const path = '/api/v1/users/me/videos'
+
+  const req = request(url)
+    .get(path)
+    .query({ start: start })
+    .query({ count: count })
+
+  if (sort) req.query({ sort })
+
+  return req.set('Accept', 'application/json')
+    .set('Authorization', 'Bearer ' + accessToken)
+    .expect(200)
+    .expect('Content-Type', /json/)
+}
+
 function getVideosListPagination (url: string, start: number, count: number, sort?: string) {
   const path = '/api/v1/videos'
 
@@ -108,26 +145,25 @@ function removeVideo (url: string, token: string, id: number, expectedStatus = 2
           .expect(expectedStatus)
 }
 
-function searchVideo (url: string, search: string, field?: string) {
+function searchVideo (url: string, search: string) {
   const path = '/api/v1/videos'
   const req = request(url)
-                .get(path + '/search/' + search)
-                .set('Accept', 'application/json')
-
-  if (field) req.query({ field })
+    .get(path + '/search')
+    .query({ search })
+    .set('Accept', 'application/json')
 
   return req.expect(200)
-            .expect('Content-Type', /json/)
+    .expect('Content-Type', /json/)
 }
 
-function searchVideoWithPagination (url: string, search: string, field: string, start: number, count: number, sort?: string) {
+function searchVideoWithPagination (url: string, search: string, start: number, count: number, sort?: string) {
   const path = '/api/v1/videos'
 
   const req = request(url)
-                .get(path + '/search/' + search)
+                .get(path + '/search')
                 .query({ start })
+                .query({ search })
                 .query({ count })
-                .query({ field })
 
   if (sort) req.query({ sort })
 
@@ -140,7 +176,8 @@ function searchVideoWithSort (url: string, search: string, sort: string) {
   const path = '/api/v1/videos'
 
   return request(url)
-          .get(path + '/search/' + search)
+          .get(path + '/search')
+          .query({ search })
           .query({ sort })
           .set('Accept', 'application/json')
           .expect(200)
@@ -164,7 +201,7 @@ async function testVideoImage (url: string, imageName: string, imagePath: string
   }
 }
 
-async function uploadVideo (url: string, accessToken: string, videoAttributesArg: VideoAttributes, specialStatus = 204) {
+async function uploadVideo (url: string, accessToken: string, videoAttributesArg: VideoAttributes, specialStatus = 201) {
   const path = '/api/v1/videos/upload'
   let defaultChannelId = '1'
 
@@ -183,6 +220,7 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg
     nsfw: true,
     description: 'my super description',
     tags: [ 'tag' ],
+    privacy: VideoPrivacy.PUBLIC,
     fixture: 'video_short.webm'
   }
   attributes = Object.assign(attributes, videoAttributesArg)
@@ -196,6 +234,7 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg
               .field('licence', attributes.licence.toString())
               .field('nsfw', JSON.stringify(attributes.nsfw))
               .field('description', attributes.description)
+              .field('privacy', attributes.privacy.toString())
               .field('channelId', attributes.channelId)
 
   if (attributes.language !== undefined) {
@@ -228,6 +267,7 @@ function updateVideo (url: string, accessToken: string, id: number, attributes:
   if (attributes.nsfw) body['nsfw'] = attributes.nsfw
   if (attributes.description) body['description'] = attributes.description
   if (attributes.tags) body['tags'] = attributes.tags
+  if (attributes.privacy) body['privacy'] = attributes.privacy
 
   return request(url)
           .put(path)
@@ -263,11 +303,14 @@ function parseTorrentVideo (server: ServerInfo, videoUUID: string, resolution: n
 // ---------------------------------------------------------------------------
 
 export {
+  getVideoDescription,
   getVideoCategories,
   getVideoLicences,
+  getVideoPrivacies,
   getVideoLanguages,
-  getAllVideosListBy,
+  getMyVideos,
   getVideo,
+  getVideoWithToken,
   getVideosList,
   getVideosListPagination,
   getVideosListSort,
@@ -279,5 +322,6 @@ export {
   uploadVideo,
   updateVideo,
   rateVideo,
+  viewVideo,
   parseTorrentVideo
 }