1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { expectStartWith, FIXTURE_URLS } from '@server/tests/shared'
6 import { areObjectStorageTestsDisabled } from '@shared/core-utils'
7 import { HttpStatusCode, VideoPrivacy } from '@shared/models'
14 setAccessTokensToServers,
15 setDefaultVideoChannel,
17 } from '@shared/server-commands'
19 const expect = chai.expect
21 async function importVideo (server: PeerTubeServer) {
24 privacy: VideoPrivacy.PUBLIC,
25 channelId: server.store.channel.id,
26 targetUrl: FIXTURE_URLS.goodVideo720
29 const { video: { uuid } } = await server.imports.importVideo({ attributes })
34 describe('Object storage for video import', function () {
35 if (areObjectStorageTestsDisabled()) return
37 let server: PeerTubeServer
39 before(async function () {
42 await ObjectStorageCommand.prepareDefaultBuckets()
44 server = await createSingleServer(1, ObjectStorageCommand.getDefaultConfig())
46 await setAccessTokensToServers([ server ])
47 await setDefaultVideoChannel([ server ])
49 await server.config.enableImports()
52 describe('Without transcoding', async function () {
54 before(async function () {
55 await server.config.disableTranscoding()
58 it('Should import a video and have sent it to object storage', async function () {
61 const uuid = await importVideo(server)
62 await waitJobs(server)
64 const video = await server.videos.get({ id: uuid })
66 expect(video.files).to.have.lengthOf(1)
67 expect(video.streamingPlaylists).to.have.lengthOf(0)
69 const fileUrl = video.files[0].fileUrl
70 expectStartWith(fileUrl, ObjectStorageCommand.getWebTorrentBaseUrl())
72 await makeRawRequest(fileUrl, HttpStatusCode.OK_200)
76 describe('With transcoding', async function () {
78 before(async function () {
79 await server.config.enableTranscoding()
82 it('Should import a video and have sent it to object storage', async function () {
85 const uuid = await importVideo(server)
86 await waitJobs(server)
88 const video = await server.videos.get({ id: uuid })
90 expect(video.files).to.have.lengthOf(5)
91 expect(video.streamingPlaylists).to.have.lengthOf(1)
92 expect(video.streamingPlaylists[0].files).to.have.lengthOf(5)
94 for (const file of video.files) {
95 expectStartWith(file.fileUrl, ObjectStorageCommand.getWebTorrentBaseUrl())
97 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
100 for (const file of video.streamingPlaylists[0].files) {
101 expectStartWith(file.fileUrl, ObjectStorageCommand.getPlaylistBaseUrl())
103 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
108 after(async function () {
109 await killallServers([ server ])