2020-01-31 16:56:52 +01:00
|
|
|
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
2018-06-02 21:39:41 +02:00
|
|
|
|
|
|
|
import 'mocha'
|
|
|
|
import * as chai from 'chai'
|
2021-02-16 16:25:53 +01:00
|
|
|
import { VideoFile } from '@shared/models/videos/video-file.model'
|
2018-06-02 21:39:41 +02:00
|
|
|
import {
|
2019-04-24 15:10:37 +02:00
|
|
|
cleanupTests,
|
2018-06-07 09:43:18 +02:00
|
|
|
doubleFollow,
|
2018-06-02 21:39:41 +02:00
|
|
|
execCLI,
|
2018-06-07 09:43:18 +02:00
|
|
|
flushAndRunMultipleServers,
|
2018-06-02 21:39:41 +02:00
|
|
|
getEnvCli,
|
2018-06-07 09:43:18 +02:00
|
|
|
getVideo,
|
2018-06-02 21:39:41 +02:00
|
|
|
getVideosList,
|
|
|
|
ServerInfo,
|
|
|
|
setAccessTokensToServers,
|
2018-06-13 10:06:50 +02:00
|
|
|
uploadVideo
|
2019-04-15 15:26:15 +02:00
|
|
|
} from '../../../shared/extra-utils'
|
|
|
|
import { waitJobs } from '../../../shared/extra-utils/server/jobs'
|
2021-02-16 16:25:53 +01:00
|
|
|
import { VideoDetails } from '../../../shared/models/videos'
|
2018-06-02 21:39:41 +02:00
|
|
|
|
2018-06-07 09:43:18 +02:00
|
|
|
const expect = chai.expect
|
|
|
|
|
|
|
|
function assertVideoProperties (video: VideoFile, resolution: number, extname: string, size?: number) {
|
2018-06-02 21:39:41 +02:00
|
|
|
expect(video).to.have.nested.property('resolution.id', resolution)
|
|
|
|
expect(video).to.have.property('torrentUrl').that.includes(`-${resolution}.torrent`)
|
|
|
|
expect(video).to.have.property('fileUrl').that.includes(`.${extname}`)
|
2021-02-17 09:36:09 +01:00
|
|
|
expect(video).to.have.property('magnetUri').that.includes(`.${extname}`)
|
2018-06-02 21:39:41 +02:00
|
|
|
expect(video).to.have.property('size').that.is.above(0)
|
2018-06-07 09:43:18 +02:00
|
|
|
|
|
|
|
if (size) expect(video.size).to.equal(size)
|
2018-06-02 21:39:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
describe('Test create import video jobs', function () {
|
|
|
|
this.timeout(60000)
|
|
|
|
|
|
|
|
let servers: ServerInfo[] = []
|
|
|
|
let video1UUID: string
|
|
|
|
let video2UUID: string
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
this.timeout(90000)
|
|
|
|
|
|
|
|
// Run server 2 to have transcoding enabled
|
|
|
|
servers = await flushAndRunMultipleServers(2)
|
|
|
|
await setAccessTokensToServers(servers)
|
|
|
|
|
|
|
|
await doubleFollow(servers[0], servers[1])
|
|
|
|
|
|
|
|
// Upload two videos for our needs
|
|
|
|
const res1 = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video1' })
|
|
|
|
video1UUID = res1.body.video.uuid
|
|
|
|
const res2 = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' })
|
|
|
|
video2UUID = res2.body.video.uuid
|
|
|
|
|
2018-06-07 09:43:18 +02:00
|
|
|
// Transcoding
|
2018-06-13 10:06:50 +02:00
|
|
|
await waitJobs(servers)
|
2018-06-02 21:39:41 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should run a import job on video 1 with a lower resolution', async function () {
|
|
|
|
const env = getEnvCli(servers[0])
|
2018-06-07 09:48:10 +02:00
|
|
|
await execCLI(`${env} npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short-480.webm`)
|
2018-06-02 21:39:41 +02:00
|
|
|
|
2018-06-13 10:06:50 +02:00
|
|
|
await waitJobs(servers)
|
2018-06-02 21:39:41 +02:00
|
|
|
|
|
|
|
for (const server of servers) {
|
|
|
|
const { data: videos } = (await getVideosList(server.url)).body
|
|
|
|
expect(videos).to.have.lengthOf(2)
|
|
|
|
|
|
|
|
const video = videos.find(({ uuid }) => uuid === video1UUID)
|
|
|
|
const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body
|
|
|
|
|
|
|
|
expect(videoDetail.files).to.have.lengthOf(2)
|
2020-01-31 16:56:52 +01:00
|
|
|
const [ originalVideo, transcodedVideo ] = videoDetail.files
|
2018-06-11 19:16:00 +02:00
|
|
|
assertVideoProperties(originalVideo, 720, 'webm', 218910)
|
|
|
|
assertVideoProperties(transcodedVideo, 480, 'webm', 69217)
|
2018-06-02 21:39:41 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-06-11 19:16:00 +02:00
|
|
|
it('Should run a import job on video 2 with the same resolution and a different extension', async function () {
|
2018-06-02 21:39:41 +02:00
|
|
|
const env = getEnvCli(servers[1])
|
2018-06-07 09:48:10 +02:00
|
|
|
await execCLI(`${env} npm run create-import-video-file-job -- -v ${video2UUID} -i server/tests/fixtures/video_short.ogv`)
|
2018-06-02 21:39:41 +02:00
|
|
|
|
2018-06-13 10:06:50 +02:00
|
|
|
await waitJobs(servers)
|
2018-06-02 21:39:41 +02:00
|
|
|
|
2018-06-11 19:16:00 +02:00
|
|
|
for (const server of servers) {
|
2018-06-02 21:39:41 +02:00
|
|
|
const { data: videos } = (await getVideosList(server.url)).body
|
|
|
|
expect(videos).to.have.lengthOf(2)
|
|
|
|
|
|
|
|
const video = videos.find(({ uuid }) => uuid === video2UUID)
|
|
|
|
const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body
|
|
|
|
|
|
|
|
expect(videoDetail.files).to.have.lengthOf(4)
|
2020-01-31 16:56:52 +01:00
|
|
|
const [ originalVideo, transcodedVideo420, transcodedVideo320, transcodedVideo240 ] = videoDetail.files
|
2018-06-07 09:43:18 +02:00
|
|
|
assertVideoProperties(originalVideo, 720, 'ogv', 140849)
|
2018-06-02 21:39:41 +02:00
|
|
|
assertVideoProperties(transcodedVideo420, 480, 'mp4')
|
|
|
|
assertVideoProperties(transcodedVideo320, 360, 'mp4')
|
|
|
|
assertVideoProperties(transcodedVideo240, 240, 'mp4')
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-06-11 19:16:00 +02:00
|
|
|
it('Should run a import job on video 2 with the same resolution and the same extension', async function () {
|
|
|
|
const env = getEnvCli(servers[0])
|
|
|
|
await execCLI(`${env} npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short2.webm`)
|
|
|
|
|
2018-06-13 10:06:50 +02:00
|
|
|
await waitJobs(servers)
|
2018-06-11 19:16:00 +02:00
|
|
|
|
|
|
|
for (const server of servers) {
|
|
|
|
const { data: videos } = (await getVideosList(server.url)).body
|
|
|
|
expect(videos).to.have.lengthOf(2)
|
|
|
|
|
|
|
|
const video = videos.find(({ uuid }) => uuid === video1UUID)
|
|
|
|
const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body
|
|
|
|
|
|
|
|
expect(videoDetail.files).to.have.lengthOf(2)
|
|
|
|
const [ video720, video480 ] = videoDetail.files
|
|
|
|
assertVideoProperties(video720, 720, 'webm', 942961)
|
|
|
|
assertVideoProperties(video480, 480, 'webm', 69217)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-04-24 15:10:37 +02:00
|
|
|
after(async function () {
|
|
|
|
await cleanupTests(servers)
|
2018-06-02 21:39:41 +02:00
|
|
|
})
|
|
|
|
})
|