]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/object-storage/video-imports.ts
141ead2f72822a1b318a71ff4812701821b97506
[github/Chocobozzz/PeerTube.git] / server / tests / api / object-storage / video-imports.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
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'
7 import {
8 createSingleServer,
9 killallServers,
10 makeRawRequest,
11 ObjectStorageCommand,
12 PeerTubeServer,
13 setAccessTokensToServers,
14 setDefaultVideoChannel,
15 waitJobs
16 } from '@shared/server-commands'
17
18 const expect = chai.expect
19
20 async function importVideo (server: PeerTubeServer) {
21 const attributes = {
22 name: 'import 2',
23 privacy: VideoPrivacy.PUBLIC,
24 channelId: server.store.channel.id,
25 targetUrl: FIXTURE_URLS.goodVideo720
26 }
27
28 const { video: { uuid } } = await server.imports.importVideo({ attributes })
29
30 return uuid
31 }
32
33 describe('Object storage for video import', function () {
34 if (areObjectStorageTestsDisabled()) return
35
36 let server: PeerTubeServer
37
38 before(async function () {
39 this.timeout(120000)
40
41 await ObjectStorageCommand.prepareDefaultBuckets()
42
43 server = await createSingleServer(1, ObjectStorageCommand.getDefaultConfig())
44
45 await setAccessTokensToServers([ server ])
46 await setDefaultVideoChannel([ server ])
47
48 await server.config.enableImports()
49 })
50
51 describe('Without transcoding', async function () {
52
53 before(async function () {
54 await server.config.disableTranscoding()
55 })
56
57 it('Should import a video and have sent it to object storage', async function () {
58 this.timeout(120000)
59
60 const uuid = await importVideo(server)
61 await waitJobs(server)
62
63 const video = await server.videos.get({ id: uuid })
64
65 expect(video.files).to.have.lengthOf(1)
66 expect(video.streamingPlaylists).to.have.lengthOf(0)
67
68 const fileUrl = video.files[0].fileUrl
69 expectStartWith(fileUrl, ObjectStorageCommand.getWebTorrentBaseUrl())
70
71 await makeRawRequest(fileUrl, HttpStatusCode.OK_200)
72 })
73 })
74
75 describe('With transcoding', async function () {
76
77 before(async function () {
78 await server.config.enableTranscoding()
79 })
80
81 it('Should import a video and have sent it to object storage', async function () {
82 this.timeout(120000)
83
84 const uuid = await importVideo(server)
85 await waitJobs(server)
86
87 const video = await server.videos.get({ id: uuid })
88
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)
92
93 for (const file of video.files) {
94 expectStartWith(file.fileUrl, ObjectStorageCommand.getWebTorrentBaseUrl())
95
96 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
97 }
98
99 for (const file of video.streamingPlaylists[0].files) {
100 expectStartWith(file.fileUrl, ObjectStorageCommand.getPlaylistBaseUrl())
101
102 await makeRawRequest(file.fileUrl, HttpStatusCode.OK_200)
103 }
104 })
105 })
106
107 after(async function () {
108 await killallServers([ server ])
109 })
110 })