]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import { VideoFile } from '@shared/models/videos/video-file.model' | |
6 | import { | |
7 | cleanupTests, | |
8 | doubleFollow, | |
9 | execCLI, | |
10 | flushAndRunMultipleServers, | |
11 | getEnvCli, | |
12 | getVideo, | |
13 | getVideosList, | |
14 | ServerInfo, | |
15 | setAccessTokensToServers, | |
16 | uploadVideo | |
17 | } from '../../../shared/extra-utils' | |
18 | import { waitJobs } from '../../../shared/extra-utils/server/jobs' | |
19 | import { VideoDetails } from '../../../shared/models/videos' | |
20 | ||
21 | const expect = chai.expect | |
22 | ||
23 | function assertVideoProperties (video: VideoFile, resolution: number, extname: string, size?: number) { | |
24 | expect(video).to.have.nested.property('resolution.id', resolution) | |
25 | expect(video).to.have.property('torrentUrl').that.includes(`-${resolution}.torrent`) | |
26 | expect(video).to.have.property('fileUrl').that.includes(`.${extname}`) | |
27 | expect(video).to.have.property('magnetUri').that.includes(`.${extname}`) | |
28 | expect(video).to.have.property('size').that.is.above(0) | |
29 | ||
30 | if (size) expect(video.size).to.equal(size) | |
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) | |
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 | ||
55 | // Transcoding | |
56 | await waitJobs(servers) | |
57 | }) | |
58 | ||
59 | it('Should run a import job on video 1 with a lower resolution', async function () { | |
60 | const env = getEnvCli(servers[0]) | |
61 | await execCLI(`${env} npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short-480.webm`) | |
62 | ||
63 | await waitJobs(servers) | |
64 | ||
65 | for (const server of servers) { | |
66 | const { data: videos } = (await getVideosList(server.url)).body | |
67 | expect(videos).to.have.lengthOf(2) | |
68 | ||
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) | |
73 | const [ originalVideo, transcodedVideo ] = videoDetail.files | |
74 | assertVideoProperties(originalVideo, 720, 'webm', 218910) | |
75 | assertVideoProperties(transcodedVideo, 480, 'webm', 69217) | |
76 | } | |
77 | }) | |
78 | ||
79 | it('Should run a import job on video 2 with the same resolution and a different extension', async function () { | |
80 | const env = getEnvCli(servers[1]) | |
81 | await execCLI(`${env} npm run create-import-video-file-job -- -v ${video2UUID} -i server/tests/fixtures/video_short.ogv`) | |
82 | ||
83 | await waitJobs(servers) | |
84 | ||
85 | for (const server of servers) { | |
86 | const { data: videos } = (await getVideosList(server.url)).body | |
87 | expect(videos).to.have.lengthOf(2) | |
88 | ||
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) | |
93 | const [ originalVideo, transcodedVideo420, transcodedVideo320, transcodedVideo240 ] = videoDetail.files | |
94 | assertVideoProperties(originalVideo, 720, 'ogv', 140849) | |
95 | assertVideoProperties(transcodedVideo420, 480, 'mp4') | |
96 | assertVideoProperties(transcodedVideo320, 360, 'mp4') | |
97 | assertVideoProperties(transcodedVideo240, 240, 'mp4') | |
98 | } | |
99 | }) | |
100 | ||
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 | ||
105 | await waitJobs(servers) | |
106 | ||
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) | |
118 | } | |
119 | }) | |
120 | ||
121 | after(async function () { | |
122 | await cleanupTests(servers) | |
123 | }) | |
124 | }) |