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
|
|
|
|
2022-08-17 15:44:32 +02:00
|
|
|
import { expect } from 'chai'
|
2022-10-19 10:43:53 +02:00
|
|
|
import { areMockObjectStorageTestsDisabled } from '@shared/core-utils'
|
2021-12-17 11:58:15 +01:00
|
|
|
import { HttpStatusCode, VideoDetails, VideoFile, VideoInclude } from '@shared/models'
|
2021-08-17 08:26:20 +02:00
|
|
|
import {
|
|
|
|
cleanupTests,
|
|
|
|
createMultipleServers,
|
|
|
|
doubleFollow,
|
|
|
|
makeRawRequest,
|
|
|
|
ObjectStorageCommand,
|
|
|
|
PeerTubeServer,
|
|
|
|
setAccessTokensToServers,
|
|
|
|
waitJobs
|
2021-12-17 09:29:23 +01:00
|
|
|
} from '@shared/server-commands'
|
2021-12-17 11:58:15 +01:00
|
|
|
import { expectStartWith } from '../shared'
|
2018-06-02 21:39:41 +02:00
|
|
|
|
2018-06-07 09:43:18 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-08-17 08:26:20 +02:00
|
|
|
async function checkFiles (video: VideoDetails, objectStorage: boolean) {
|
|
|
|
for (const file of video.files) {
|
2022-10-19 10:43:53 +02:00
|
|
|
if (objectStorage) expectStartWith(file.fileUrl, ObjectStorageCommand.getMockWebTorrentBaseUrl())
|
2018-06-02 21:39:41 +02:00
|
|
|
|
2022-10-12 16:09:02 +02:00
|
|
|
await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
|
2021-08-17 08:26:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function runTests (objectStorage: boolean) {
|
2021-08-17 11:06:10 +02:00
|
|
|
let video1ShortId: string
|
2018-06-02 21:39:41 +02:00
|
|
|
let video2UUID: string
|
|
|
|
|
2021-08-17 08:26:20 +02:00
|
|
|
let servers: PeerTubeServer[] = []
|
|
|
|
|
2018-06-02 21:39:41 +02:00
|
|
|
before(async function () {
|
|
|
|
this.timeout(90000)
|
|
|
|
|
2021-08-17 08:26:20 +02:00
|
|
|
const config = objectStorage
|
2022-10-19 10:43:53 +02:00
|
|
|
? ObjectStorageCommand.getDefaultMockConfig()
|
2021-08-17 08:26:20 +02:00
|
|
|
: {}
|
|
|
|
|
2018-06-02 21:39:41 +02:00
|
|
|
// Run server 2 to have transcoding enabled
|
2021-08-17 08:26:20 +02:00
|
|
|
servers = await createMultipleServers(2, config)
|
2018-06-02 21:39:41 +02:00
|
|
|
await setAccessTokensToServers(servers)
|
|
|
|
|
|
|
|
await doubleFollow(servers[0], servers[1])
|
|
|
|
|
2022-10-19 10:43:53 +02:00
|
|
|
if (objectStorage) await ObjectStorageCommand.prepareDefaultMockBuckets()
|
2021-08-17 08:26:20 +02:00
|
|
|
|
2018-06-02 21:39:41 +02:00
|
|
|
// Upload two videos for our needs
|
2021-07-15 10:02:54 +02:00
|
|
|
{
|
2021-08-17 11:06:10 +02:00
|
|
|
const { shortUUID } = await servers[0].videos.upload({ attributes: { name: 'video1' } })
|
|
|
|
video1ShortId = shortUUID
|
2021-07-15 10:02:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2021-07-16 09:04:35 +02:00
|
|
|
const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video2' } })
|
2021-07-15 10:02:54 +02:00
|
|
|
video2UUID = uuid
|
|
|
|
}
|
2018-06-02 21:39:41 +02:00
|
|
|
|
2018-06-13 10:06:50 +02:00
|
|
|
await waitJobs(servers)
|
2021-11-23 15:22:07 +01:00
|
|
|
|
|
|
|
for (const server of servers) {
|
|
|
|
await server.config.enableTranscoding()
|
|
|
|
}
|
2018-06-02 21:39:41 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should run a import job on video 1 with a lower resolution', async function () {
|
2021-08-17 11:06:10 +02:00
|
|
|
const command = `npm run create-import-video-file-job -- -v ${video1ShortId} -i server/tests/fixtures/video_short-480.webm`
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[0].cli.execWithEnv(command)
|
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) {
|
2021-07-16 09:04:35 +02:00
|
|
|
const { data: videos } = await server.videos.list()
|
2018-06-02 21:39:41 +02:00
|
|
|
expect(videos).to.have.lengthOf(2)
|
|
|
|
|
2021-08-17 11:06:10 +02:00
|
|
|
const video = videos.find(({ shortUUID }) => shortUUID === video1ShortId)
|
|
|
|
const videoDetails = await server.videos.get({ id: video.shortUUID })
|
2018-06-02 21:39:41 +02:00
|
|
|
|
2021-07-15 10:02:54 +02:00
|
|
|
expect(videoDetails.files).to.have.lengthOf(2)
|
|
|
|
const [ originalVideo, transcodedVideo ] = videoDetails.files
|
2018-06-11 19:16:00 +02:00
|
|
|
assertVideoProperties(originalVideo, 720, 'webm', 218910)
|
|
|
|
assertVideoProperties(transcodedVideo, 480, 'webm', 69217)
|
2021-08-17 08:26:20 +02:00
|
|
|
|
|
|
|
await checkFiles(videoDetails, objectStorage)
|
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 () {
|
2021-07-05 16:37:50 +02:00
|
|
|
const command = `npm run create-import-video-file-job -- -v ${video2UUID} -i server/tests/fixtures/video_short.ogv`
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[1].cli.execWithEnv(command)
|
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) {
|
2021-11-09 11:52:41 +01:00
|
|
|
const { data: videos } = await server.videos.listWithToken({ include: VideoInclude.NOT_PUBLISHED_STATE })
|
2018-06-02 21:39:41 +02:00
|
|
|
expect(videos).to.have.lengthOf(2)
|
|
|
|
|
|
|
|
const video = videos.find(({ uuid }) => uuid === video2UUID)
|
2021-07-16 09:04:35 +02:00
|
|
|
const videoDetails = await server.videos.get({ id: video.uuid })
|
2018-06-02 21:39:41 +02:00
|
|
|
|
2021-07-15 10:02:54 +02:00
|
|
|
expect(videoDetails.files).to.have.lengthOf(4)
|
|
|
|
const [ originalVideo, transcodedVideo420, transcodedVideo320, transcodedVideo240 ] = videoDetails.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')
|
2021-08-17 08:26:20 +02:00
|
|
|
|
|
|
|
await checkFiles(videoDetails, objectStorage)
|
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 the same extension', async function () {
|
2021-08-17 11:06:10 +02:00
|
|
|
const command = `npm run create-import-video-file-job -- -v ${video1ShortId} -i server/tests/fixtures/video_short2.webm`
|
2021-07-16 09:04:35 +02:00
|
|
|
await servers[0].cli.execWithEnv(command)
|
2018-06-11 19:16:00 +02:00
|
|
|
|
2018-06-13 10:06:50 +02:00
|
|
|
await waitJobs(servers)
|
2018-06-11 19:16:00 +02:00
|
|
|
|
|
|
|
for (const server of servers) {
|
2021-11-09 11:52:41 +01:00
|
|
|
const { data: videos } = await server.videos.listWithToken({ include: VideoInclude.NOT_PUBLISHED_STATE })
|
2018-06-11 19:16:00 +02:00
|
|
|
expect(videos).to.have.lengthOf(2)
|
|
|
|
|
2021-08-17 11:06:10 +02:00
|
|
|
const video = videos.find(({ shortUUID }) => shortUUID === video1ShortId)
|
2021-07-16 09:04:35 +02:00
|
|
|
const videoDetails = await server.videos.get({ id: video.uuid })
|
2018-06-11 19:16:00 +02:00
|
|
|
|
2021-07-15 10:02:54 +02:00
|
|
|
expect(videoDetails.files).to.have.lengthOf(2)
|
|
|
|
const [ video720, video480 ] = videoDetails.files
|
2018-06-11 19:16:00 +02:00
|
|
|
assertVideoProperties(video720, 720, 'webm', 942961)
|
|
|
|
assertVideoProperties(video480, 480, 'webm', 69217)
|
2021-08-17 08:26:20 +02:00
|
|
|
|
|
|
|
await checkFiles(videoDetails, objectStorage)
|
2018-06-11 19:16:00 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-11-23 15:22:07 +01:00
|
|
|
it('Should not have run transcoding after an import job', async function () {
|
|
|
|
const { data } = await servers[0].jobs.list({ jobType: 'video-transcoding' })
|
|
|
|
expect(data).to.have.lengthOf(0)
|
|
|
|
})
|
|
|
|
|
2019-04-24 15:10:37 +02:00
|
|
|
after(async function () {
|
|
|
|
await cleanupTests(servers)
|
2018-06-02 21:39:41 +02:00
|
|
|
})
|
2021-08-17 08:26:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
describe('Test create import video jobs', function () {
|
|
|
|
|
|
|
|
describe('On filesystem', function () {
|
|
|
|
runTests(false)
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('On object storage', function () {
|
2022-10-19 10:43:53 +02:00
|
|
|
if (areMockObjectStorageTestsDisabled()) return
|
2021-08-17 08:26:20 +02:00
|
|
|
|
|
|
|
runTests(true)
|
|
|
|
})
|
2018-06-02 21:39:41 +02:00
|
|
|
})
|