]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/utils/videos/videos.ts
Add downloadingEnabled property to video model
[github/Chocobozzz/PeerTube.git] / server / tests / utils / videos / videos.ts
index 973bbbe87f0f1163d6c6f68b9aab93441ba2298b..a7fd4c8a60b140a625ce52afa881aebb131281cb 100644 (file)
@@ -1,13 +1,14 @@
 /* tslint:disable:no-unused-expression */
 
 import { expect } from 'chai'
-import { existsSync, readFile } from 'fs-extra'
+import { existsSync, readdir, readFile } from 'fs-extra'
 import * as parseTorrent from 'parse-torrent'
 import { extname, join } from 'path'
 import * as request from 'supertest'
 import {
   buildAbsoluteFixturePath,
-  getMyUserInformation, immutableAssign,
+  getMyUserInformation,
+  immutableAssign,
   makeGetRequest,
   makePutBodyRequest,
   makeUploadRequest,
@@ -16,7 +17,6 @@ import {
   testImage
 } from '../'
 import { VideoDetails, VideoPrivacy } from '../../../../shared/models/videos'
-import { readdirPromise } from '../../../helpers/core-utils'
 import { VIDEO_CATEGORIES, VIDEO_LANGUAGES, VIDEO_LICENCES, VIDEO_PRIVACIES } from '../../../initializers'
 import { dateIsValid, webtorrentAdd } from '../index'
 
@@ -27,6 +27,7 @@ type VideoAttributes = {
   language?: string
   nsfw?: boolean
   commentsEnabled?: boolean
+  downloadingEnabled?: boolean
   waitTranscoding?: boolean
   description?: string
   tags?: string[]
@@ -267,16 +268,20 @@ function removeVideo (url: string, token: string, id: number | string, expectedS
           .expect(expectedStatus)
 }
 
-async function checkVideoFilesWereRemoved (videoUUID: string, serverNumber: number) {
+async function checkVideoFilesWereRemoved (
+  videoUUID: string,
+  serverNumber: number,
+  directories = [ 'videos', 'thumbnails', 'torrents', 'previews', 'captions' ]
+) {
   const testDirectory = 'test' + serverNumber
 
-  for (const directory of [ 'videos', 'thumbnails', 'torrents', 'previews', 'captions' ]) {
+  for (const directory of directories) {
     const directoryPath = join(root(), testDirectory, directory)
 
     const directoryExists = existsSync(directoryPath)
     expect(directoryExists).to.be.true
 
-    const files = await readdirPromise(directoryPath)
+    const files = await readdir(directoryPath)
     for (const file of files) {
       expect(file).to.not.contain(videoUUID)
     }
@@ -306,6 +311,7 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg
     tags: [ 'tag' ],
     privacy: VideoPrivacy.PUBLIC,
     commentsEnabled: true,
+    downloadingEnabled: true,
     fixture: 'video_short.webm'
   }, videoAttributesArg)
 
@@ -316,6 +322,7 @@ async function uploadVideo (url: string, accessToken: string, videoAttributesArg
               .field('name', attributes.name)
               .field('nsfw', JSON.stringify(attributes.nsfw))
               .field('commentsEnabled', JSON.stringify(attributes.commentsEnabled))
+              .field('downloadingEnabled', JSON.stringify(attributes.downloadingEnabled))
               .field('waitTranscoding', JSON.stringify(attributes.waitTranscoding))
               .field('privacy', attributes.privacy.toString())
               .field('channelId', attributes.channelId)
@@ -366,6 +373,7 @@ function updateVideo (url: string, accessToken: string, id: number | string, att
   if (attributes.language) body['language'] = attributes.language
   if (attributes.nsfw !== undefined) body['nsfw'] = JSON.stringify(attributes.nsfw)
   if (attributes.commentsEnabled !== undefined) body['commentsEnabled'] = JSON.stringify(attributes.commentsEnabled)
+  if (attributes.downloadingEnabled !== undefined) body['downloadingEnabled'] = JSON.stringify(attributes.downloadingEnabled)
   if (attributes.description) body['description'] = attributes.description
   if (attributes.tags) body['tags'] = attributes.tags
   if (attributes.privacy) body['privacy'] = attributes.privacy
@@ -431,6 +439,7 @@ async function completeVideoCheck (
     language: string
     nsfw: boolean
     commentsEnabled: boolean
+    downloadingEnabled: boolean
     description: string
     publishedAt?: string
     support: string
@@ -505,6 +514,7 @@ async function completeVideoCheck (
   expect(dateIsValid(videoDetails.channel.createdAt.toString())).to.be.true
   expect(dateIsValid(videoDetails.channel.updatedAt.toString())).to.be.true
   expect(videoDetails.commentsEnabled).to.equal(attributes.commentsEnabled)
+  expect(videoDetails.downloadingEnabled).to.equal(attributes.downloadingEnabled)
 
   for (const attributeFile of attributes.files) {
     const file = videoDetails.files.find(f => f.resolution.id === attributeFile.resolution)