1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
6 areObjectStorageTestsDisabled,
14 setAccessTokensToServers,
16 } from '@shared/extra-utils'
17 import { HttpStatusCode, VideoDetails } from '@shared/models'
19 const expect = chai.expect
21 async function checkFilesInObjectStorage (video: VideoDetails) {
22 for (const file of video.files) {
23 expectStartWith(file.fileUrl, ObjectStorageCommand.getWebTorrentBaseUrl())
24 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
27 for (const file of video.streamingPlaylists[0].files) {
28 expectStartWith(file.fileUrl, ObjectStorageCommand.getPlaylistBaseUrl())
29 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
33 async function expectNoFailedTranscodingJob (server: PeerTubeServer) {
34 const { data } = await server.jobs.listFailed({ jobType: 'video-transcoding' })
35 expect(data).to.have.lengthOf(0)
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 not have updated published at attributes', async function () {
135 const video = await servers[0].videos.get({ id: videoUUID })
137 expect(video.publishedAt).to.equal(publishedAt)
140 after(async function () {
141 await cleanupTests(servers)
145 describe('Test create transcoding jobs from API', function () {
147 describe('On filesystem', function () {
151 describe('On object storage', function () {
152 if (areObjectStorageTestsDisabled()) return