1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { VideoFile } from '@shared/models/videos/video-file.model'
10 flushAndRunMultipleServers,
15 setAccessTokensToServers,
17 } from '../../../shared/extra-utils'
18 import { waitJobs } from '../../../shared/extra-utils/server/jobs'
19 import { VideoDetails } from '../../../shared/models/videos'
21 const expect = chai.expect
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)
30 if (size) expect(video.size).to.equal(size)
33 describe('Test create import video jobs', function () {
36 let servers: ServerInfo[] = []
37 let video1UUID: string
38 let video2UUID: string
40 before(async function () {
43 // Run server 2 to have transcoding enabled
44 servers = await flushAndRunMultipleServers(2)
45 await setAccessTokensToServers(servers)
47 await doubleFollow(servers[0], servers[1])
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
56 await waitJobs(servers)
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`)
63 await waitJobs(servers)
65 for (const server of servers) {
66 const { data: videos } = (await getVideosList(server.url)).body
67 expect(videos).to.have.lengthOf(2)
69 const video = videos.find(({ uuid }) => uuid === video1UUID)
70 const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body
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)
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`)
83 await waitJobs(servers)
85 for (const server of servers) {
86 const { data: videos } = (await getVideosList(server.url)).body
87 expect(videos).to.have.lengthOf(2)
89 const video = videos.find(({ uuid }) => uuid === video2UUID)
90 const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body
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')
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`)
105 await waitJobs(servers)
107 for (const server of servers) {
108 const { data: videos } = (await getVideosList(server.url)).body
109 expect(videos).to.have.lengthOf(2)
111 const video = videos.find(({ uuid }) => uuid === video1UUID)
112 const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body
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)
121 after(async function () {
122 await cleanupTests(servers)