]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/cli/create-transcoding-job.ts
Merge branch 'master' into develop
[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 cleanupTests,
8 doubleFollow,
9 execCLI,
10 flushAndRunMultipleServers,
11 flushTests,
12 getEnvCli,
13 getVideo,
14 getVideosList,
15 killallServers,
16 ServerInfo,
17 setAccessTokensToServers,
18 uploadVideo, wait
19 } from '../../../shared/extra-utils'
20 import { waitJobs } from '../../../shared/extra-utils/server/jobs'
21
22 const expect = chai.expect
23
24 describe('Test create transcoding jobs', function () {
25 let servers: ServerInfo[] = []
26 let video1UUID: string
27 let video2UUID: string
28
29 before(async function () {
30 this.timeout(60000)
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 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
43
44 await waitJobs(servers)
45 })
46
47 it('Should have two video files on each server', async function () {
48 this.timeout(30000)
49
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)
54
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)
59 }
60 }
61 })
62
63 it('Should run a transcoding job on video 2', async function () {
64 this.timeout(60000)
65
66 const env = getEnvCli(servers[0])
67 await execCLI(`${env} npm run create-transcoding-job -- -v ${video2UUID}`)
68
69 await waitJobs(servers)
70
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)
75
76 let infoHashes: { [ id: number ]: string }
77
78 for (const video of videos) {
79 const res2 = await getVideo(server.url, video.uuid)
80 const videoDetail: VideoDetails = res2.body
81
82 if (video.uuid === video2UUID) {
83 expect(videoDetail.files).to.have.lengthOf(4)
84
85 if (!infoHashes) {
86 infoHashes = {}
87
88 for (const file of videoDetail.files) {
89 infoHashes[file.resolution.id.toString()] = file.magnetUri
90 }
91 } else {
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])
95 }
96 }
97 } else {
98 expect(videoDetail.files).to.have.lengthOf(1)
99 }
100 }
101 }
102 })
103
104 it('Should run a transcoding job on video 1 with resolution', async function () {
105 this.timeout(60000)
106
107 const env = getEnvCli(servers[0])
108 await execCLI(`${env} npm run create-transcoding-job -- -v ${video1UUID} -r 480`)
109
110 await waitJobs(servers)
111
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)
116
117 const res2 = await getVideo(server.url, video1UUID)
118 const videoDetail: VideoDetails = res2.body
119
120 expect(videoDetail.files).to.have.lengthOf(2)
121
122 expect(videoDetail.files[0].resolution.id).to.equal(720)
123
124 expect(videoDetail.files[1].resolution.id).to.equal(480)
125 }
126 })
127
128 after(async function () {
129 await cleanupTests(servers)
130 })
131 })