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 { areMockObjectStorageTestsDisabled } 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 (areMockObjectStorageTestsDisabled()) return
34 let server: PeerTubeServer
36 before(async function () {
39 await ObjectStorageCommand.prepareDefaultMockBuckets()
41 server = await createSingleServer(1, ObjectStorageCommand.getDefaultMockConfig())
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.getMockWebTorrentBaseUrl())
69 await makeRawRequest({ url: fileUrl, expectedStatus: 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.getMockWebTorrentBaseUrl())
94 await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
97 for (const file of video.streamingPlaylists[0].files) {
98 expectStartWith(file.fileUrl, ObjectStorageCommand.getMockPlaylistBaseUrl())
100 await makeRawRequest({ url: file.fileUrl, expectedStatus: HttpStatusCode.OK_200 })
105 after(async function () {
106 await killallServers([ server ])