PeerTube/server/tests/cli/create-import-video-file-jo...

117 lines
4.2 KiB
TypeScript
Raw Normal View History

2020-01-31 09:56:52 -06:00
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import 'mocha'
import * as chai from 'chai'
2021-07-15 03:02:54 -05:00
import { cleanupTests, doubleFollow, flushAndRunMultipleServers, ServerInfo, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
import { VideoFile } from '@shared/models'
const expect = chai.expect
function assertVideoProperties (video: VideoFile, resolution: number, extname: string, size?: number) {
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 02:36:09 -06:00
expect(video).to.have.property('magnetUri').that.includes(`.${extname}`)
expect(video).to.have.property('size').that.is.above(0)
if (size) expect(video.size).to.equal(size)
}
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
2021-07-15 03:02:54 -05:00
{
2021-07-16 02:04:35 -05:00
const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video1' } })
2021-07-15 03:02:54 -05:00
video1UUID = uuid
}
{
2021-07-16 02:04:35 -05:00
const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video2' } })
2021-07-15 03:02:54 -05:00
video2UUID = uuid
}
// Transcoding
await waitJobs(servers)
})
it('Should run a import job on video 1 with a lower resolution', async function () {
2021-07-05 09:37:50 -05:00
const command = `npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short-480.webm`
2021-07-16 02:04:35 -05:00
await servers[0].cli.execWithEnv(command)
await waitJobs(servers)
for (const server of servers) {
2021-07-16 02:04:35 -05:00
const { data: videos } = await server.videos.list()
expect(videos).to.have.lengthOf(2)
const video = videos.find(({ uuid }) => uuid === video1UUID)
2021-07-16 02:04:35 -05:00
const videoDetails = await server.videos.get({ id: video.uuid })
2021-07-15 03:02:54 -05:00
expect(videoDetails.files).to.have.lengthOf(2)
const [ originalVideo, transcodedVideo ] = videoDetails.files
assertVideoProperties(originalVideo, 720, 'webm', 218910)
assertVideoProperties(transcodedVideo, 480, 'webm', 69217)
}
})
it('Should run a import job on video 2 with the same resolution and a different extension', async function () {
2021-07-05 09:37:50 -05:00
const command = `npm run create-import-video-file-job -- -v ${video2UUID} -i server/tests/fixtures/video_short.ogv`
2021-07-16 02:04:35 -05:00
await servers[1].cli.execWithEnv(command)
await waitJobs(servers)
for (const server of servers) {
2021-07-16 02:04:35 -05:00
const { data: videos } = await server.videos.list()
expect(videos).to.have.lengthOf(2)
const video = videos.find(({ uuid }) => uuid === video2UUID)
2021-07-16 02:04:35 -05:00
const videoDetails = await server.videos.get({ id: video.uuid })
2021-07-15 03:02:54 -05:00
expect(videoDetails.files).to.have.lengthOf(4)
const [ originalVideo, transcodedVideo420, transcodedVideo320, transcodedVideo240 ] = videoDetails.files
assertVideoProperties(originalVideo, 720, 'ogv', 140849)
assertVideoProperties(transcodedVideo420, 480, 'mp4')
assertVideoProperties(transcodedVideo320, 360, 'mp4')
assertVideoProperties(transcodedVideo240, 240, 'mp4')
}
})
it('Should run a import job on video 2 with the same resolution and the same extension', async function () {
2021-07-05 09:37:50 -05:00
const command = `npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short2.webm`
2021-07-16 02:04:35 -05:00
await servers[0].cli.execWithEnv(command)
await waitJobs(servers)
for (const server of servers) {
2021-07-16 02:04:35 -05:00
const { data: videos } = await server.videos.list()
expect(videos).to.have.lengthOf(2)
const video = videos.find(({ uuid }) => uuid === video1UUID)
2021-07-16 02:04:35 -05:00
const videoDetails = await server.videos.get({ id: video.uuid })
2021-07-15 03:02:54 -05:00
expect(videoDetails.files).to.have.lengthOf(2)
const [ video720, video480 ] = videoDetails.files
assertVideoProperties(video720, 720, 'webm', 942961)
assertVideoProperties(video480, 480, 'webm', 69217)
}
})
2019-04-24 08:10:37 -05:00
after(async function () {
await cleanupTests(servers)
})
})