import 'mocha'
import * as chai from 'chai'
import { VideoDetails } from '../../../shared/models/videos'
-const expect = chai.expect
-
import {
+ doubleFollow,
execCLI,
+ flushAndRunMultipleServers,
flushTests,
getEnvCli,
+ getVideo,
getVideosList,
killallServers,
- parseTorrentVideo,
- runServer,
ServerInfo,
setAccessTokensToServers,
- uploadVideo,
- wait,
- getVideo, flushAndRunMultipleServers, doubleFollow
-} from '../utils'
+ uploadVideo, wait
+} from '../../../shared/utils'
+import { waitJobs } from '../../../shared/utils/server/jobs'
+
+const expect = chai.expect
describe('Test create transcoding jobs', function () {
let servers: ServerInfo[] = []
+ let video1UUID: string
let video2UUID: string
before(async function () {
await doubleFollow(servers[0], servers[1])
// Upload two videos for our needs
- await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video1' })
- const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video2' })
- video2UUID = res.body.video.uuid
+ const res1 = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video1' })
+ video1UUID = res1.body.video.uuid
+ const res2 = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video2' })
+ video2UUID = res2.body.video.uuid
- await wait(3000)
+ await waitJobs(servers)
})
it('Should have two video files on each server', async function () {
const env = getEnvCli(servers[0])
await execCLI(`${env} npm run create-transcoding-job -- -v ${video2UUID}`)
- await wait(30000)
+ await waitJobs(servers)
for (const server of servers) {
const res = await getVideosList(server.url)
const videos = res.body.data
expect(videos).to.have.lengthOf(2)
+ let infoHashes: { [ id: number ]: string }
+
for (const video of videos) {
const res2 = await getVideo(server.url, video.uuid)
const videoDetail: VideoDetails = res2.body
if (video.uuid === video2UUID) {
expect(videoDetail.files).to.have.lengthOf(4)
+
+ if (!infoHashes) {
+ infoHashes = {}
+
+ for (const file of videoDetail.files) {
+ infoHashes[file.resolution.id.toString()] = file.magnetUri
+ }
+ } else {
+ for (const resolution of Object.keys(infoHashes)) {
+ const file = videoDetail.files.find(f => f.resolution.id.toString() === resolution)
+ expect(file.magnetUri).to.equal(infoHashes[resolution])
+ }
+ }
} else {
expect(videoDetail.files).to.have.lengthOf(1)
}
}
})
- after(async function () {
- killallServers(servers)
+ it('Should run a transcoding job on video 1 with resolution', async function () {
+ this.timeout(60000)
+
+ const env = getEnvCli(servers[0])
+ await execCLI(`${env} npm run create-transcoding-job -- -v ${video1UUID} -r 480`)
+
+ await waitJobs(servers)
- // Keep the logs if the test failed
- if (this['ok']) {
- await flushTests()
+ for (const server of servers) {
+ const res = await getVideosList(server.url)
+ const videos = res.body.data
+ expect(videos).to.have.lengthOf(2)
+
+ const res2 = await getVideo(server.url, video1UUID)
+ const videoDetail: VideoDetails = res2.body
+
+ expect(videoDetail.files).to.have.lengthOf(2)
+
+ expect(videoDetail.files[0].resolution.id).to.equal(720)
+
+ expect(videoDetail.files[1].resolution.id).to.equal(480)
}
})
+
+ after(async function () {
+ killallServers(servers)
+ })
})