]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/cli/create-import-video-file-job.ts
Introduce CLI command
[github/Chocobozzz/PeerTube.git] / server / tests / cli / create-import-video-file-job.ts
index dac049fe4c3dfeec96c7c7a0c626729a9269f553..8a23a94decaf556242a59933e67a6ee8afff0b2f 100644 (file)
@@ -2,13 +2,11 @@
 
 import 'mocha'
 import * as chai from 'chai'
-import { VideoDetails } from '../../../shared/models/videos'
+import { VideoFile } from '@shared/models/videos/video-file.model'
 import {
   cleanupTests,
   doubleFollow,
-  execCLI,
   flushAndRunMultipleServers,
-  getEnvCli,
   getVideo,
   getVideosList,
   ServerInfo,
@@ -16,15 +14,15 @@ import {
   uploadVideo
 } from '../../../shared/extra-utils'
 import { waitJobs } from '../../../shared/extra-utils/server/jobs'
-import { VideoFile } from '@shared/models/videos/video-file.model'
+import { VideoDetails } from '../../../shared/models/videos'
 
 const expect = chai.expect
 
 function assertVideoProperties (video: VideoFile, resolution: number, extname: string, size?: number) {
   expect(video).to.have.nested.property('resolution.id', resolution)
-  expect(video).to.have.property('magnetUri').that.includes(`.${extname}`)
   expect(video).to.have.property('torrentUrl').that.includes(`-${resolution}.torrent`)
   expect(video).to.have.property('fileUrl').that.includes(`.${extname}`)
+  expect(video).to.have.property('magnetUri').that.includes(`.${extname}`)
   expect(video).to.have.property('size').that.is.above(0)
 
   if (size) expect(video.size).to.equal(size)
@@ -57,12 +55,11 @@ describe('Test create import video jobs', function () {
   })
 
   it('Should run a import job on video 1 with a lower resolution', async function () {
-    const env = getEnvCli(servers[0])
-    await execCLI(`${env} npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short-480.webm`)
+    const command = `npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short-480.webm`
+    await servers[0].cliCommand.execWithEnv(command)
 
     await waitJobs(servers)
 
-    let magnetUri: string
     for (const server of servers) {
       const { data: videos } = (await getVideosList(server.url)).body
       expect(videos).to.have.lengthOf(2)
@@ -74,19 +71,15 @@ describe('Test create import video jobs', function () {
       const [ originalVideo, transcodedVideo ] = videoDetail.files
       assertVideoProperties(originalVideo, 720, 'webm', 218910)
       assertVideoProperties(transcodedVideo, 480, 'webm', 69217)
-
-      if (!magnetUri) magnetUri = transcodedVideo.magnetUri
-      else expect(transcodedVideo.magnetUri).to.equal(magnetUri)
     }
   })
 
   it('Should run a import job on video 2 with the same resolution and a different extension', async function () {
-    const env = getEnvCli(servers[1])
-    await execCLI(`${env} npm run create-import-video-file-job -- -v ${video2UUID} -i server/tests/fixtures/video_short.ogv`)
+    const command = `npm run create-import-video-file-job -- -v ${video2UUID} -i server/tests/fixtures/video_short.ogv`
+    await servers[1].cliCommand.execWithEnv(command)
 
     await waitJobs(servers)
 
-    let magnetUri: string
     for (const server of servers) {
       const { data: videos } = (await getVideosList(server.url)).body
       expect(videos).to.have.lengthOf(2)
@@ -100,19 +93,15 @@ describe('Test create import video jobs', function () {
       assertVideoProperties(transcodedVideo420, 480, 'mp4')
       assertVideoProperties(transcodedVideo320, 360, 'mp4')
       assertVideoProperties(transcodedVideo240, 240, 'mp4')
-
-      if (!magnetUri) magnetUri = originalVideo.magnetUri
-      else expect(originalVideo.magnetUri).to.equal(magnetUri)
     }
   })
 
   it('Should run a import job on video 2 with the same resolution and the same extension', async function () {
-    const env = getEnvCli(servers[0])
-    await execCLI(`${env} npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short2.webm`)
+    const command = `npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short2.webm`
+    await servers[0].cliCommand.execWithEnv(command)
 
     await waitJobs(servers)
 
-    let magnetUri: string
     for (const server of servers) {
       const { data: videos } = (await getVideosList(server.url)).body
       expect(videos).to.have.lengthOf(2)
@@ -124,9 +113,6 @@ describe('Test create import video jobs', function () {
       const [ video720, video480 ] = videoDetail.files
       assertVideoProperties(video720, 720, 'webm', 942961)
       assertVideoProperties(video480, 480, 'webm', 69217)
-
-      if (!magnetUri) magnetUri = video720.magnetUri
-      else expect(video720.magnetUri).to.equal(magnetUri)
     }
   })