1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
4 import { expectStartWith, FIXTURE_URLS } from '@server/tests/shared'
5 import { areObjectStorageTestsDisabled } from '@shared/core-utils'
6 import { HttpStatusCode, VideoPrivacy } from '@shared/models'
13 setAccessTokensToServers,
14 setDefaultVideoChannel,
16 } from '@shared/server-commands'
18 const expect = chai.expect
20 async function importVideo (server: PeerTubeServer) {
23 privacy: VideoPrivacy.PUBLIC,
24 channelId: server.store.channel.id,
25 targetUrl: FIXTURE_URLS.goodVideo720
28 const { video: { uuid } } = await server.imports.importVideo({ attributes })
33 describe('Object storage for video import', function () {
34 if (areObjectStorageTestsDisabled()) return
36 let server: PeerTubeServer
38 before(async function () {
41 await ObjectStorageCommand.prepareDefaultBuckets()
43 server = await createSingleServer(1, ObjectStorageCommand.getDefaultConfig())
45 await setAccessTokensToServers([ server ])
46 await setDefaultVideoChannel([ server ])
48 await server.config.enableImports()
51 describe('Without transcoding', async function () {
53 before(async function () {
54 await server.config.disableTranscoding()
57 it('Should import a video and have sent it to object storage', async function () {
60 const uuid = await importVideo(server)
61 await waitJobs(server)
63 const video = await server.videos.get({ id: uuid })
65 expect(video.files).to.have.lengthOf(1)
66 expect(video.streamingPlaylists).to.have.lengthOf(0)
68 const fileUrl = video.files[0].fileUrl
69 expectStartWith(fileUrl, ObjectStorageCommand.getWebTorrentBaseUrl())
71 await makeRawRequest(fileUrl, HttpStatusCode.OK_200)
75 describe('With transcoding', async function () {
77 before(async function () {
78 await server.config.enableTranscoding()
81 it('Should import a video and have sent it to object storage', async function () {
84 const uuid = await importVideo(server)
85 await waitJobs(server)
87 const video = await server.videos.get({ id: uuid })
89 expect(video.files).to.have.lengthOf(5)
90 expect(video.streamingPlaylists).to.have.lengthOf(1)
91 expect(video.streamingPlaylists[0].files).to.have.lengthOf(5)
93 for (const file of video.files) {
94 expectStartWith(file.fileUrl, ObjectStorageCommand.getWebTorrentBaseUrl())
96 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
99 for (const file of video.streamingPlaylists[0].files) {
100 expectStartWith(file.fileUrl, ObjectStorageCommand.getPlaylistBaseUrl())
102 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
107 after(async function () {
108 await killallServers([ server ])