]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/cli/create-import-video-file-job.ts
Merge branch 'release/3.3.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / cli / create-import-video-file-job.ts
index 8a23a94decaf556242a59933e67a6ee8afff0b2f..bddcff5e70590ba3e1c549ad4fc2f948b3643e1f 100644 (file)
@@ -2,19 +2,8 @@
 
 import 'mocha'
 import * as chai from 'chai'
-import { VideoFile } from '@shared/models/videos/video-file.model'
-import {
-  cleanupTests,
-  doubleFollow,
-  flushAndRunMultipleServers,
-  getVideo,
-  getVideosList,
-  ServerInfo,
-  setAccessTokensToServers,
-  uploadVideo
-} from '../../../shared/extra-utils'
-import { waitJobs } from '../../../shared/extra-utils/server/jobs'
-import { VideoDetails } from '../../../shared/models/videos'
+import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
+import { VideoFile } from '@shared/models'
 
 const expect = chai.expect
 
@@ -31,7 +20,7 @@ function assertVideoProperties (video: VideoFile, resolution: number, extname: s
 describe('Test create import video jobs', function () {
   this.timeout(60000)
 
-  let servers: ServerInfo[] = []
+  let servers: PeerTubeServer[] = []
   let video1UUID: string
   let video2UUID: string
 
@@ -39,16 +28,21 @@ describe('Test create import video jobs', function () {
     this.timeout(90000)
 
     // Run server 2 to have transcoding enabled
-    servers = await flushAndRunMultipleServers(2)
+    servers = await createMultipleServers(2)
     await setAccessTokensToServers(servers)
 
     await doubleFollow(servers[0], servers[1])
 
     // Upload two videos for our needs
-    const res1 = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video1' })
-    video1UUID = res1.body.video.uuid
-    const res2 = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' })
-    video2UUID = res2.body.video.uuid
+    {
+      const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video1' } })
+      video1UUID = uuid
+    }
+
+    {
+      const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video2' } })
+      video2UUID = uuid
+    }
 
     // Transcoding
     await waitJobs(servers)
@@ -56,19 +50,19 @@ describe('Test create import video jobs', function () {
 
   it('Should run a import job on video 1 with a lower resolution', async function () {
     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 servers[0].cli.execWithEnv(command)
 
     await waitJobs(servers)
 
     for (const server of servers) {
-      const { data: videos } = (await getVideosList(server.url)).body
+      const { data: videos } = await server.videos.list()
       expect(videos).to.have.lengthOf(2)
 
       const video = videos.find(({ uuid }) => uuid === video1UUID)
-      const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body
+      const videoDetails = await server.videos.get({ id: video.uuid })
 
-      expect(videoDetail.files).to.have.lengthOf(2)
-      const [ originalVideo, transcodedVideo ] = videoDetail.files
+      expect(videoDetails.files).to.have.lengthOf(2)
+      const [ originalVideo, transcodedVideo ] = videoDetails.files
       assertVideoProperties(originalVideo, 720, 'webm', 218910)
       assertVideoProperties(transcodedVideo, 480, 'webm', 69217)
     }
@@ -76,19 +70,19 @@ describe('Test create import video jobs', function () {
 
   it('Should run a import job on video 2 with the same resolution and a different extension', async function () {
     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 servers[1].cli.execWithEnv(command)
 
     await waitJobs(servers)
 
     for (const server of servers) {
-      const { data: videos } = (await getVideosList(server.url)).body
+      const { data: videos } = await server.videos.list()
       expect(videos).to.have.lengthOf(2)
 
       const video = videos.find(({ uuid }) => uuid === video2UUID)
-      const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body
+      const videoDetails = await server.videos.get({ id: video.uuid })
 
-      expect(videoDetail.files).to.have.lengthOf(4)
-      const [ originalVideo, transcodedVideo420, transcodedVideo320, transcodedVideo240 ] = videoDetail.files
+      expect(videoDetails.files).to.have.lengthOf(4)
+      const [ originalVideo, transcodedVideo420, transcodedVideo320, transcodedVideo240 ] = videoDetails.files
       assertVideoProperties(originalVideo, 720, 'ogv', 140849)
       assertVideoProperties(transcodedVideo420, 480, 'mp4')
       assertVideoProperties(transcodedVideo320, 360, 'mp4')
@@ -98,19 +92,19 @@ describe('Test create import video jobs', function () {
 
   it('Should run a import job on video 2 with the same resolution and the same extension', async function () {
     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 servers[0].cli.execWithEnv(command)
 
     await waitJobs(servers)
 
     for (const server of servers) {
-      const { data: videos } = (await getVideosList(server.url)).body
+      const { data: videos } = await server.videos.list()
       expect(videos).to.have.lengthOf(2)
 
       const video = videos.find(({ uuid }) => uuid === video1UUID)
-      const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body
+      const videoDetails = await server.videos.get({ id: video.uuid })
 
-      expect(videoDetail.files).to.have.lengthOf(2)
-      const [ video720, video480 ] = videoDetail.files
+      expect(videoDetails.files).to.have.lengthOf(2)
+      const [ video720, video480 ] = videoDetails.files
       assertVideoProperties(video720, 720, 'webm', 942961)
       assertVideoProperties(video480, 480, 'webm', 69217)
     }