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