]>
Commit | Line | Data |
---|---|---|
1 | /* tslint:disable:no-unused-expression */ | |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import { VideoDetails, VideoFile } 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 | |
19 | } from '../../../shared/extra-utils' | |
20 | import { waitJobs } from '../../../shared/extra-utils/server/jobs' | |
21 | ||
22 | const expect = chai.expect | |
23 | ||
24 | function assertVideoProperties (video: VideoFile, resolution: number, extname: string, size?: number) { | |
25 | expect(video).to.have.nested.property('resolution.id', resolution) | |
26 | expect(video).to.have.property('magnetUri').that.includes(`.${extname}`) | |
27 | expect(video).to.have.property('torrentUrl').that.includes(`-${resolution}.torrent`) | |
28 | expect(video).to.have.property('fileUrl').that.includes(`.${extname}`) | |
29 | expect(video).to.have.property('size').that.is.above(0) | |
30 | ||
31 | if (size) expect(video.size).to.equal(size) | |
32 | } | |
33 | ||
34 | describe('Test create import video jobs', function () { | |
35 | this.timeout(60000) | |
36 | ||
37 | let servers: ServerInfo[] = [] | |
38 | let video1UUID: string | |
39 | let video2UUID: string | |
40 | ||
41 | before(async function () { | |
42 | this.timeout(90000) | |
43 | ||
44 | // Run server 2 to have transcoding enabled | |
45 | servers = await flushAndRunMultipleServers(2) | |
46 | await setAccessTokensToServers(servers) | |
47 | ||
48 | await doubleFollow(servers[0], servers[1]) | |
49 | ||
50 | // Upload two videos for our needs | |
51 | const res1 = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video1' }) | |
52 | video1UUID = res1.body.video.uuid | |
53 | const res2 = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' }) | |
54 | video2UUID = res2.body.video.uuid | |
55 | ||
56 | // Transcoding | |
57 | await waitJobs(servers) | |
58 | }) | |
59 | ||
60 | it('Should run a import job on video 1 with a lower resolution', async function () { | |
61 | const env = getEnvCli(servers[0]) | |
62 | await execCLI(`${env} npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short-480.webm`) | |
63 | ||
64 | await waitJobs(servers) | |
65 | ||
66 | let magnetUri: string | |
67 | for (const server of servers) { | |
68 | const { data: videos } = (await getVideosList(server.url)).body | |
69 | expect(videos).to.have.lengthOf(2) | |
70 | ||
71 | const video = videos.find(({ uuid }) => uuid === video1UUID) | |
72 | const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body | |
73 | ||
74 | expect(videoDetail.files).to.have.lengthOf(2) | |
75 | const [originalVideo, transcodedVideo] = videoDetail.files | |
76 | assertVideoProperties(originalVideo, 720, 'webm', 218910) | |
77 | assertVideoProperties(transcodedVideo, 480, 'webm', 69217) | |
78 | ||
79 | if (!magnetUri) magnetUri = transcodedVideo.magnetUri | |
80 | else expect(transcodedVideo.magnetUri).to.equal(magnetUri) | |
81 | } | |
82 | }) | |
83 | ||
84 | it('Should run a import job on video 2 with the same resolution and a different extension', async function () { | |
85 | const env = getEnvCli(servers[1]) | |
86 | await execCLI(`${env} npm run create-import-video-file-job -- -v ${video2UUID} -i server/tests/fixtures/video_short.ogv`) | |
87 | ||
88 | await waitJobs(servers) | |
89 | ||
90 | let magnetUri: string | |
91 | for (const server of servers) { | |
92 | const { data: videos } = (await getVideosList(server.url)).body | |
93 | expect(videos).to.have.lengthOf(2) | |
94 | ||
95 | const video = videos.find(({ uuid }) => uuid === video2UUID) | |
96 | const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body | |
97 | ||
98 | expect(videoDetail.files).to.have.lengthOf(4) | |
99 | const [originalVideo, transcodedVideo420, transcodedVideo320, transcodedVideo240] = videoDetail.files | |
100 | assertVideoProperties(originalVideo, 720, 'ogv', 140849) | |
101 | assertVideoProperties(transcodedVideo420, 480, 'mp4') | |
102 | assertVideoProperties(transcodedVideo320, 360, 'mp4') | |
103 | assertVideoProperties(transcodedVideo240, 240, 'mp4') | |
104 | ||
105 | if (!magnetUri) magnetUri = originalVideo.magnetUri | |
106 | else expect(originalVideo.magnetUri).to.equal(magnetUri) | |
107 | } | |
108 | }) | |
109 | ||
110 | it('Should run a import job on video 2 with the same resolution and the same extension', async function () { | |
111 | const env = getEnvCli(servers[0]) | |
112 | await execCLI(`${env} npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short2.webm`) | |
113 | ||
114 | await waitJobs(servers) | |
115 | ||
116 | let magnetUri: string | |
117 | for (const server of servers) { | |
118 | const { data: videos } = (await getVideosList(server.url)).body | |
119 | expect(videos).to.have.lengthOf(2) | |
120 | ||
121 | const video = videos.find(({ uuid }) => uuid === video1UUID) | |
122 | const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body | |
123 | ||
124 | expect(videoDetail.files).to.have.lengthOf(2) | |
125 | const [ video720, video480 ] = videoDetail.files | |
126 | assertVideoProperties(video720, 720, 'webm', 942961) | |
127 | assertVideoProperties(video480, 480, 'webm', 69217) | |
128 | ||
129 | if (!magnetUri) magnetUri = video720.magnetUri | |
130 | else expect(video720.magnetUri).to.equal(magnetUri) | |
131 | } | |
132 | }) | |
133 | ||
134 | after(async function () { | |
135 | await cleanupTests(servers) | |
136 | }) | |
137 | }) |