]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/videos/video-create-transcoding.ts
Move test functions outside extra-utils
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-create-transcoding.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
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'
8 import {
9 cleanupTests,
10 createMultipleServers,
11 doubleFollow,
12 expectNoFailedTranscodingJob,
13 makeRawRequest,
14 ObjectStorageCommand,
15 PeerTubeServer,
16 setAccessTokensToServers,
17 waitJobs
18 } from '@shared/server-commands'
19
20 const expect = chai.expect
21
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)
26 }
27
28 for (const file of video.streamingPlaylists[0].files) {
29 expectStartWith(file.fileUrl, ObjectStorageCommand.getPlaylistBaseUrl())
30 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
31 }
32 }
33
34 function runTests (objectStorage: boolean) {
35 let servers: PeerTubeServer[] = []
36 let videoUUID: string
37 let publishedAt: string
38
39 before(async function () {
40 this.timeout(120000)
41
42 const config = objectStorage
43 ? ObjectStorageCommand.getDefaultConfig()
44 : {}
45
46 // Run server 2 to have transcoding enabled
47 servers = await createMultipleServers(2, config)
48 await setAccessTokensToServers(servers)
49
50 await servers[0].config.disableTranscoding()
51
52 await doubleFollow(servers[0], servers[1])
53
54 if (objectStorage) await ObjectStorageCommand.prepareDefaultBuckets()
55
56 const { shortUUID } = await servers[0].videos.quickUpload({ name: 'video' })
57 videoUUID = shortUUID
58
59 await waitJobs(servers)
60
61 const video = await servers[0].videos.get({ id: videoUUID })
62 publishedAt = video.publishedAt as string
63
64 await servers[0].config.enableTranscoding()
65 })
66
67 it('Should generate HLS', async function () {
68 this.timeout(60000)
69
70 await servers[0].videos.runTranscoding({
71 videoId: videoUUID,
72 transcodingType: 'hls'
73 })
74
75 await waitJobs(servers)
76 await expectNoFailedTranscodingJob(servers[0])
77
78 for (const server of servers) {
79 const videoDetails = await server.videos.get({ id: videoUUID })
80
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)
84
85 if (objectStorage) await checkFilesInObjectStorage(videoDetails)
86 }
87 })
88
89 it('Should generate WebTorrent', async function () {
90 this.timeout(60000)
91
92 await servers[0].videos.runTranscoding({
93 videoId: videoUUID,
94 transcodingType: 'webtorrent'
95 })
96
97 await waitJobs(servers)
98
99 for (const server of servers) {
100 const videoDetails = await server.videos.get({ id: videoUUID })
101
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)
105
106 if (objectStorage) await checkFilesInObjectStorage(videoDetails)
107 }
108 })
109
110 it('Should generate WebTorrent from HLS only video', async function () {
111 this.timeout(60000)
112
113 await servers[0].videos.removeWebTorrentFiles({ videoId: videoUUID })
114 await waitJobs(servers)
115
116 await servers[0].videos.runTranscoding({ videoId: videoUUID, transcodingType: 'webtorrent' })
117 await waitJobs(servers)
118
119 for (const server of servers) {
120 const videoDetails = await server.videos.get({ id: videoUUID })
121
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)
125
126 if (objectStorage) await checkFilesInObjectStorage(videoDetails)
127 }
128 })
129
130 it('Should not have updated published at attributes', async function () {
131 const video = await servers[0].videos.get({ id: videoUUID })
132
133 expect(video.publishedAt).to.equal(publishedAt)
134 })
135
136 after(async function () {
137 await cleanupTests(servers)
138 })
139 }
140
141 describe('Test create transcoding jobs from API', function () {
142
143 describe('On filesystem', function () {
144 runTests(false)
145 })
146
147 describe('On object storage', function () {
148 if (areObjectStorageTestsDisabled()) return
149
150 runTests(true)
151 })
152 })