1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
6 areObjectStorageTestsDisabled,
14 setAccessTokensToServers,
16 } from '@shared/extra-utils'
17 import { HttpStatusCode, VideoDetails, VideoFile, VideoInclude } from '@shared/models'
19 const expect = chai.expect
21 function assertVideoProperties (video: VideoFile, resolution: number, extname: string, size?: number) {
22 expect(video).to.have.nested.property('resolution.id', resolution)
23 expect(video).to.have.property('torrentUrl').that.includes(`-${resolution}.torrent`)
24 expect(video).to.have.property('fileUrl').that.includes(`.${extname}`)
25 expect(video).to.have.property('magnetUri').that.includes(`.${extname}`)
26 expect(video).to.have.property('size').that.is.above(0)
28 if (size) expect(video.size).to.equal(size)
31 async function checkFiles (video: VideoDetails, objectStorage: boolean) {
32 for (const file of video.files) {
33 if (objectStorage) expectStartWith(file.fileUrl, ObjectStorageCommand.getWebTorrentBaseUrl())
35 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
39 function runTests (objectStorage: boolean) {
40 let video1ShortId: string
41 let video2UUID: string
43 let servers: PeerTubeServer[] = []
45 before(async function () {
48 const config = objectStorage
49 ? ObjectStorageCommand.getDefaultConfig()
52 // Run server 2 to have transcoding enabled
53 servers = await createMultipleServers(2, config)
54 await setAccessTokensToServers(servers)
56 await doubleFollow(servers[0], servers[1])
58 if (objectStorage) await ObjectStorageCommand.prepareDefaultBuckets()
60 // Upload two videos for our needs
62 const { shortUUID } = await servers[0].videos.upload({ attributes: { name: 'video1' } })
63 video1ShortId = shortUUID
67 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video2' } })
71 await waitJobs(servers)
73 for (const server of servers) {
74 await server.config.enableTranscoding()
78 it('Should run a import job on video 1 with a lower resolution', async function () {
79 const command = `npm run create-import-video-file-job -- -v ${video1ShortId} -i server/tests/fixtures/video_short-480.webm`
80 await servers[0].cli.execWithEnv(command)
82 await waitJobs(servers)
84 for (const server of servers) {
85 const { data: videos } = await server.videos.list()
86 expect(videos).to.have.lengthOf(2)
88 const video = videos.find(({ shortUUID }) => shortUUID === video1ShortId)
89 const videoDetails = await server.videos.get({ id: video.shortUUID })
91 expect(videoDetails.files).to.have.lengthOf(2)
92 const [ originalVideo, transcodedVideo ] = videoDetails.files
93 assertVideoProperties(originalVideo, 720, 'webm', 218910)
94 assertVideoProperties(transcodedVideo, 480, 'webm', 69217)
96 await checkFiles(videoDetails, objectStorage)
100 it('Should run a import job on video 2 with the same resolution and a different extension', async function () {
101 const command = `npm run create-import-video-file-job -- -v ${video2UUID} -i server/tests/fixtures/video_short.ogv`
102 await servers[1].cli.execWithEnv(command)
104 await waitJobs(servers)
106 for (const server of servers) {
107 const { data: videos } = await server.videos.listWithToken({ include: VideoInclude.NOT_PUBLISHED_STATE })
108 expect(videos).to.have.lengthOf(2)
110 const video = videos.find(({ uuid }) => uuid === video2UUID)
111 const videoDetails = await server.videos.get({ id: video.uuid })
113 expect(videoDetails.files).to.have.lengthOf(4)
114 const [ originalVideo, transcodedVideo420, transcodedVideo320, transcodedVideo240 ] = videoDetails.files
115 assertVideoProperties(originalVideo, 720, 'ogv', 140849)
116 assertVideoProperties(transcodedVideo420, 480, 'mp4')
117 assertVideoProperties(transcodedVideo320, 360, 'mp4')
118 assertVideoProperties(transcodedVideo240, 240, 'mp4')
120 await checkFiles(videoDetails, objectStorage)
124 it('Should run a import job on video 2 with the same resolution and the same extension', async function () {
125 const command = `npm run create-import-video-file-job -- -v ${video1ShortId} -i server/tests/fixtures/video_short2.webm`
126 await servers[0].cli.execWithEnv(command)
128 await waitJobs(servers)
130 for (const server of servers) {
131 const { data: videos } = await server.videos.listWithToken({ include: VideoInclude.NOT_PUBLISHED_STATE })
132 expect(videos).to.have.lengthOf(2)
134 const video = videos.find(({ shortUUID }) => shortUUID === video1ShortId)
135 const videoDetails = await server.videos.get({ id: video.uuid })
137 expect(videoDetails.files).to.have.lengthOf(2)
138 const [ video720, video480 ] = videoDetails.files
139 assertVideoProperties(video720, 720, 'webm', 942961)
140 assertVideoProperties(video480, 480, 'webm', 69217)
142 await checkFiles(videoDetails, objectStorage)
146 it('Should not have run transcoding after an import job', async function () {
147 const { data } = await servers[0].jobs.list({ jobType: 'video-transcoding' })
148 expect(data).to.have.lengthOf(0)
151 after(async function () {
152 await cleanupTests(servers)
156 describe('Test create import video jobs', function () {
158 describe('On filesystem', function () {
162 describe('On object storage', function () {
163 if (areObjectStorageTestsDisabled()) return