1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
6 areObjectStorageTestsDisabled,
10 expectNoFailedTranscodingJob,
15 setAccessTokensToServers,
17 } from '@shared/extra-utils'
18 import { HttpStatusCode, VideoDetails } from '@shared/models'
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 for (const file of video.streamingPlaylists[0].files) {
29 expectStartWith(file.fileUrl, ObjectStorageCommand.getPlaylistBaseUrl())
30 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
34 function runTests (objectStorage: boolean) {
35 let servers: PeerTubeServer[] = []
37 let publishedAt: string
39 before(async function () {
42 const config = objectStorage
43 ? ObjectStorageCommand.getDefaultConfig()
46 // Run server 2 to have transcoding enabled
47 servers = await createMultipleServers(2, config)
48 await setAccessTokensToServers(servers)
50 await servers[0].config.disableTranscoding()
52 await doubleFollow(servers[0], servers[1])
54 if (objectStorage) await ObjectStorageCommand.prepareDefaultBuckets()
56 const { shortUUID } = await servers[0].videos.quickUpload({ name: 'video' })
59 await waitJobs(servers)
61 const video = await servers[0].videos.get({ id: videoUUID })
62 publishedAt = video.publishedAt as string
64 await servers[0].config.enableTranscoding()
67 it('Should generate HLS', async function () {
70 await servers[0].videos.runTranscoding({
72 transcodingType: 'hls'
75 await waitJobs(servers)
76 await expectNoFailedTranscodingJob(servers[0])
78 for (const server of servers) {
79 const videoDetails = await server.videos.get({ id: videoUUID })
81 expect(videoDetails.files).to.have.lengthOf(1)
82 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
83 expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5)
85 if (objectStorage) await checkFilesInObjectStorage(videoDetails)
89 it('Should generate WebTorrent', async function () {
92 await servers[0].videos.runTranscoding({
94 transcodingType: 'webtorrent'
97 await waitJobs(servers)
99 for (const server of servers) {
100 const videoDetails = await server.videos.get({ id: videoUUID })
102 expect(videoDetails.files).to.have.lengthOf(5)
103 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
104 expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5)
106 if (objectStorage) await checkFilesInObjectStorage(videoDetails)
110 it('Should generate WebTorrent from HLS only video', async function () {
113 await servers[0].videos.removeWebTorrentFiles({ videoId: videoUUID })
114 await waitJobs(servers)
116 await servers[0].videos.runTranscoding({ videoId: videoUUID, transcodingType: 'webtorrent' })
117 await waitJobs(servers)
119 for (const server of servers) {
120 const videoDetails = await server.videos.get({ id: videoUUID })
122 expect(videoDetails.files).to.have.lengthOf(5)
123 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
124 expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(5)
126 if (objectStorage) await checkFilesInObjectStorage(videoDetails)
130 it('Should not have updated published at attributes', async function () {
131 const video = await servers[0].videos.get({ id: videoUUID })
133 expect(video.publishedAt).to.equal(publishedAt)
136 after(async function () {
137 await cleanupTests(servers)
141 describe('Test create transcoding jobs from API', function () {
143 describe('On filesystem', function () {
147 describe('On object storage', function () {
148 if (areObjectStorageTestsDisabled()) return