]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/tests/cli/create-import-video-file-job.ts
Merge branch 'next' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / cli / create-import-video-file-job.ts
... / ...
CommitLineData
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import * as chai from 'chai'
5import {
6 areObjectStorageTestsDisabled,
7 cleanupTests,
8 createMultipleServers,
9 doubleFollow,
10 expectStartWith,
11 makeRawRequest,
12 ObjectStorageCommand,
13 PeerTubeServer,
14 setAccessTokensToServers,
15 waitJobs
16} from '@shared/extra-utils'
17import { HttpStatusCode, VideoDetails, VideoFile } from '@shared/models'
18
19const expect = chai.expect
20
21function 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
31async function checkFiles (video: VideoDetails, objectStorage: boolean) {
32 for (const file of video.files) {
33 if (objectStorage) expectStartWith(file.fileUrl, ObjectStorageCommand.getWebTorrentBaseUrl())
34
35 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
36 }
37}
38
39function runTests (objectStorage: boolean) {
40 let video1ShortId: string
41 let video2UUID: string
42
43 let servers: PeerTubeServer[] = []
44
45 before(async function () {
46 this.timeout(90000)
47
48 const config = objectStorage
49 ? ObjectStorageCommand.getDefaultConfig()
50 : {}
51
52 // Run server 2 to have transcoding enabled
53 servers = await createMultipleServers(2, config)
54 await setAccessTokensToServers(servers)
55
56 await doubleFollow(servers[0], servers[1])
57
58 if (objectStorage) await ObjectStorageCommand.prepareDefaultBuckets()
59
60 // Upload two videos for our needs
61 {
62 const { shortUUID } = await servers[0].videos.upload({ attributes: { name: 'video1' } })
63 video1ShortId = shortUUID
64 }
65
66 {
67 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video2' } })
68 video2UUID = uuid
69 }
70
71 await waitJobs(servers)
72 })
73
74 it('Should run a import job on video 1 with a lower resolution', async function () {
75 const command = `npm run create-import-video-file-job -- -v ${video1ShortId} -i server/tests/fixtures/video_short-480.webm`
76 await servers[0].cli.execWithEnv(command)
77
78 await waitJobs(servers)
79
80 for (const server of servers) {
81 const { data: videos } = await server.videos.list()
82 expect(videos).to.have.lengthOf(2)
83
84 const video = videos.find(({ shortUUID }) => shortUUID === video1ShortId)
85 const videoDetails = await server.videos.get({ id: video.shortUUID })
86
87 expect(videoDetails.files).to.have.lengthOf(2)
88 const [ originalVideo, transcodedVideo ] = videoDetails.files
89 assertVideoProperties(originalVideo, 720, 'webm', 218910)
90 assertVideoProperties(transcodedVideo, 480, 'webm', 69217)
91
92 await checkFiles(videoDetails, objectStorage)
93 }
94 })
95
96 it('Should run a import job on video 2 with the same resolution and a different extension', async function () {
97 const command = `npm run create-import-video-file-job -- -v ${video2UUID} -i server/tests/fixtures/video_short.ogv`
98 await servers[1].cli.execWithEnv(command)
99
100 await waitJobs(servers)
101
102 for (const server of servers) {
103 const { data: videos } = await server.videos.list()
104 expect(videos).to.have.lengthOf(2)
105
106 const video = videos.find(({ uuid }) => uuid === video2UUID)
107 const videoDetails = await server.videos.get({ id: video.uuid })
108
109 expect(videoDetails.files).to.have.lengthOf(4)
110 const [ originalVideo, transcodedVideo420, transcodedVideo320, transcodedVideo240 ] = videoDetails.files
111 assertVideoProperties(originalVideo, 720, 'ogv', 140849)
112 assertVideoProperties(transcodedVideo420, 480, 'mp4')
113 assertVideoProperties(transcodedVideo320, 360, 'mp4')
114 assertVideoProperties(transcodedVideo240, 240, 'mp4')
115
116 await checkFiles(videoDetails, objectStorage)
117 }
118 })
119
120 it('Should run a import job on video 2 with the same resolution and the same extension', async function () {
121 const command = `npm run create-import-video-file-job -- -v ${video1ShortId} -i server/tests/fixtures/video_short2.webm`
122 await servers[0].cli.execWithEnv(command)
123
124 await waitJobs(servers)
125
126 for (const server of servers) {
127 const { data: videos } = await server.videos.list()
128 expect(videos).to.have.lengthOf(2)
129
130 const video = videos.find(({ shortUUID }) => shortUUID === video1ShortId)
131 const videoDetails = await server.videos.get({ id: video.uuid })
132
133 expect(videoDetails.files).to.have.lengthOf(2)
134 const [ video720, video480 ] = videoDetails.files
135 assertVideoProperties(video720, 720, 'webm', 942961)
136 assertVideoProperties(video480, 480, 'webm', 69217)
137
138 await checkFiles(videoDetails, objectStorage)
139 }
140 })
141
142 after(async function () {
143 await cleanupTests(servers)
144 })
145}
146
147describe('Test create import video jobs', function () {
148
149 describe('On filesystem', function () {
150 runTests(false)
151 })
152
153 describe('On object storage', function () {
154 if (areObjectStorageTestsDisabled()) return
155
156 runTests(true)
157 })
158})