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