1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
6 import { VideoFile } from '@shared/models'
8 const expect = chai.expect
10 function assertVideoProperties (video: VideoFile, resolution: number, extname: string, size?: number) {
11 expect(video).to.have.nested.property('resolution.id', resolution)
12 expect(video).to.have.property('torrentUrl').that.includes(`-${resolution}.torrent`)
13 expect(video).to.have.property('fileUrl').that.includes(`.${extname}`)
14 expect(video).to.have.property('magnetUri').that.includes(`.${extname}`)
15 expect(video).to.have.property('size').that.is.above(0)
17 if (size) expect(video.size).to.equal(size)
20 describe('Test create import video jobs', function () {
23 let servers: PeerTubeServer[] = []
24 let video1UUID: string
25 let video2UUID: string
27 before(async function () {
30 // Run server 2 to have transcoding enabled
31 servers = await createMultipleServers(2)
32 await setAccessTokensToServers(servers)
34 await doubleFollow(servers[0], servers[1])
36 // Upload two videos for our needs
38 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video1' } })
43 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video2' } })
48 await waitJobs(servers)
51 it('Should run a import job on video 1 with a lower resolution', async function () {
52 const command = `npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short-480.webm`
53 await servers[0].cli.execWithEnv(command)
55 await waitJobs(servers)
57 for (const server of servers) {
58 const { data: videos } = await server.videos.list()
59 expect(videos).to.have.lengthOf(2)
61 const video = videos.find(({ uuid }) => uuid === video1UUID)
62 const videoDetails = await server.videos.get({ id: video.uuid })
64 expect(videoDetails.files).to.have.lengthOf(2)
65 const [ originalVideo, transcodedVideo ] = videoDetails.files
66 assertVideoProperties(originalVideo, 720, 'webm', 218910)
67 assertVideoProperties(transcodedVideo, 480, 'webm', 69217)
71 it('Should run a import job on video 2 with the same resolution and a different extension', async function () {
72 const command = `npm run create-import-video-file-job -- -v ${video2UUID} -i server/tests/fixtures/video_short.ogv`
73 await servers[1].cli.execWithEnv(command)
75 await waitJobs(servers)
77 for (const server of servers) {
78 const { data: videos } = await server.videos.list()
79 expect(videos).to.have.lengthOf(2)
81 const video = videos.find(({ uuid }) => uuid === video2UUID)
82 const videoDetails = await server.videos.get({ id: video.uuid })
84 expect(videoDetails.files).to.have.lengthOf(4)
85 const [ originalVideo, transcodedVideo420, transcodedVideo320, transcodedVideo240 ] = videoDetails.files
86 assertVideoProperties(originalVideo, 720, 'ogv', 140849)
87 assertVideoProperties(transcodedVideo420, 480, 'mp4')
88 assertVideoProperties(transcodedVideo320, 360, 'mp4')
89 assertVideoProperties(transcodedVideo240, 240, 'mp4')
93 it('Should run a import job on video 2 with the same resolution and the same extension', async function () {
94 const command = `npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short2.webm`
95 await servers[0].cli.execWithEnv(command)
97 await waitJobs(servers)
99 for (const server of servers) {
100 const { data: videos } = await server.videos.list()
101 expect(videos).to.have.lengthOf(2)
103 const video = videos.find(({ uuid }) => uuid === video1UUID)
104 const videoDetails = await server.videos.get({ id: video.uuid })
106 expect(videoDetails.files).to.have.lengthOf(2)
107 const [ video720, video480 ] = videoDetails.files
108 assertVideoProperties(video720, 720, 'webm', 942961)
109 assertVideoProperties(video480, 480, 'webm', 69217)
113 after(async function () {
114 await cleanupTests(servers)