]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/cli/create-import-video-file-job.ts
Merge branch 'release/2.1.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / cli / create-import-video-file-job.ts
index 372c7e51751a8c23ebc3e4951c5486116a0bacec..dac049fe4c3dfeec96c7c7a0c626729a9269f553 100644 (file)
@@ -1,22 +1,22 @@
-/* tslint:disable:no-unused-expression */
+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
 import 'mocha'
 import * as chai from 'chai'
-import { VideoDetails, VideoFile } from '../../../shared/models/videos'
+import { VideoDetails } from '../../../shared/models/videos'
 import {
+  cleanupTests,
   doubleFollow,
   execCLI,
   flushAndRunMultipleServers,
-  flushTests,
   getEnvCli,
   getVideo,
   getVideosList,
-  killallServers,
   ServerInfo,
   setAccessTokensToServers,
-  uploadVideo,
-  wait
-} from '../utils'
+  uploadVideo
+} from '../../../shared/extra-utils'
+import { waitJobs } from '../../../shared/extra-utils/server/jobs'
+import { VideoFile } from '@shared/models/videos/video-file.model'
 
 const expect = chai.expect
 
@@ -39,7 +39,6 @@ describe('Test create import video jobs', function () {
 
   before(async function () {
     this.timeout(90000)
-    await flushTests()
 
     // Run server 2 to have transcoding enabled
     servers = await flushAndRunMultipleServers(2)
@@ -54,14 +53,14 @@ describe('Test create import video jobs', function () {
     video2UUID = res2.body.video.uuid
 
     // Transcoding
-    await wait(40000)
+    await waitJobs(servers)
   })
 
   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`)
 
-    await wait(30000)
+    await waitJobs(servers)
 
     let magnetUri: string
     for (const server of servers) {
@@ -72,23 +71,23 @@ describe('Test create import video jobs', function () {
       const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body
 
       expect(videoDetail.files).to.have.lengthOf(2)
-      const [originalVideo, transcodedVideo] = videoDetail.files
-      assertVideoProperties(originalVideo, 720, 'webm')
-      assertVideoProperties(transcodedVideo, 480, 'webm')
+      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', async function () {
+  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`)
 
-    await wait(30000)
+    await waitJobs(servers)
 
     let magnetUri: string
-    for (const server of servers.reverse()) {
+    for (const server of servers) {
       const { data: videos } = (await getVideosList(server.url)).body
       expect(videos).to.have.lengthOf(2)
 
@@ -96,7 +95,7 @@ describe('Test create import video jobs', function () {
       const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body
 
       expect(videoDetail.files).to.have.lengthOf(4)
-      const [originalVideo, transcodedVideo420, transcodedVideo320, transcodedVideo240] = videoDetail.files
+      const [ originalVideo, transcodedVideo420, transcodedVideo320, transcodedVideo240 ] = videoDetail.files
       assertVideoProperties(originalVideo, 720, 'ogv', 140849)
       assertVideoProperties(transcodedVideo420, 480, 'mp4')
       assertVideoProperties(transcodedVideo320, 360, 'mp4')
@@ -107,12 +106,31 @@ describe('Test create import video jobs', function () {
     }
   })
 
-  after(async function () {
-    killallServers(servers)
+  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`)
+
+    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)
 
-    // Keep the logs if the test failed
-    if (this['ok']) {
-      await flushTests()
+      const video = videos.find(({ uuid }) => uuid === video1UUID)
+      const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body
+
+      expect(videoDetail.files).to.have.lengthOf(2)
+      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)
     }
   })
+
+  after(async function () {
+    await cleanupTests(servers)
+  })
 })