]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/cli/create-import-video-file-job.ts
8a23a94decaf556242a59933e67a6ee8afff0b2f
[github/Chocobozzz/PeerTube.git] / server / tests / cli / create-import-video-file-job.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 import { VideoFile } from '@shared/models/videos/video-file.model'
6 import {
7 cleanupTests,
8 doubleFollow,
9 flushAndRunMultipleServers,
10 getVideo,
11 getVideosList,
12 ServerInfo,
13 setAccessTokensToServers,
14 uploadVideo
15 } from '../../../shared/extra-utils'
16 import { waitJobs } from '../../../shared/extra-utils/server/jobs'
17 import { VideoDetails } from '../../../shared/models/videos'
18
19 const expect = chai.expect
20
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)
27
28 if (size) expect(video.size).to.equal(size)
29 }
30
31 describe('Test create import video jobs', function () {
32 this.timeout(60000)
33
34 let servers: ServerInfo[] = []
35 let video1UUID: string
36 let video2UUID: string
37
38 before(async function () {
39 this.timeout(90000)
40
41 // Run server 2 to have transcoding enabled
42 servers = await flushAndRunMultipleServers(2)
43 await setAccessTokensToServers(servers)
44
45 await doubleFollow(servers[0], servers[1])
46
47 // Upload two videos for our needs
48 const res1 = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video1' })
49 video1UUID = res1.body.video.uuid
50 const res2 = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' })
51 video2UUID = res2.body.video.uuid
52
53 // Transcoding
54 await waitJobs(servers)
55 })
56
57 it('Should run a import job on video 1 with a lower resolution', async function () {
58 const command = `npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short-480.webm`
59 await servers[0].cliCommand.execWithEnv(command)
60
61 await waitJobs(servers)
62
63 for (const server of servers) {
64 const { data: videos } = (await getVideosList(server.url)).body
65 expect(videos).to.have.lengthOf(2)
66
67 const video = videos.find(({ uuid }) => uuid === video1UUID)
68 const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body
69
70 expect(videoDetail.files).to.have.lengthOf(2)
71 const [ originalVideo, transcodedVideo ] = videoDetail.files
72 assertVideoProperties(originalVideo, 720, 'webm', 218910)
73 assertVideoProperties(transcodedVideo, 480, 'webm', 69217)
74 }
75 })
76
77 it('Should run a import job on video 2 with the same resolution and a different extension', async function () {
78 const command = `npm run create-import-video-file-job -- -v ${video2UUID} -i server/tests/fixtures/video_short.ogv`
79 await servers[1].cliCommand.execWithEnv(command)
80
81 await waitJobs(servers)
82
83 for (const server of servers) {
84 const { data: videos } = (await getVideosList(server.url)).body
85 expect(videos).to.have.lengthOf(2)
86
87 const video = videos.find(({ uuid }) => uuid === video2UUID)
88 const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body
89
90 expect(videoDetail.files).to.have.lengthOf(4)
91 const [ originalVideo, transcodedVideo420, transcodedVideo320, transcodedVideo240 ] = videoDetail.files
92 assertVideoProperties(originalVideo, 720, 'ogv', 140849)
93 assertVideoProperties(transcodedVideo420, 480, 'mp4')
94 assertVideoProperties(transcodedVideo320, 360, 'mp4')
95 assertVideoProperties(transcodedVideo240, 240, 'mp4')
96 }
97 })
98
99 it('Should run a import job on video 2 with the same resolution and the same extension', async function () {
100 const command = `npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short2.webm`
101 await servers[0].cliCommand.execWithEnv(command)
102
103 await waitJobs(servers)
104
105 for (const server of servers) {
106 const { data: videos } = (await getVideosList(server.url)).body
107 expect(videos).to.have.lengthOf(2)
108
109 const video = videos.find(({ uuid }) => uuid === video1UUID)
110 const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body
111
112 expect(videoDetail.files).to.have.lengthOf(2)
113 const [ video720, video480 ] = videoDetail.files
114 assertVideoProperties(video720, 720, 'webm', 942961)
115 assertVideoProperties(video480, 480, 'webm', 69217)
116 }
117 })
118
119 after(async function () {
120 await cleanupTests(servers)
121 })
122 })