]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/cli/create-transcoding-job.ts
e7c36f9c6243702c4775f05de750daafbdb62c9d
[github/Chocobozzz/PeerTube.git] / server / tests / cli / create-transcoding-job.ts
1 /* tslint:disable:no-unused-expression */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 import { VideoDetails } from '../../../shared/models/videos'
6 import {
7 doubleFollow,
8 execCLI,
9 flushAndRunMultipleServers,
10 flushTests,
11 getEnvCli,
12 getVideo,
13 getVideosList,
14 killallServers,
15 ServerInfo,
16 setAccessTokensToServers,
17 uploadVideo, wait
18 } from '../utils'
19 import { waitJobs } from '../utils/server/jobs'
20
21 const expect = chai.expect
22
23 describe('Test create transcoding jobs', function () {
24 let servers: ServerInfo[] = []
25 let video2UUID: string
26
27 before(async function () {
28 this.timeout(60000)
29
30 await flushTests()
31
32 // Run server 2 to have transcoding enabled
33 servers = await flushAndRunMultipleServers(2)
34 await setAccessTokensToServers(servers)
35
36 await doubleFollow(servers[0], servers[1])
37
38 // Upload two videos for our needs
39 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video1' })
40 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video2' })
41 video2UUID = res.body.video.uuid
42
43 await waitJobs(servers)
44 })
45
46 it('Should have two video files on each server', async function () {
47 this.timeout(30000)
48
49 for (const server of servers) {
50 const res = await getVideosList(server.url)
51 const videos = res.body.data
52 expect(videos).to.have.lengthOf(2)
53
54 for (const video of videos) {
55 const res2 = await getVideo(server.url, video.uuid)
56 const videoDetail: VideoDetails = res2.body
57 expect(videoDetail.files).to.have.lengthOf(1)
58 }
59 }
60 })
61
62 it('Should run a transcoding job on video 2', async function () {
63 this.timeout(60000)
64
65 const env = getEnvCli(servers[0])
66 await execCLI(`${env} npm run create-transcoding-job -- -v ${video2UUID}`)
67
68 await waitJobs(servers)
69
70 for (const server of servers) {
71 const res = await getVideosList(server.url)
72 const videos = res.body.data
73 expect(videos).to.have.lengthOf(2)
74
75 let infoHashes: { [ id: number ]: string }
76
77 for (const video of videos) {
78 const res2 = await getVideo(server.url, video.uuid)
79 const videoDetail: VideoDetails = res2.body
80
81 if (video.uuid === video2UUID) {
82 expect(videoDetail.files).to.have.lengthOf(4)
83
84 if (!infoHashes) {
85 infoHashes = {}
86
87 for (const file of videoDetail.files) {
88 infoHashes[file.resolution.id.toString()] = file.magnetUri
89 }
90 } else {
91 for (const resolution of Object.keys(infoHashes)) {
92 const file = videoDetail.files.find(f => f.resolution.id.toString() === resolution)
93 expect(file.magnetUri).to.equal(infoHashes[resolution])
94 }
95 }
96 } else {
97 expect(videoDetail.files).to.have.lengthOf(1)
98 }
99 }
100 }
101 })
102
103 after(async function () {
104 killallServers(servers)
105 })
106 })