aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/cli/optimize-old-videos.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/cli/optimize-old-videos.ts')
-rw-r--r--server/tests/cli/optimize-old-videos.ts65
1 files changed, 25 insertions, 40 deletions
diff --git a/server/tests/cli/optimize-old-videos.ts b/server/tests/cli/optimize-old-videos.ts
index 91a1c9cc4..579b2e7d8 100644
--- a/server/tests/cli/optimize-old-videos.ts
+++ b/server/tests/cli/optimize-old-videos.ts
@@ -2,38 +2,30 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { join } from 'path'
6import { 5import {
7 buildServerDirectory,
8 cleanupTests, 6 cleanupTests,
7 createMultipleServers,
9 doubleFollow, 8 doubleFollow,
10 execCLI,
11 flushAndRunMultipleServers,
12 generateHighBitrateVideo, 9 generateHighBitrateVideo,
13 getEnvCli, 10 PeerTubeServer,
14 getVideo,
15 getVideosList,
16 ServerInfo,
17 setAccessTokensToServers, 11 setAccessTokensToServers,
18 uploadVideo, 12 wait,
19 viewVideo, 13 waitJobs
20 wait 14} from '@shared/extra-utils'
21} from '../../../shared/extra-utils' 15import { getMaxBitrate, VideoResolution } from '@shared/models'
22import { waitJobs } from '../../../shared/extra-utils/server/jobs'
23import { getMaxBitrate, Video, VideoDetails, VideoResolution } from '../../../shared/models/videos'
24import { getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../../helpers/ffprobe-utils' 16import { getVideoFileBitrate, getVideoFileFPS, getVideoFileResolution } from '../../helpers/ffprobe-utils'
25import { VIDEO_TRANSCODING_FPS } from '../../initializers/constants' 17import { VIDEO_TRANSCODING_FPS } from '../../initializers/constants'
26 18
27const expect = chai.expect 19const expect = chai.expect
28 20
29describe('Test optimize old videos', function () { 21describe('Test optimize old videos', function () {
30 let servers: ServerInfo[] = [] 22 let servers: PeerTubeServer[] = []
31 23
32 before(async function () { 24 before(async function () {
33 this.timeout(200000) 25 this.timeout(200000)
34 26
35 // Run server 2 to have transcoding enabled 27 // Run server 2 to have transcoding enabled
36 servers = await flushAndRunMultipleServers(2) 28 servers = await createMultipleServers(2)
37 await setAccessTokensToServers(servers) 29 await setAccessTokensToServers(servers)
38 30
39 await doubleFollow(servers[0], servers[1]) 31 await doubleFollow(servers[0], servers[1])
@@ -48,8 +40,8 @@ describe('Test optimize old videos', function () {
48 } 40 }
49 41
50 // Upload two videos for our needs 42 // Upload two videos for our needs
51 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video1', fixture: tempFixturePath }) 43 await servers[0].videos.upload({ attributes: { name: 'video1', fixture: tempFixturePath } })
52 await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video2', fixture: tempFixturePath }) 44 await servers[0].videos.upload({ attributes: { name: 'video2', fixture: tempFixturePath } })
53 45
54 await waitJobs(servers) 46 await waitJobs(servers)
55 }) 47 })
@@ -58,14 +50,12 @@ describe('Test optimize old videos', function () {
58 this.timeout(30000) 50 this.timeout(30000)
59 51
60 for (const server of servers) { 52 for (const server of servers) {
61 const res = await getVideosList(server.url) 53 const { data } = await server.videos.list()
62 const videos = res.body.data 54 expect(data).to.have.lengthOf(2)
63 expect(videos).to.have.lengthOf(2) 55
64 56 for (const video of data) {
65 for (const video of videos) { 57 const videoDetails = await server.videos.get({ id: video.uuid })
66 const res2 = await getVideo(server.url, video.uuid) 58 expect(videoDetails.files).to.have.lengthOf(1)
67 const videoDetail: VideoDetails = res2.body
68 expect(videoDetail.files).to.have.lengthOf(1)
69 } 59 }
70 } 60 }
71 }) 61 })
@@ -73,34 +63,29 @@ describe('Test optimize old videos', function () {
73 it('Should run optimize script', async function () { 63 it('Should run optimize script', async function () {
74 this.timeout(200000) 64 this.timeout(200000)
75 65
76 const env = getEnvCli(servers[0]) 66 await servers[0].cli.execWithEnv('npm run optimize-old-videos')
77 await execCLI(`${env} npm run optimize-old-videos`)
78
79 await waitJobs(servers) 67 await waitJobs(servers)
80 68
81 for (const server of servers) { 69 for (const server of servers) {
82 const res = await getVideosList(server.url) 70 const { data } = await server.videos.list()
83 const videos: Video[] = res.body.data 71 expect(data).to.have.lengthOf(2)
84
85 expect(videos).to.have.lengthOf(2)
86 72
87 for (const video of videos) { 73 for (const video of data) {
88 await viewVideo(server.url, video.uuid) 74 await server.videos.view({ id: video.uuid })
89 75
90 // Refresh video 76 // Refresh video
91 await waitJobs(servers) 77 await waitJobs(servers)
92 await wait(5000) 78 await wait(5000)
93 await waitJobs(servers) 79 await waitJobs(servers)
94 80
95 const res2 = await getVideo(server.url, video.uuid) 81 const videoDetails = await server.videos.get({ id: video.uuid })
96 const videosDetails: VideoDetails = res2.body
97 82
98 expect(videosDetails.files).to.have.lengthOf(1) 83 expect(videoDetails.files).to.have.lengthOf(1)
99 const file = videosDetails.files[0] 84 const file = videoDetails.files[0]
100 85
101 expect(file.size).to.be.below(8000000) 86 expect(file.size).to.be.below(8000000)
102 87
103 const path = buildServerDirectory(servers[0], join('videos', video.uuid + '-' + file.resolution.id + '.mp4')) 88 const path = servers[0].servers.buildWebTorrentFilePath(file.fileUrl)
104 const bitrate = await getVideoFileBitrate(path) 89 const bitrate = await getVideoFileBitrate(path)
105 const fps = await getVideoFileFPS(path) 90 const fps = await getVideoFileFPS(path)
106 const resolution = await getVideoFileResolution(path) 91 const resolution = await getVideoFileResolution(path)