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