]>
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' | |
90a8bd30 | 5 | import { VideoFile } from '@shared/models/videos/video-file.model' |
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' | |
90a8bd30 | 19 | import { VideoDetails } from '../../../shared/models/videos' |
0138af92 | 20 | |
28be8916 C |
21 | const expect = chai.expect |
22 | ||
23 | function assertVideoProperties (video: VideoFile, resolution: number, extname: string, size?: number) { | |
0138af92 | 24 | expect(video).to.have.nested.property('resolution.id', resolution) |
0138af92 FF |
25 | expect(video).to.have.property('torrentUrl').that.includes(`-${resolution}.torrent`) |
26 | expect(video).to.have.property('fileUrl').that.includes(`.${extname}`) | |
2451916e | 27 | expect(video).to.have.property('magnetUri').that.includes(`.${extname}`) |
0138af92 | 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 FF |
64 | |
65 | for (const server of servers) { | |
66 | const { data: videos } = (await getVideosList(server.url)).body | |
67 | expect(videos).to.have.lengthOf(2) | |
68 | ||
0138af92 FF |
69 | const video = videos.find(({ uuid }) => uuid === video1UUID) |
70 | const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body | |
71 | ||
72 | expect(videoDetail.files).to.have.lengthOf(2) | |
a1587156 | 73 | const [ originalVideo, transcodedVideo ] = videoDetail.files |
6ccdf3a2 C |
74 | assertVideoProperties(originalVideo, 720, 'webm', 218910) |
75 | assertVideoProperties(transcodedVideo, 480, 'webm', 69217) | |
0138af92 FF |
76 | } |
77 | }) | |
78 | ||
6ccdf3a2 | 79 | it('Should run a import job on video 2 with the same resolution and a different extension', async function () { |
0138af92 | 80 | const env = getEnvCli(servers[1]) |
99d10301 | 81 | await execCLI(`${env} npm run create-import-video-file-job -- -v ${video2UUID} -i server/tests/fixtures/video_short.ogv`) |
0138af92 | 82 | |
3cd0734f | 83 | await waitJobs(servers) |
0138af92 | 84 | |
6ccdf3a2 | 85 | for (const server of servers) { |
0138af92 FF |
86 | const { data: videos } = (await getVideosList(server.url)).body |
87 | expect(videos).to.have.lengthOf(2) | |
88 | ||
0138af92 FF |
89 | const video = videos.find(({ uuid }) => uuid === video2UUID) |
90 | const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body | |
91 | ||
92 | expect(videoDetail.files).to.have.lengthOf(4) | |
a1587156 | 93 | const [ originalVideo, transcodedVideo420, transcodedVideo320, transcodedVideo240 ] = videoDetail.files |
28be8916 | 94 | assertVideoProperties(originalVideo, 720, 'ogv', 140849) |
0138af92 FF |
95 | assertVideoProperties(transcodedVideo420, 480, 'mp4') |
96 | assertVideoProperties(transcodedVideo320, 360, 'mp4') | |
97 | assertVideoProperties(transcodedVideo240, 240, 'mp4') | |
98 | } | |
99 | }) | |
100 | ||
6ccdf3a2 C |
101 | it('Should run a import job on video 2 with the same resolution and the same extension', async function () { |
102 | const env = getEnvCli(servers[0]) | |
103 | await execCLI(`${env} npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short2.webm`) | |
104 | ||
3cd0734f | 105 | await waitJobs(servers) |
6ccdf3a2 | 106 | |
6ccdf3a2 C |
107 | for (const server of servers) { |
108 | const { data: videos } = (await getVideosList(server.url)).body | |
109 | expect(videos).to.have.lengthOf(2) | |
110 | ||
111 | const video = videos.find(({ uuid }) => uuid === video1UUID) | |
112 | const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body | |
113 | ||
114 | expect(videoDetail.files).to.have.lengthOf(2) | |
115 | const [ video720, video480 ] = videoDetail.files | |
116 | assertVideoProperties(video720, 720, 'webm', 942961) | |
117 | assertVideoProperties(video480, 480, 'webm', 69217) | |
6ccdf3a2 C |
118 | } |
119 | }) | |
120 | ||
7c3b7976 C |
121 | after(async function () { |
122 | await cleanupTests(servers) | |
0138af92 FF |
123 | }) |
124 | }) |