]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/cli/create-transcoding-job.ts
Add tests when getting a blacklisted video
[github/Chocobozzz/PeerTube.git] / server / tests / cli / create-transcoding-job.ts
CommitLineData
0c948c16
C
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
4import * as chai from 'chai'
5import { VideoDetails } from '../../../shared/models/videos'
0c948c16 6import {
3cd0734f 7 doubleFollow,
0c948c16 8 execCLI,
3cd0734f 9 flushAndRunMultipleServers,
0c948c16
C
10 flushTests,
11 getEnvCli,
3cd0734f 12 getVideo,
0c948c16
C
13 getVideosList,
14 killallServers,
0c948c16
C
15 ServerInfo,
16 setAccessTokensToServers,
3cd0734f 17 uploadVideo, wait
0c948c16 18} from '../utils'
3cd0734f
C
19import { waitJobs } from '../utils/server/jobs'
20
21const expect = chai.expect
0c948c16
C
22
23describe('Test create transcoding jobs', function () {
24 let servers: ServerInfo[] = []
05623b90 25 let video1UUID: string
0c948c16
C
26 let video2UUID: string
27
28 before(async function () {
29 this.timeout(60000)
30
31 await flushTests()
32
33 // Run server 2 to have transcoding enabled
34 servers = await flushAndRunMultipleServers(2)
35 await setAccessTokensToServers(servers)
36
37 await doubleFollow(servers[0], servers[1])
38
39 // Upload two videos for our needs
05623b90
F
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
0c948c16 44
3cd0734f 45 await waitJobs(servers)
0c948c16
C
46 })
47
48 it('Should have two video files on each server', async function () {
49 this.timeout(30000)
50
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)
55
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)
60 }
61 }
62 })
63
64 it('Should run a transcoding job on video 2', async function () {
65 this.timeout(60000)
66
67 const env = getEnvCli(servers[0])
68 await execCLI(`${env} npm run create-transcoding-job -- -v ${video2UUID}`)
69
3cd0734f 70 await waitJobs(servers)
0c948c16
C
71
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)
76
04bf312c
C
77 let infoHashes: { [ id: number ]: string }
78
0c948c16
C
79 for (const video of videos) {
80 const res2 = await getVideo(server.url, video.uuid)
81 const videoDetail: VideoDetails = res2.body
82
83 if (video.uuid === video2UUID) {
84 expect(videoDetail.files).to.have.lengthOf(4)
04bf312c
C
85
86 if (!infoHashes) {
87 infoHashes = {}
88
89 for (const file of videoDetail.files) {
90 infoHashes[file.resolution.id.toString()] = file.magnetUri
91 }
92 } else {
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])
96 }
97 }
0c948c16
C
98 } else {
99 expect(videoDetail.files).to.have.lengthOf(1)
100 }
101 }
102 }
103 })
104
05623b90
F
105 it('Should run a transcoding job on video 1 with resolution', async function () {
106 this.timeout(60000)
107
108 const env = getEnvCli(servers[0])
109 await execCLI(`${env} npm run create-transcoding-job -- -v ${video1UUID} -r 480`)
110
111 await waitJobs(servers)
112
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)
117
118 const res2 = await getVideo(server.url, video1UUID)
119 const videoDetail: VideoDetails = res2.body
120
121 expect(videoDetail.files).to.have.lengthOf(2)
122
123 expect(videoDetail.files[0].resolution.id).to.equal(720)
124
125 expect(videoDetail.files[1].resolution.id).to.equal(480)
126 }
127 })
128
0c948c16
C
129 after(async function () {
130 killallServers(servers)
0c948c16
C
131 })
132})