1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { expectStartWith } from '@server/tests/shared'
6 import { areObjectStorageTestsDisabled } from '@shared/core-utils'
7 import { HttpStatusCode, VideoDetails } from '@shared/models'
10 createMultipleServers,
12 expectNoFailedTranscodingJob,
16 setAccessTokensToServers,
18 } from '@shared/server-commands'
20 const expect = chai.expect
22 async function checkFilesInObjectStorage (video: VideoDetails) {
23 for (const file of video.files) {
24 expectStartWith(file.fileUrl, ObjectStorageCommand.getWebTorrentBaseUrl())
25 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
28 const streamingPlaylistFiles = video.streamingPlaylists.length === 0
30 : video.streamingPlaylists[0].files
32 for (const file of streamingPlaylistFiles) {
33 expectStartWith(file.fileUrl, ObjectStorageCommand.getPlaylistBaseUrl())
34 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
38 function runTests (objectStorage: boolean) {
39 let servers: PeerTubeServer[] = []
41 let publishedAt: string
43 before(async function () {
46 const config = objectStorage
47 ? ObjectStorageCommand.getDefaultConfig()
50 // Run server 2 to have transcoding enabled
51 servers = await createMultipleServers(2, config)
52 await setAccessTokensToServers(servers)
54 await servers[0].config.disableTranscoding()
56 await doubleFollow(servers[0], servers[1])
58 if (objectStorage) await ObjectStorageCommand.prepareDefaultBuckets()
60 const { shortUUID } = await servers[0].videos.quickUpload({ name: 'video' })
63 await waitJobs(servers)
65 const video = await servers[0].videos.get({ id: videoUUID })
66 publishedAt = video.publishedAt as string
68 await servers[0].config.enableTranscoding()
71 it('Should generate HLS', async function () {
74 await servers[0].videos.runTranscoding({
76 transcodingType: 'hls'
79 await waitJobs(servers)
80 await expectNoFailedTranscodingJob(servers[0])
82 for (const server of servers) {
83 const videoDetails = await server.videos.get({ id: videoUUID })
85 expect(videoDetails.files).to.have.lengthOf(1)
86 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
87 expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5)
89 if (objectStorage) await checkFilesInObjectStorage(videoDetails)
93 it('Should generate WebTorrent', async function () {
96 await servers[0].videos.runTranscoding({
98 transcodingType: 'webtorrent'
101 await waitJobs(servers)
103 for (const server of servers) {
104 const videoDetails = await server.videos.get({ id: videoUUID })
106 expect(videoDetails.files).to.have.lengthOf(5)
107 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
108 expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5)
110 if (objectStorage) await checkFilesInObjectStorage(videoDetails)
114 it('Should generate WebTorrent from HLS only video', async function () {
117 await servers[0].videos.removeWebTorrentFiles({ videoId: videoUUID })
118 await waitJobs(servers)
120 await servers[0].videos.runTranscoding({ videoId: videoUUID, transcodingType: 'webtorrent' })
121 await waitJobs(servers)
123 for (const server of servers) {
124 const videoDetails = await server.videos.get({ id: videoUUID })
126 expect(videoDetails.files).to.have.lengthOf(5)
127 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
128 expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5)
130 if (objectStorage) await checkFilesInObjectStorage(videoDetails)
134 it('Should only generate WebTorrent', async function () {
137 await servers[0].videos.removeHLSFiles({ videoId: videoUUID })
138 await waitJobs(servers)
140 await servers[0].videos.runTranscoding({ videoId: videoUUID, transcodingType: 'webtorrent' })
141 await waitJobs(servers)
143 for (const server of servers) {
144 const videoDetails = await server.videos.get({ id: videoUUID })
146 expect(videoDetails.files).to.have.lengthOf(5)
147 expect(videoDetails.streamingPlaylists).to.have.lengthOf(0)
149 if (objectStorage) await checkFilesInObjectStorage(videoDetails)
153 it('Should not have updated published at attributes', async function () {
154 const video = await servers[0].videos.get({ id: videoUUID })
156 expect(video.publishedAt).to.equal(publishedAt)
159 after(async function () {
160 await cleanupTests(servers)
164 describe('Test create transcoding jobs from API', function () {
166 describe('On filesystem', function () {
170 describe('On object storage', function () {
171 if (areObjectStorageTestsDisabled()) return