]>
Commit | Line | Data |
---|---|---|
0c948c16 C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import { VideoDetails } from '../../../shared/models/videos' | |
0c948c16 | 6 | import { |
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 |
94565d52 C |
18 | } from '../../../shared/extra-utils' |
19 | import { waitJobs } from '../../../shared/extra-utils/server/jobs' | |
3cd0734f C |
20 | |
21 | const expect = chai.expect | |
0c948c16 C |
22 | |
23 | describe('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 | ||
0c948c16 C |
31 | // Run server 2 to have transcoding enabled |
32 | servers = await flushAndRunMultipleServers(2) | |
33 | await setAccessTokensToServers(servers) | |
34 | ||
35 | await doubleFollow(servers[0], servers[1]) | |
36 | ||
37 | // Upload two videos for our needs | |
05623b90 F |
38 | const res1 = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video1' }) |
39 | video1UUID = res1.body.video.uuid | |
40 | const res2 = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video2' }) | |
41 | video2UUID = res2.body.video.uuid | |
0c948c16 | 42 | |
3cd0734f | 43 | await waitJobs(servers) |
0c948c16 C |
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 | ||
3cd0734f | 68 | await waitJobs(servers) |
0c948c16 C |
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 | ||
04bf312c C |
75 | let infoHashes: { [ id: number ]: string } |
76 | ||
0c948c16 C |
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) | |
04bf312c C |
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 | } | |
0c948c16 C |
96 | } else { |
97 | expect(videoDetail.files).to.have.lengthOf(1) | |
98 | } | |
99 | } | |
100 | } | |
101 | }) | |
102 | ||
05623b90 F |
103 | it('Should run a transcoding job on video 1 with resolution', async function () { |
104 | this.timeout(60000) | |
105 | ||
106 | const env = getEnvCli(servers[0]) | |
107 | await execCLI(`${env} npm run create-transcoding-job -- -v ${video1UUID} -r 480`) | |
108 | ||
109 | await waitJobs(servers) | |
110 | ||
111 | for (const server of servers) { | |
112 | const res = await getVideosList(server.url) | |
113 | const videos = res.body.data | |
114 | expect(videos).to.have.lengthOf(2) | |
115 | ||
116 | const res2 = await getVideo(server.url, video1UUID) | |
117 | const videoDetail: VideoDetails = res2.body | |
118 | ||
119 | expect(videoDetail.files).to.have.lengthOf(2) | |
120 | ||
121 | expect(videoDetail.files[0].resolution.id).to.equal(720) | |
122 | ||
123 | expect(videoDetail.files[1].resolution.id).to.equal(480) | |
124 | } | |
125 | }) | |
126 | ||
210feb6c | 127 | after(function () { |
0c948c16 | 128 | killallServers(servers) |
0c948c16 C |
129 | }) |
130 | }) |