1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } 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 async function importVideo (server: PeerTubeServer) {
21 privacy: VideoPrivacy.PUBLIC,
22 channelId: server.store.channel.id,
23 targetUrl: FIXTURE_URLS.goodVideo720
26 const { video: { uuid } } = await server.imports.importVideo({ attributes })
31 describe('Object storage for video import', function () {
32 if (areObjectStorageTestsDisabled()) return
34 let server: PeerTubeServer
36 before(async function () {
39 await ObjectStorageCommand.prepareDefaultBuckets()
41 server = await createSingleServer(1, ObjectStorageCommand.getDefaultConfig())
43 await setAccessTokensToServers([ server ])
44 await setDefaultVideoChannel([ server ])
46 await server.config.enableImports()
49 describe('Without transcoding', async function () {
51 before(async function () {
52 await server.config.disableTranscoding()
55 it('Should import a video and have sent it to object storage', async function () {
58 const uuid = await importVideo(server)
59 await waitJobs(server)
61 const video = await server.videos.get({ id: uuid })
63 expect(video.files).to.have.lengthOf(1)
64 expect(video.streamingPlaylists).to.have.lengthOf(0)
66 const fileUrl = video.files[0].fileUrl
67 expectStartWith(fileUrl, ObjectStorageCommand.getWebTorrentBaseUrl())
69 await makeRawRequest(fileUrl, HttpStatusCode.OK_200)
73 describe('With transcoding', async function () {
75 before(async function () {
76 await server.config.enableTranscoding()
79 it('Should import a video and have sent it to object storage', async function () {
82 const uuid = await importVideo(server)
83 await waitJobs(server)
85 const video = await server.videos.get({ id: uuid })
87 expect(video.files).to.have.lengthOf(5)
88 expect(video.streamingPlaylists).to.have.lengthOf(1)
89 expect(video.streamingPlaylists[0].files).to.have.lengthOf(5)
91 for (const file of video.files) {
92 expectStartWith(file.fileUrl, ObjectStorageCommand.getWebTorrentBaseUrl())
94 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
97 for (const file of video.streamingPlaylists[0].files) {
98 expectStartWith(file.fileUrl, ObjectStorageCommand.getPlaylistBaseUrl())
100 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
105 after(async function () {
106 await killallServers([ server ])