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