]>
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 { |
7c3b7976 | 7 | cleanupTests, |
3cd0734f | 8 | doubleFollow, |
0c948c16 | 9 | execCLI, |
3cd0734f | 10 | flushAndRunMultipleServers, |
0c948c16 C |
11 | flushTests, |
12 | getEnvCli, | |
3cd0734f | 13 | getVideo, |
0c948c16 C |
14 | getVideosList, |
15 | killallServers, | |
0c948c16 C |
16 | ServerInfo, |
17 | setAccessTokensToServers, | |
3cd0734f | 18 | uploadVideo, wait |
94565d52 C |
19 | } from '../../../shared/extra-utils' |
20 | import { waitJobs } from '../../../shared/extra-utils/server/jobs' | |
3cd0734f C |
21 | |
22 | const expect = chai.expect | |
0c948c16 C |
23 | |
24 | describe('Test create transcoding jobs', function () { | |
25 | let servers: ServerInfo[] = [] | |
05623b90 | 26 | let video1UUID: string |
0c948c16 C |
27 | let video2UUID: string |
28 | ||
29 | before(async function () { | |
30 | this.timeout(60000) | |
31 | ||
0c948c16 C |
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 | |
05623b90 F |
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 | |
0c948c16 | 43 | |
3cd0734f | 44 | await waitJobs(servers) |
0c948c16 C |
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 | ||
3cd0734f | 69 | await waitJobs(servers) |
0c948c16 C |
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 | ||
04bf312c C |
76 | let infoHashes: { [ id: number ]: string } |
77 | ||
0c948c16 C |
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) | |
04bf312c C |
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 | } | |
0c948c16 C |
97 | } else { |
98 | expect(videoDetail.files).to.have.lengthOf(1) | |
99 | } | |
100 | } | |
101 | } | |
102 | }) | |
103 | ||
05623b90 F |
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 | ||
7c3b7976 C |
128 | after(async function () { |
129 | await cleanupTests(servers) | |
0c948c16 C |
130 | }) |
131 | }) |