1 /* tslint:disable:no-unused-expression */
4 import * as chai from 'chai'
5 import { VideoDetails } from '../../../shared/models/videos'
10 flushAndRunMultipleServers,
17 setAccessTokensToServers,
19 } from '../../../shared/extra-utils'
20 import { waitJobs } from '../../../shared/extra-utils/server/jobs'
22 const expect = chai.expect
24 describe('Test create transcoding jobs', function () {
25 let servers: ServerInfo[] = []
26 let video1UUID: string
27 let video2UUID: string
29 before(async function () {
32 // Run server 2 to have transcoding enabled
33 servers = await flushAndRunMultipleServers(2)
34 await setAccessTokensToServers(servers)
36 await doubleFollow(servers[0], servers[1])
38 // Upload two videos for our needs
39 const res1 = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video1' })
40 video1UUID = res1.body.video.uuid
41 const res2 = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video2' })
42 video2UUID = res2.body.video.uuid
44 await waitJobs(servers)
47 it('Should have two video files on each server', async function () {
50 for (const server of servers) {
51 const res = await getVideosList(server.url)
52 const videos = res.body.data
53 expect(videos).to.have.lengthOf(2)
55 for (const video of videos) {
56 const res2 = await getVideo(server.url, video.uuid)
57 const videoDetail: VideoDetails = res2.body
58 expect(videoDetail.files).to.have.lengthOf(1)
63 it('Should run a transcoding job on video 2', async function () {
66 const env = getEnvCli(servers[0])
67 await execCLI(`${env} npm run create-transcoding-job -- -v ${video2UUID}`)
69 await waitJobs(servers)
71 for (const server of servers) {
72 const res = await getVideosList(server.url)
73 const videos = res.body.data
74 expect(videos).to.have.lengthOf(2)
76 let infoHashes: { [ id: number ]: string }
78 for (const video of videos) {
79 const res2 = await getVideo(server.url, video.uuid)
80 const videoDetail: VideoDetails = res2.body
82 if (video.uuid === video2UUID) {
83 expect(videoDetail.files).to.have.lengthOf(4)
88 for (const file of videoDetail.files) {
89 infoHashes[file.resolution.id.toString()] = file.magnetUri
92 for (const resolution of Object.keys(infoHashes)) {
93 const file = videoDetail.files.find(f => f.resolution.id.toString() === resolution)
94 expect(file.magnetUri).to.equal(infoHashes[resolution])
98 expect(videoDetail.files).to.have.lengthOf(1)
104 it('Should run a transcoding job on video 1 with resolution', async function () {
107 const env = getEnvCli(servers[0])
108 await execCLI(`${env} npm run create-transcoding-job -- -v ${video1UUID} -r 480`)
110 await waitJobs(servers)
112 for (const server of servers) {
113 const res = await getVideosList(server.url)
114 const videos = res.body.data
115 expect(videos).to.have.lengthOf(2)
117 const res2 = await getVideo(server.url, video1UUID)
118 const videoDetail: VideoDetails = res2.body
120 expect(videoDetail.files).to.have.lengthOf(2)
122 expect(videoDetail.files[0].resolution.id).to.equal(720)
124 expect(videoDetail.files[1].resolution.id).to.equal(480)
128 after(async function () {
129 await cleanupTests(servers)