]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/cli/create-import-video-file-job.ts
Prevent object storage mock conflicts
[github/Chocobozzz/PeerTube.git] / server / tests / cli / create-import-video-file-job.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
0138af92 2
86347717 3import { expect } from 'chai'
9ab330b9 4import { areMockObjectStorageTestsDisabled } from '@shared/core-utils'
c55e3d72 5import { HttpStatusCode, VideoDetails, VideoFile, VideoInclude } from '@shared/models'
0305db28 6import {
0305db28
JB
7 cleanupTests,
8 createMultipleServers,
9 doubleFollow,
0305db28
JB
10 makeRawRequest,
11 ObjectStorageCommand,
12 PeerTubeServer,
13 setAccessTokensToServers,
14 waitJobs
bf54587a 15} from '@shared/server-commands'
c55e3d72 16import { expectStartWith } from '../shared'
0138af92 17
28be8916 18function assertVideoProperties (video: VideoFile, resolution: number, extname: string, size?: number) {
0138af92 19 expect(video).to.have.nested.property('resolution.id', resolution)
0138af92
FF
20 expect(video).to.have.property('torrentUrl').that.includes(`-${resolution}.torrent`)
21 expect(video).to.have.property('fileUrl').that.includes(`.${extname}`)
2451916e 22 expect(video).to.have.property('magnetUri').that.includes(`.${extname}`)
0138af92 23 expect(video).to.have.property('size').that.is.above(0)
28be8916
C
24
25 if (size) expect(video.size).to.equal(size)
0138af92
FF
26}
27
f8918990 28async function checkFiles (video: VideoDetails, objectStorage: ObjectStorageCommand) {
0305db28 29 for (const file of video.files) {
f8918990 30 if (objectStorage) expectStartWith(file.fileUrl, objectStorage.getMockWebVideosBaseUrl())
0138af92 31
3545e72c 32 await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
0305db28
JB
33 }
34}
35
f8918990 36function runTests (enableObjectStorage: boolean) {
c186a67f 37 let video1ShortId: string
0138af92
FF
38 let video2UUID: string
39
0305db28
JB
40 let servers: PeerTubeServer[] = []
41
f8918990
C
42 const objectStorage = new ObjectStorageCommand()
43
0138af92
FF
44 before(async function () {
45 this.timeout(90000)
0138af92 46
f8918990
C
47 const config = enableObjectStorage
48 ? objectStorage.getDefaultMockConfig()
0305db28
JB
49 : {}
50
0138af92 51 // Run server 2 to have transcoding enabled
0305db28 52 servers = await createMultipleServers(2, config)
0138af92
FF
53 await setAccessTokensToServers(servers)
54
55 await doubleFollow(servers[0], servers[1])
56
f8918990 57 if (enableObjectStorage) await objectStorage.prepareDefaultMockBuckets()
0305db28 58
0138af92 59 // Upload two videos for our needs
d23dd9fb 60 {
c186a67f
C
61 const { shortUUID } = await servers[0].videos.upload({ attributes: { name: 'video1' } })
62 video1ShortId = shortUUID
d23dd9fb
C
63 }
64
65 {
89d241a7 66 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video2' } })
d23dd9fb
C
67 video2UUID = uuid
68 }
0138af92 69
3cd0734f 70 await waitJobs(servers)
842a1573
C
71
72 for (const server of servers) {
73 await server.config.enableTranscoding()
74 }
0138af92
FF
75 })
76
77 it('Should run a import job on video 1 with a lower resolution', async function () {
3a0c2a77 78 const command = `npm run create-import-video-file-job -- -v ${video1ShortId} -i server/tests/fixtures/video_short_480.webm`
89d241a7 79 await servers[0].cli.execWithEnv(command)
0138af92 80
3cd0734f 81 await waitJobs(servers)
0138af92
FF
82
83 for (const server of servers) {
89d241a7 84 const { data: videos } = await server.videos.list()
0138af92
FF
85 expect(videos).to.have.lengthOf(2)
86
c186a67f
C
87 const video = videos.find(({ shortUUID }) => shortUUID === video1ShortId)
88 const videoDetails = await server.videos.get({ id: video.shortUUID })
0138af92 89
d23dd9fb
C
90 expect(videoDetails.files).to.have.lengthOf(2)
91 const [ originalVideo, transcodedVideo ] = videoDetails.files
6ccdf3a2
C
92 assertVideoProperties(originalVideo, 720, 'webm', 218910)
93 assertVideoProperties(transcodedVideo, 480, 'webm', 69217)
0305db28 94
f8918990 95 await checkFiles(videoDetails, enableObjectStorage && objectStorage)
0138af92
FF
96 }
97 })
98
6ccdf3a2 99 it('Should run a import job on video 2 with the same resolution and a different extension', async function () {
329619b3 100 const command = `npm run create-import-video-file-job -- -v ${video2UUID} -i server/tests/fixtures/video_short.ogv`
89d241a7 101 await servers[1].cli.execWithEnv(command)
0138af92 102
3cd0734f 103 await waitJobs(servers)
0138af92 104
6ccdf3a2 105 for (const server of servers) {
221ee1ad 106 const { data: videos } = await server.videos.listWithToken({ include: VideoInclude.NOT_PUBLISHED_STATE })
0138af92
FF
107 expect(videos).to.have.lengthOf(2)
108
0138af92 109 const video = videos.find(({ uuid }) => uuid === video2UUID)
89d241a7 110 const videoDetails = await server.videos.get({ id: video.uuid })
0138af92 111
d23dd9fb
C
112 expect(videoDetails.files).to.have.lengthOf(4)
113 const [ originalVideo, transcodedVideo420, transcodedVideo320, transcodedVideo240 ] = videoDetails.files
28be8916 114 assertVideoProperties(originalVideo, 720, 'ogv', 140849)
0138af92
FF
115 assertVideoProperties(transcodedVideo420, 480, 'mp4')
116 assertVideoProperties(transcodedVideo320, 360, 'mp4')
117 assertVideoProperties(transcodedVideo240, 240, 'mp4')
0305db28 118
f8918990 119 await checkFiles(videoDetails, enableObjectStorage && objectStorage)
0138af92
FF
120 }
121 })
122
6ccdf3a2 123 it('Should run a import job on video 2 with the same resolution and the same extension', async function () {
c186a67f 124 const command = `npm run create-import-video-file-job -- -v ${video1ShortId} -i server/tests/fixtures/video_short2.webm`
89d241a7 125 await servers[0].cli.execWithEnv(command)
6ccdf3a2 126
3cd0734f 127 await waitJobs(servers)
6ccdf3a2 128
6ccdf3a2 129 for (const server of servers) {
221ee1ad 130 const { data: videos } = await server.videos.listWithToken({ include: VideoInclude.NOT_PUBLISHED_STATE })
6ccdf3a2
C
131 expect(videos).to.have.lengthOf(2)
132
c186a67f 133 const video = videos.find(({ shortUUID }) => shortUUID === video1ShortId)
89d241a7 134 const videoDetails = await server.videos.get({ id: video.uuid })
6ccdf3a2 135
d23dd9fb
C
136 expect(videoDetails.files).to.have.lengthOf(2)
137 const [ video720, video480 ] = videoDetails.files
6ccdf3a2
C
138 assertVideoProperties(video720, 720, 'webm', 942961)
139 assertVideoProperties(video480, 480, 'webm', 69217)
0305db28 140
f8918990 141 await checkFiles(videoDetails, enableObjectStorage && objectStorage)
6ccdf3a2
C
142 }
143 })
144
842a1573
C
145 it('Should not have run transcoding after an import job', async function () {
146 const { data } = await servers[0].jobs.list({ jobType: 'video-transcoding' })
147 expect(data).to.have.lengthOf(0)
148 })
149
7c3b7976 150 after(async function () {
f8918990
C
151 await objectStorage.cleanupMock()
152
7c3b7976 153 await cleanupTests(servers)
0138af92 154 })
0305db28
JB
155}
156
157describe('Test create import video jobs', function () {
158
159 describe('On filesystem', function () {
160 runTests(false)
161 })
162
163 describe('On object storage', function () {
9ab330b9 164 if (areMockObjectStorageTestsDisabled()) return
0305db28
JB
165
166 runTests(true)
167 })
0138af92 168})