1 /* tslint:disable:no-unused-expression */
4 import * as chai from 'chai'
5 import { VideoDetails } from '../../../shared/models/videos'
9 flushAndRunMultipleServers,
16 setAccessTokensToServers,
19 import { waitJobs } from '../utils/server/jobs'
21 const expect = chai.expect
23 describe('Test create transcoding jobs', function () {
24 let servers: ServerInfo[] = []
25 let video1UUID: string
26 let video2UUID: string
28 before(async function () {
33 // Run server 2 to have transcoding enabled
34 servers = await flushAndRunMultipleServers(2)
35 await setAccessTokensToServers(servers)
37 await doubleFollow(servers[0], servers[1])
39 // Upload two videos for our needs
40 const res1 = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video1' })
41 video1UUID = res1.body.video.uuid
42 const res2 = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video2' })
43 video2UUID = res2.body.video.uuid
45 await waitJobs(servers)
48 it('Should have two video files on each server', async function () {
51 for (const server of servers) {
52 const res = await getVideosList(server.url)
53 const videos = res.body.data
54 expect(videos).to.have.lengthOf(2)
56 for (const video of videos) {
57 const res2 = await getVideo(server.url, video.uuid)
58 const videoDetail: VideoDetails = res2.body
59 expect(videoDetail.files).to.have.lengthOf(1)
64 it('Should run a transcoding job on video 2', async function () {
67 const env = getEnvCli(servers[0])
68 await execCLI(`${env} npm run create-transcoding-job -- -v ${video2UUID}`)
70 await waitJobs(servers)
72 for (const server of servers) {
73 const res = await getVideosList(server.url)
74 const videos = res.body.data
75 expect(videos).to.have.lengthOf(2)
77 let infoHashes: { [ id: number ]: string }
79 for (const video of videos) {
80 const res2 = await getVideo(server.url, video.uuid)
81 const videoDetail: VideoDetails = res2.body
83 if (video.uuid === video2UUID) {
84 expect(videoDetail.files).to.have.lengthOf(4)
89 for (const file of videoDetail.files) {
90 infoHashes[file.resolution.id.toString()] = file.magnetUri
93 for (const resolution of Object.keys(infoHashes)) {
94 const file = videoDetail.files.find(f => f.resolution.id.toString() === resolution)
95 expect(file.magnetUri).to.equal(infoHashes[resolution])
99 expect(videoDetail.files).to.have.lengthOf(1)
105 it('Should run a transcoding job on video 1 with resolution', async function () {
108 const env = getEnvCli(servers[0])
109 await execCLI(`${env} npm run create-transcoding-job -- -v ${video1UUID} -r 480`)
111 await waitJobs(servers)
113 for (const server of servers) {
114 const res = await getVideosList(server.url)
115 const videos = res.body.data
116 expect(videos).to.have.lengthOf(2)
118 const res2 = await getVideo(server.url, video1UUID)
119 const videoDetail: VideoDetails = res2.body
121 expect(videoDetail.files).to.have.lengthOf(2)
123 expect(videoDetail.files[0].resolution.id).to.equal(720)
125 expect(videoDetail.files[1].resolution.id).to.equal(480)
129 after(async function () {
130 killallServers(servers)