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