aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/cli
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/cli')
-rw-r--r--server/tests/cli/create-import-video-file-job.ts70
-rw-r--r--server/tests/cli/create-transcoding-job.ts110
-rw-r--r--server/tests/cli/optimize-old-videos.ts64
-rw-r--r--server/tests/cli/peertube.ts163
-rw-r--r--server/tests/cli/plugins.ts42
-rw-r--r--server/tests/cli/print-transcode-command.ts7
-rw-r--r--server/tests/cli/prune-storage.ts87
-rw-r--r--server/tests/cli/regenerate-thumbnails.ts52
-rw-r--r--server/tests/cli/reset-password.ts25
-rw-r--r--server/tests/cli/update-host.ts79
10 files changed, 281 insertions, 418 deletions
diff --git a/server/tests/cli/create-import-video-file-job.ts b/server/tests/cli/create-import-video-file-job.ts
index 49758ff56..bddcff5e7 100644
--- a/server/tests/cli/create-import-video-file-job.ts
+++ b/server/tests/cli/create-import-video-file-job.ts
@@ -2,21 +2,8 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { VideoFile } from '@shared/models/videos/video-file.model' 5import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/extra-utils'
6import { 6import { VideoFile } from '@shared/models'
7 cleanupTests,
8 doubleFollow,
9 execCLI,
10 flushAndRunMultipleServers,
11 getEnvCli,
12 getVideo,
13 getVideosList,
14 ServerInfo,
15 setAccessTokensToServers,
16 uploadVideo
17} from '../../../shared/extra-utils'
18import { waitJobs } from '../../../shared/extra-utils/server/jobs'
19import { VideoDetails } from '../../../shared/models/videos'
20 7
21const expect = chai.expect 8const expect = chai.expect
22 9
@@ -33,7 +20,7 @@ function assertVideoProperties (video: VideoFile, resolution: number, extname: s
33describe('Test create import video jobs', function () { 20describe('Test create import video jobs', function () {
34 this.timeout(60000) 21 this.timeout(60000)
35 22
36 let servers: ServerInfo[] = [] 23 let servers: PeerTubeServer[] = []
37 let video1UUID: string 24 let video1UUID: string
38 let video2UUID: string 25 let video2UUID: string
39 26
@@ -41,56 +28,61 @@ describe('Test create import video jobs', function () {
41 this.timeout(90000) 28 this.timeout(90000)
42 29
43 // Run server 2 to have transcoding enabled 30 // Run server 2 to have transcoding enabled
44 servers = await flushAndRunMultipleServers(2) 31 servers = await createMultipleServers(2)
45 await setAccessTokensToServers(servers) 32 await setAccessTokensToServers(servers)
46 33
47 await doubleFollow(servers[0], servers[1]) 34 await doubleFollow(servers[0], servers[1])
48 35
49 // Upload two videos for our needs 36 // Upload two videos for our needs
50 const res1 = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video1' }) 37 {
51 video1UUID = res1.body.video.uuid 38 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video1' } })
52 const res2 = await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'video2' }) 39 video1UUID = uuid
53 video2UUID = res2.body.video.uuid 40 }
41
42 {
43 const { uuid } = await servers[1].videos.upload({ attributes: { name: 'video2' } })
44 video2UUID = uuid
45 }
54 46
55 // Transcoding 47 // Transcoding
56 await waitJobs(servers) 48 await waitJobs(servers)
57 }) 49 })
58 50
59 it('Should run a import job on video 1 with a lower resolution', async function () { 51 it('Should run a import job on video 1 with a lower resolution', async function () {
60 const env = getEnvCli(servers[0]) 52 const command = `npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short-480.webm`
61 await execCLI(`${env} npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short-480.webm`) 53 await servers[0].cli.execWithEnv(command)
62 54
63 await waitJobs(servers) 55 await waitJobs(servers)
64 56
65 for (const server of servers) { 57 for (const server of servers) {
66 const { data: videos } = (await getVideosList(server.url)).body 58 const { data: videos } = await server.videos.list()
67 expect(videos).to.have.lengthOf(2) 59 expect(videos).to.have.lengthOf(2)
68 60
69 const video = videos.find(({ uuid }) => uuid === video1UUID) 61 const video = videos.find(({ uuid }) => uuid === video1UUID)
70 const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body 62 const videoDetails = await server.videos.get({ id: video.uuid })
71 63
72 expect(videoDetail.files).to.have.lengthOf(2) 64 expect(videoDetails.files).to.have.lengthOf(2)
73 const [ originalVideo, transcodedVideo ] = videoDetail.files 65 const [ originalVideo, transcodedVideo ] = videoDetails.files
74 assertVideoProperties(originalVideo, 720, 'webm', 218910) 66 assertVideoProperties(originalVideo, 720, 'webm', 218910)
75 assertVideoProperties(transcodedVideo, 480, 'webm', 69217) 67 assertVideoProperties(transcodedVideo, 480, 'webm', 69217)
76 } 68 }
77 }) 69 })
78 70
79 it('Should run a import job on video 2 with the same resolution and a different extension', async function () { 71 it('Should run a import job on video 2 with the same resolution and a different extension', async function () {
80 const env = getEnvCli(servers[1]) 72 const command = `npm run create-import-video-file-job -- -v ${video2UUID} -i server/tests/fixtures/video_short.ogv`
81 await execCLI(`${env} npm run create-import-video-file-job -- -v ${video2UUID} -i server/tests/fixtures/video_short.ogv`) 73 await servers[1].cli.execWithEnv(command)
82 74
83 await waitJobs(servers) 75 await waitJobs(servers)
84 76
85 for (const server of servers) { 77 for (const server of servers) {
86 const { data: videos } = (await getVideosList(server.url)).body 78 const { data: videos } = await server.videos.list()
87 expect(videos).to.have.lengthOf(2) 79 expect(videos).to.have.lengthOf(2)
88 80
89 const video = videos.find(({ uuid }) => uuid === video2UUID) 81 const video = videos.find(({ uuid }) => uuid === video2UUID)
90 const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body 82 const videoDetails = await server.videos.get({ id: video.uuid })
91 83
92 expect(videoDetail.files).to.have.lengthOf(4) 84 expect(videoDetails.files).to.have.lengthOf(4)
93 const [ originalVideo, transcodedVideo420, transcodedVideo320, transcodedVideo240 ] = videoDetail.files 85 const [ originalVideo, transcodedVideo420, transcodedVideo320, transcodedVideo240 ] = videoDetails.files
94 assertVideoProperties(originalVideo, 720, 'ogv', 140849) 86 assertVideoProperties(originalVideo, 720, 'ogv', 140849)
95 assertVideoProperties(transcodedVideo420, 480, 'mp4') 87 assertVideoProperties(transcodedVideo420, 480, 'mp4')
96 assertVideoProperties(transcodedVideo320, 360, 'mp4') 88 assertVideoProperties(transcodedVideo320, 360, 'mp4')
@@ -99,20 +91,20 @@ describe('Test create import video jobs', function () {
99 }) 91 })
100 92
101 it('Should run a import job on video 2 with the same resolution and the same extension', async function () { 93 it('Should run a import job on video 2 with the same resolution and the same extension', async function () {
102 const env = getEnvCli(servers[0]) 94 const command = `npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short2.webm`
103 await execCLI(`${env} npm run create-import-video-file-job -- -v ${video1UUID} -i server/tests/fixtures/video_short2.webm`) 95 await servers[0].cli.execWithEnv(command)
104 96
105 await waitJobs(servers) 97 await waitJobs(servers)
106 98
107 for (const server of servers) { 99 for (const server of servers) {
108 const { data: videos } = (await getVideosList(server.url)).body 100 const { data: videos } = await server.videos.list()
109 expect(videos).to.have.lengthOf(2) 101 expect(videos).to.have.lengthOf(2)
110 102
111 const video = videos.find(({ uuid }) => uuid === video1UUID) 103 const video = videos.find(({ uuid }) => uuid === video1UUID)
112 const videoDetail: VideoDetails = (await getVideo(server.url, video.uuid)).body 104 const videoDetails = await server.videos.get({ id: video.uuid })
113 105
114 expect(videoDetail.files).to.have.lengthOf(2) 106 expect(videoDetails.files).to.have.lengthOf(2)
115 const [ video720, video480 ] = videoDetail.files 107 const [ video720, video480 ] = videoDetails.files
116 assertVideoProperties(video720, 720, 'webm', 942961) 108 assertVideoProperties(video720, 720, 'webm', 942961)
117 assertVideoProperties(video480, 480, 'webm', 69217) 109 assertVideoProperties(video480, 480, 'webm', 69217)
118 } 110 }
diff --git a/server/tests/cli/create-transcoding-job.ts b/server/tests/cli/create-transcoding-job.ts
index 5bc1687cd..df787ccdc 100644
--- a/server/tests/cli/create-transcoding-job.ts
+++ b/server/tests/cli/create-transcoding-job.ts
@@ -2,26 +2,19 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { VideoDetails } from '../../../shared/models/videos'
6import { 5import {
7 cleanupTests, 6 cleanupTests,
7 createMultipleServers,
8 doubleFollow, 8 doubleFollow,
9 execCLI, 9 PeerTubeServer,
10 flushAndRunMultipleServers,
11 getEnvCli,
12 getVideo,
13 getVideosList,
14 ServerInfo,
15 setAccessTokensToServers, 10 setAccessTokensToServers,
16 updateCustomSubConfig, 11 waitJobs
17 uploadVideo
18} from '../../../shared/extra-utils' 12} from '../../../shared/extra-utils'
19import { waitJobs } from '../../../shared/extra-utils/server/jobs'
20 13
21const expect = chai.expect 14const expect = chai.expect
22 15
23describe('Test create transcoding jobs', function () { 16describe('Test create transcoding jobs', function () {
24 let servers: ServerInfo[] = [] 17 let servers: PeerTubeServer[] = []
25 const videosUUID: string[] = [] 18 const videosUUID: string[] = []
26 19
27 const config = { 20 const config = {
@@ -46,16 +39,16 @@ describe('Test create transcoding jobs', function () {
46 this.timeout(60000) 39 this.timeout(60000)
47 40
48 // Run server 2 to have transcoding enabled 41 // Run server 2 to have transcoding enabled
49 servers = await flushAndRunMultipleServers(2) 42 servers = await createMultipleServers(2)
50 await setAccessTokensToServers(servers) 43 await setAccessTokensToServers(servers)
51 44
52 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) 45 await servers[0].config.updateCustomSubConfig({ newConfig: config })
53 46
54 await doubleFollow(servers[0], servers[1]) 47 await doubleFollow(servers[0], servers[1])
55 48
56 for (let i = 1; i <= 5; i++) { 49 for (let i = 1; i <= 5; i++) {
57 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'video' + i }) 50 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'video' + i } })
58 videosUUID.push(res.body.video.uuid) 51 videosUUID.push(uuid)
59 } 52 }
60 53
61 await waitJobs(servers) 54 await waitJobs(servers)
@@ -65,13 +58,11 @@ describe('Test create transcoding jobs', function () {
65 this.timeout(30000) 58 this.timeout(30000)
66 59
67 for (const server of servers) { 60 for (const server of servers) {
68 const res = await getVideosList(server.url) 61 const { data } = await server.videos.list()
69 const videos = res.body.data 62 expect(data).to.have.lengthOf(videosUUID.length)
70 expect(videos).to.have.lengthOf(videosUUID.length)
71 63
72 for (const video of videos) { 64 for (const video of data) {
73 const res2 = await getVideo(server.url, video.uuid) 65 const videoDetail = await server.videos.get({ id: video.uuid })
74 const videoDetail: VideoDetails = res2.body
75 expect(videoDetail.files).to.have.lengthOf(1) 66 expect(videoDetail.files).to.have.lengthOf(1)
76 expect(videoDetail.streamingPlaylists).to.have.lengthOf(0) 67 expect(videoDetail.streamingPlaylists).to.have.lengthOf(0)
77 } 68 }
@@ -81,20 +72,16 @@ describe('Test create transcoding jobs', function () {
81 it('Should run a transcoding job on video 2', async function () { 72 it('Should run a transcoding job on video 2', async function () {
82 this.timeout(60000) 73 this.timeout(60000)
83 74
84 const env = getEnvCli(servers[0]) 75 await servers[0].cli.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[1]}`)
85 await execCLI(`${env} npm run create-transcoding-job -- -v ${videosUUID[1]}`)
86
87 await waitJobs(servers) 76 await waitJobs(servers)
88 77
89 for (const server of servers) { 78 for (const server of servers) {
90 const res = await getVideosList(server.url) 79 const { data } = await server.videos.list()
91 const videos = res.body.data
92 80
93 let infoHashes: { [id: number]: string } 81 let infoHashes: { [id: number]: string }
94 82
95 for (const video of videos) { 83 for (const video of data) {
96 const res2 = await getVideo(server.url, video.uuid) 84 const videoDetail = await server.videos.get({ id: video.uuid })
97 const videoDetail: VideoDetails = res2.body
98 85
99 if (video.uuid === videosUUID[1]) { 86 if (video.uuid === videosUUID[1]) {
100 expect(videoDetail.files).to.have.lengthOf(4) 87 expect(videoDetail.files).to.have.lengthOf(4)
@@ -123,43 +110,38 @@ describe('Test create transcoding jobs', function () {
123 it('Should run a transcoding job on video 1 with resolution', async function () { 110 it('Should run a transcoding job on video 1 with resolution', async function () {
124 this.timeout(60000) 111 this.timeout(60000)
125 112
126 const env = getEnvCli(servers[0]) 113 await servers[0].cli.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[0]} -r 480`)
127 await execCLI(`${env} npm run create-transcoding-job -- -v ${videosUUID[0]} -r 480`)
128 114
129 await waitJobs(servers) 115 await waitJobs(servers)
130 116
131 for (const server of servers) { 117 for (const server of servers) {
132 const res = await getVideosList(server.url) 118 const { data } = await server.videos.list()
133 const videos = res.body.data 119 expect(data).to.have.lengthOf(videosUUID.length)
134 expect(videos).to.have.lengthOf(videosUUID.length)
135 120
136 const res2 = await getVideo(server.url, videosUUID[0]) 121 const videoDetails = await server.videos.get({ id: videosUUID[0] })
137 const videoDetail: VideoDetails = res2.body
138 122
139 expect(videoDetail.files).to.have.lengthOf(2) 123 expect(videoDetails.files).to.have.lengthOf(2)
140 expect(videoDetail.files[0].resolution.id).to.equal(720) 124 expect(videoDetails.files[0].resolution.id).to.equal(720)
141 expect(videoDetail.files[1].resolution.id).to.equal(480) 125 expect(videoDetails.files[1].resolution.id).to.equal(480)
142 126
143 expect(videoDetail.streamingPlaylists).to.have.lengthOf(0) 127 expect(videoDetails.streamingPlaylists).to.have.lengthOf(0)
144 } 128 }
145 }) 129 })
146 130
147 it('Should generate an HLS resolution', async function () { 131 it('Should generate an HLS resolution', async function () {
148 this.timeout(120000) 132 this.timeout(120000)
149 133
150 const env = getEnvCli(servers[0]) 134 await servers[0].cli.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[2]} --generate-hls -r 480`)
151 await execCLI(`${env} npm run create-transcoding-job -- -v ${videosUUID[2]} --generate-hls -r 480`)
152 135
153 await waitJobs(servers) 136 await waitJobs(servers)
154 137
155 for (const server of servers) { 138 for (const server of servers) {
156 const res = await getVideo(server.url, videosUUID[2]) 139 const videoDetails = await server.videos.get({ id: videosUUID[2] })
157 const videoDetail: VideoDetails = res.body
158 140
159 expect(videoDetail.files).to.have.lengthOf(1) 141 expect(videoDetails.files).to.have.lengthOf(1)
160 expect(videoDetail.streamingPlaylists).to.have.lengthOf(1) 142 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
161 143
162 const files = videoDetail.streamingPlaylists[0].files 144 const files = videoDetails.streamingPlaylists[0].files
163 expect(files).to.have.lengthOf(1) 145 expect(files).to.have.lengthOf(1)
164 expect(files[0].resolution.id).to.equal(480) 146 expect(files[0].resolution.id).to.equal(480)
165 } 147 }
@@ -168,16 +150,14 @@ describe('Test create transcoding jobs', function () {
168 it('Should not duplicate an HLS resolution', async function () { 150 it('Should not duplicate an HLS resolution', async function () {
169 this.timeout(120000) 151 this.timeout(120000)
170 152
171 const env = getEnvCli(servers[0]) 153 await servers[0].cli.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[2]} --generate-hls -r 480`)
172 await execCLI(`${env} npm run create-transcoding-job -- -v ${videosUUID[2]} --generate-hls -r 480`)
173 154
174 await waitJobs(servers) 155 await waitJobs(servers)
175 156
176 for (const server of servers) { 157 for (const server of servers) {
177 const res = await getVideo(server.url, videosUUID[2]) 158 const videoDetails = await server.videos.get({ id: videosUUID[2] })
178 const videoDetail: VideoDetails = res.body
179 159
180 const files = videoDetail.streamingPlaylists[0].files 160 const files = videoDetails.streamingPlaylists[0].files
181 expect(files).to.have.lengthOf(1) 161 expect(files).to.have.lengthOf(1)
182 expect(files[0].resolution.id).to.equal(480) 162 expect(files[0].resolution.id).to.equal(480)
183 } 163 }
@@ -186,19 +166,17 @@ describe('Test create transcoding jobs', function () {
186 it('Should generate all HLS resolutions', async function () { 166 it('Should generate all HLS resolutions', async function () {
187 this.timeout(120000) 167 this.timeout(120000)
188 168
189 const env = getEnvCli(servers[0]) 169 await servers[0].cli.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[3]} --generate-hls`)
190 await execCLI(`${env} npm run create-transcoding-job -- -v ${videosUUID[3]} --generate-hls`)
191 170
192 await waitJobs(servers) 171 await waitJobs(servers)
193 172
194 for (const server of servers) { 173 for (const server of servers) {
195 const res = await getVideo(server.url, videosUUID[3]) 174 const videoDetails = await server.videos.get({ id: videosUUID[3] })
196 const videoDetail: VideoDetails = res.body
197 175
198 expect(videoDetail.files).to.have.lengthOf(1) 176 expect(videoDetails.files).to.have.lengthOf(1)
199 expect(videoDetail.streamingPlaylists).to.have.lengthOf(1) 177 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
200 178
201 const files = videoDetail.streamingPlaylists[0].files 179 const files = videoDetails.streamingPlaylists[0].files
202 expect(files).to.have.lengthOf(4) 180 expect(files).to.have.lengthOf(4)
203 } 181 }
204 }) 182 })
@@ -207,20 +185,18 @@ describe('Test create transcoding jobs', function () {
207 this.timeout(120000) 185 this.timeout(120000)
208 186
209 config.transcoding.hls.enabled = true 187 config.transcoding.hls.enabled = true
210 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) 188 await servers[0].config.updateCustomSubConfig({ newConfig: config })
211 189
212 const env = getEnvCli(servers[0]) 190 await servers[0].cli.execWithEnv(`npm run create-transcoding-job -- -v ${videosUUID[4]}`)
213 await execCLI(`${env} npm run create-transcoding-job -- -v ${videosUUID[4]}`)
214 191
215 await waitJobs(servers) 192 await waitJobs(servers)
216 193
217 for (const server of servers) { 194 for (const server of servers) {
218 const res = await getVideo(server.url, videosUUID[4]) 195 const videoDetails = await server.videos.get({ id: videosUUID[4] })
219 const videoDetail: VideoDetails = res.body
220 196
221 expect(videoDetail.files).to.have.lengthOf(4) 197 expect(videoDetails.files).to.have.lengthOf(4)
222 expect(videoDetail.streamingPlaylists).to.have.lengthOf(1) 198 expect(videoDetails.streamingPlaylists).to.have.lengthOf(1)
223 expect(videoDetail.streamingPlaylists[0].files).to.have.lengthOf(4) 199 expect(videoDetails.streamingPlaylists[0].files).to.have.lengthOf(4)
224 } 200 }
225 }) 201 })
226 202
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)
diff --git a/server/tests/cli/peertube.ts b/server/tests/cli/peertube.ts
index fcf7e2e2e..f2a984962 100644
--- a/server/tests/cli/peertube.ts
+++ b/server/tests/cli/peertube.ts
@@ -2,97 +2,91 @@
2 2
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { Video, VideoDetails } from '../../../shared'
6import { 5import {
7 addVideoChannel,
8 areHttpImportTestsDisabled, 6 areHttpImportTestsDisabled,
9 buildAbsoluteFixturePath, 7 buildAbsoluteFixturePath,
10 cleanupTests, 8 cleanupTests,
11 createUser, 9 CLICommand,
10 createSingleServer,
12 doubleFollow, 11 doubleFollow,
13 execCLI, 12 FIXTURE_URLS,
14 flushAndRunServer, 13 PeerTubeServer,
15 getEnvCli,
16 getLocalIdByUUID,
17 getVideo,
18 getVideosList,
19 removeVideo,
20 ServerInfo,
21 setAccessTokensToServers, 14 setAccessTokensToServers,
22 testHelloWorldRegisteredSettings, 15 testHelloWorldRegisteredSettings,
23 uploadVideoAndGetId,
24 userLogin,
25 waitJobs 16 waitJobs
26} from '../../../shared/extra-utils' 17} from '../../../shared/extra-utils'
27import { getYoutubeVideoUrl } from '../../../shared/extra-utils/videos/video-imports'
28 18
29describe('Test CLI wrapper', function () { 19describe('Test CLI wrapper', function () {
30 let server: ServerInfo 20 let server: PeerTubeServer
31 let userAccessToken: string 21 let userAccessToken: string
32 22
23 let cliCommand: CLICommand
24
33 const cmd = 'node ./dist/server/tools/peertube.js' 25 const cmd = 'node ./dist/server/tools/peertube.js'
34 26
35 before(async function () { 27 before(async function () {
36 this.timeout(30000) 28 this.timeout(30000)
37 29
38 server = await flushAndRunServer(1) 30 server = await createSingleServer(1)
39 await setAccessTokensToServers([ server ]) 31 await setAccessTokensToServers([ server ])
40 32
41 await createUser({ url: server.url, accessToken: server.accessToken, username: 'user_1', password: 'super_password' }) 33 await server.users.create({ username: 'user_1', password: 'super_password' })
42 34
43 userAccessToken = await userLogin(server, { username: 'user_1', password: 'super_password' }) 35 userAccessToken = await server.login.getAccessToken({ username: 'user_1', password: 'super_password' })
44 36
45 { 37 {
46 const args = { name: 'user_channel', displayName: 'User channel', support: 'super support text' } 38 const attributes = { name: 'user_channel', displayName: 'User channel', support: 'super support text' }
47 await addVideoChannel(server.url, userAccessToken, args) 39 await server.channels.create({ token: userAccessToken, attributes })
48 } 40 }
41
42 cliCommand = server.cli
49 }) 43 })
50 44
51 describe('Authentication and instance selection', function () { 45 describe('Authentication and instance selection', function () {
52 46
47 it('Should get an access token', async function () {
48 const stdout = await cliCommand.execWithEnv(`${cmd} token --url ${server.url} --username user_1 --password super_password`)
49 const token = stdout.trim()
50
51 const body = await server.users.getMyInfo({ token })
52 expect(body.username).to.equal('user_1')
53 })
54
53 it('Should display no selected instance', async function () { 55 it('Should display no selected instance', async function () {
54 this.timeout(60000) 56 this.timeout(60000)
55 57
56 const env = getEnvCli(server) 58 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
57 const stdout = await execCLI(`${env} ${cmd} --help`)
58
59 expect(stdout).to.contain('no instance selected') 59 expect(stdout).to.contain('no instance selected')
60 }) 60 })
61 61
62 it('Should add a user', async function () { 62 it('Should add a user', async function () {
63 this.timeout(60000) 63 this.timeout(60000)
64 64
65 const env = getEnvCli(server) 65 await cliCommand.execWithEnv(`${cmd} auth add -u ${server.url} -U user_1 -p super_password`)
66 await execCLI(`${env} ${cmd} auth add -u ${server.url} -U user_1 -p super_password`)
67 }) 66 })
68 67
69 it('Should not fail to add a user if there is a slash at the end of the instance URL', async function () { 68 it('Should not fail to add a user if there is a slash at the end of the instance URL', async function () {
70 this.timeout(60000) 69 this.timeout(60000)
71 70
72 const env = getEnvCli(server) 71 let fullServerURL = server.url + '/'
73 let fullServerURL 72
74 fullServerURL = server.url + '/' 73 await cliCommand.execWithEnv(`${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
75 await execCLI(`${env} ${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
76 74
77 fullServerURL = server.url + '/asdfasdf' 75 fullServerURL = server.url + '/asdfasdf'
78 await execCLI(`${env} ${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`) 76 await cliCommand.execWithEnv(`${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
79 }) 77 })
80 78
81 it('Should default to this user', async function () { 79 it('Should default to this user', async function () {
82 this.timeout(60000) 80 this.timeout(60000)
83 81
84 const env = getEnvCli(server) 82 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
85 const stdout = await execCLI(`${env} ${cmd} --help`)
86
87 expect(stdout).to.contain(`instance ${server.url} selected`) 83 expect(stdout).to.contain(`instance ${server.url} selected`)
88 }) 84 })
89 85
90 it('Should remember the user', async function () { 86 it('Should remember the user', async function () {
91 this.timeout(60000) 87 this.timeout(60000)
92 88
93 const env = getEnvCli(server) 89 const stdout = await cliCommand.execWithEnv(`${cmd} auth list`)
94 const stdout = await execCLI(`${env} ${cmd} auth list`)
95
96 expect(stdout).to.contain(server.url) 90 expect(stdout).to.contain(server.url)
97 }) 91 })
98 }) 92 })
@@ -102,24 +96,17 @@ describe('Test CLI wrapper', function () {
102 it('Should upload a video', async function () { 96 it('Should upload a video', async function () {
103 this.timeout(60000) 97 this.timeout(60000)
104 98
105 const env = getEnvCli(server)
106
107 const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4') 99 const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4')
108
109 const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'` 100 const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'`
110 101
111 await execCLI(`${env} ${cmd} upload ${params}`) 102 await cliCommand.execWithEnv(`${cmd} upload ${params}`)
112 }) 103 })
113 104
114 it('Should have the video uploaded', async function () { 105 it('Should have the video uploaded', async function () {
115 const res = await getVideosList(server.url) 106 const { total, data } = await server.videos.list()
116 107 expect(total).to.equal(1)
117 expect(res.body.total).to.equal(1)
118
119 const videos: Video[] = res.body.data
120
121 const video: VideoDetails = (await getVideo(server.url, videos[0].uuid)).body
122 108
109 const video = await server.videos.get({ id: data[0].uuid })
123 expect(video.name).to.equal('test upload') 110 expect(video.name).to.equal('test upload')
124 expect(video.support).to.equal('support_text') 111 expect(video.support).to.equal('support_text')
125 expect(video.channel.name).to.equal('user_channel') 112 expect(video.channel.name).to.equal('user_channel')
@@ -130,11 +117,8 @@ describe('Test CLI wrapper', function () {
130 117
131 this.timeout(60000) 118 this.timeout(60000)
132 119
133 const env = getEnvCli(server) 120 const params = `--target-url ${FIXTURE_URLS.youtube} --channel-name user_channel`
134 121 await cliCommand.execWithEnv(`${cmd} import ${params}`)
135 const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel`
136
137 await execCLI(`${env} ${cmd} import ${params}`)
138 }) 122 })
139 123
140 it('Should have imported the video', async function () { 124 it('Should have imported the video', async function () {
@@ -144,21 +128,19 @@ describe('Test CLI wrapper', function () {
144 128
145 await waitJobs([ server ]) 129 await waitJobs([ server ])
146 130
147 const res = await getVideosList(server.url) 131 const { total, data } = await server.videos.list()
148 132 expect(total).to.equal(2)
149 expect(res.body.total).to.equal(2)
150 133
151 const videos: Video[] = res.body.data 134 const video = data.find(v => v.name === 'small video - youtube')
152 const video = videos.find(v => v.name === 'small video - youtube')
153 expect(video).to.not.be.undefined 135 expect(video).to.not.be.undefined
154 136
155 const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body 137 const videoDetails = await server.videos.get({ id: video.id })
156 expect(videoDetails.channel.name).to.equal('user_channel') 138 expect(videoDetails.channel.name).to.equal('user_channel')
157 expect(videoDetails.support).to.equal('super support text') 139 expect(videoDetails.support).to.equal('super support text')
158 expect(videoDetails.nsfw).to.be.false 140 expect(videoDetails.nsfw).to.be.false
159 141
160 // So we can reimport it 142 // So we can reimport it
161 await removeVideo(server.url, userAccessToken, video.id) 143 await server.videos.remove({ token: userAccessToken, id: video.id })
162 }) 144 })
163 145
164 it('Should import and override some imported attributes', async function () { 146 it('Should import and override some imported attributes', async function () {
@@ -166,23 +148,20 @@ describe('Test CLI wrapper', function () {
166 148
167 this.timeout(60000) 149 this.timeout(60000)
168 150
169 const env = getEnvCli(server) 151 const params = `--target-url ${FIXTURE_URLS.youtube} ` +
170 152 `--channel-name user_channel --video-name toto --nsfw --support support`
171 const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel --video-name toto --nsfw --support support` 153 await cliCommand.execWithEnv(`${cmd} import ${params}`)
172
173 await execCLI(`${env} ${cmd} import ${params}`)
174 154
175 await waitJobs([ server ]) 155 await waitJobs([ server ])
176 156
177 { 157 {
178 const res = await getVideosList(server.url) 158 const { total, data } = await server.videos.list()
179 expect(res.body.total).to.equal(2) 159 expect(total).to.equal(2)
180 160
181 const videos: Video[] = res.body.data 161 const video = data.find(v => v.name === 'toto')
182 const video = videos.find(v => v.name === 'toto')
183 expect(video).to.not.be.undefined 162 expect(video).to.not.be.undefined
184 163
185 const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body 164 const videoDetails = await server.videos.get({ id: video.id })
186 expect(videoDetails.channel.name).to.equal('user_channel') 165 expect(videoDetails.channel.name).to.equal('user_channel')
187 expect(videoDetails.support).to.equal('support') 166 expect(videoDetails.support).to.equal('support')
188 expect(videoDetails.nsfw).to.be.true 167 expect(videoDetails.nsfw).to.be.true
@@ -194,18 +173,14 @@ describe('Test CLI wrapper', function () {
194 describe('Admin auth', function () { 173 describe('Admin auth', function () {
195 174
196 it('Should remove the auth user', async function () { 175 it('Should remove the auth user', async function () {
197 const env = getEnvCli(server) 176 await cliCommand.execWithEnv(`${cmd} auth del ${server.url}`)
198
199 await execCLI(`${env} ${cmd} auth del ${server.url}`)
200
201 const stdout = await execCLI(`${env} ${cmd} --help`)
202 177
178 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
203 expect(stdout).to.contain('no instance selected') 179 expect(stdout).to.contain('no instance selected')
204 }) 180 })
205 181
206 it('Should add the admin user', async function () { 182 it('Should add the admin user', async function () {
207 const env = getEnvCli(server) 183 await cliCommand.execWithEnv(`${cmd} auth add -u ${server.url} -U root -p test${server.internalServerNumber}`)
208 await execCLI(`${env} ${cmd} auth add -u ${server.url} -U root -p test${server.internalServerNumber}`)
209 }) 184 })
210 }) 185 })
211 186
@@ -214,8 +189,7 @@ describe('Test CLI wrapper', function () {
214 it('Should install a plugin', async function () { 189 it('Should install a plugin', async function () {
215 this.timeout(60000) 190 this.timeout(60000)
216 191
217 const env = getEnvCli(server) 192 await cliCommand.execWithEnv(`${cmd} plugins install --npm-name peertube-plugin-hello-world`)
218 await execCLI(`${env} ${cmd} plugins install --npm-name peertube-plugin-hello-world`)
219 }) 193 })
220 194
221 it('Should have registered settings', async function () { 195 it('Should have registered settings', async function () {
@@ -223,29 +197,27 @@ describe('Test CLI wrapper', function () {
223 }) 197 })
224 198
225 it('Should list installed plugins', async function () { 199 it('Should list installed plugins', async function () {
226 const env = getEnvCli(server) 200 const res = await cliCommand.execWithEnv(`${cmd} plugins list`)
227 const res = await execCLI(`${env} ${cmd} plugins list`)
228 201
229 expect(res).to.contain('peertube-plugin-hello-world') 202 expect(res).to.contain('peertube-plugin-hello-world')
230 }) 203 })
231 204
232 it('Should uninstall the plugin', async function () { 205 it('Should uninstall the plugin', async function () {
233 const env = getEnvCli(server) 206 const res = await cliCommand.execWithEnv(`${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`)
234 const res = await execCLI(`${env} ${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`)
235 207
236 expect(res).to.not.contain('peertube-plugin-hello-world') 208 expect(res).to.not.contain('peertube-plugin-hello-world')
237 }) 209 })
238 }) 210 })
239 211
240 describe('Manage video redundancies', function () { 212 describe('Manage video redundancies', function () {
241 let anotherServer: ServerInfo 213 let anotherServer: PeerTubeServer
242 let video1Server2: number 214 let video1Server2: number
243 let servers: ServerInfo[] 215 let servers: PeerTubeServer[]
244 216
245 before(async function () { 217 before(async function () {
246 this.timeout(120000) 218 this.timeout(120000)
247 219
248 anotherServer = await flushAndRunServer(2) 220 anotherServer = await createSingleServer(2)
249 await setAccessTokensToServers([ anotherServer ]) 221 await setAccessTokensToServers([ anotherServer ])
250 222
251 await doubleFollow(server, anotherServer) 223 await doubleFollow(server, anotherServer)
@@ -253,20 +225,17 @@ describe('Test CLI wrapper', function () {
253 servers = [ server, anotherServer ] 225 servers = [ server, anotherServer ]
254 await waitJobs(servers) 226 await waitJobs(servers)
255 227
256 const uuid = (await uploadVideoAndGetId({ server: anotherServer, videoName: 'super video' })).uuid 228 const { uuid } = await anotherServer.videos.quickUpload({ name: 'super video' })
257 await waitJobs(servers) 229 await waitJobs(servers)
258 230
259 video1Server2 = await getLocalIdByUUID(server.url, uuid) 231 video1Server2 = await server.videos.getId({ uuid })
260 }) 232 })
261 233
262 it('Should add a redundancy', async function () { 234 it('Should add a redundancy', async function () {
263 this.timeout(60000) 235 this.timeout(60000)
264 236
265 const env = getEnvCli(server)
266
267 const params = `add --video ${video1Server2}` 237 const params = `add --video ${video1Server2}`
268 238 await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
269 await execCLI(`${env} ${cmd} redundancy ${params}`)
270 239
271 await waitJobs(servers) 240 await waitJobs(servers)
272 }) 241 })
@@ -275,10 +244,8 @@ describe('Test CLI wrapper', function () {
275 this.timeout(60000) 244 this.timeout(60000)
276 245
277 { 246 {
278 const env = getEnvCli(server)
279
280 const params = 'list-my-redundancies' 247 const params = 'list-my-redundancies'
281 const stdout = await execCLI(`${env} ${cmd} redundancy ${params}`) 248 const stdout = await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
282 249
283 expect(stdout).to.contain('super video') 250 expect(stdout).to.contain('super video')
284 expect(stdout).to.contain(`localhost:${server.port}`) 251 expect(stdout).to.contain(`localhost:${server.port}`)
@@ -288,18 +255,14 @@ describe('Test CLI wrapper', function () {
288 it('Should remove a redundancy', async function () { 255 it('Should remove a redundancy', async function () {
289 this.timeout(60000) 256 this.timeout(60000)
290 257
291 const env = getEnvCli(server)
292
293 const params = `remove --video ${video1Server2}` 258 const params = `remove --video ${video1Server2}`
294 259 await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
295 await execCLI(`${env} ${cmd} redundancy ${params}`)
296 260
297 await waitJobs(servers) 261 await waitJobs(servers)
298 262
299 { 263 {
300 const env = getEnvCli(server)
301 const params = 'list-my-redundancies' 264 const params = 'list-my-redundancies'
302 const stdout = await execCLI(`${env} ${cmd} redundancy ${params}`) 265 const stdout = await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
303 266
304 expect(stdout).to.not.contain('super video') 267 expect(stdout).to.not.contain('super video')
305 } 268 }
diff --git a/server/tests/cli/plugins.ts b/server/tests/cli/plugins.ts
index 7f19f14b7..07c78cc89 100644
--- a/server/tests/cli/plugins.ts
+++ b/server/tests/cli/plugins.ts
@@ -1,55 +1,47 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai'
4import { 5import {
5 cleanupTests, 6 cleanupTests,
6 execCLI, 7 createSingleServer,
7 flushAndRunServer,
8 getConfig,
9 getEnvCli,
10 getPluginTestPath,
11 killallServers, 8 killallServers,
12 reRunServer, 9 PeerTubeServer,
13 ServerInfo, 10 PluginsCommand,
14 setAccessTokensToServers 11 setAccessTokensToServers
15} from '../../../shared/extra-utils' 12} from '../../../shared/extra-utils'
16import { ServerConfig } from '../../../shared/models/server'
17import { expect } from 'chai'
18 13
19describe('Test plugin scripts', function () { 14describe('Test plugin scripts', function () {
20 let server: ServerInfo 15 let server: PeerTubeServer
21 16
22 before(async function () { 17 before(async function () {
23 this.timeout(30000) 18 this.timeout(30000)
24 19
25 server = await flushAndRunServer(1) 20 server = await createSingleServer(1)
26 await setAccessTokensToServers([ server ]) 21 await setAccessTokensToServers([ server ])
27 }) 22 })
28 23
29 it('Should install a plugin from stateless CLI', async function () { 24 it('Should install a plugin from stateless CLI', async function () {
30 this.timeout(60000) 25 this.timeout(60000)
31 26
32 const packagePath = getPluginTestPath() 27 const packagePath = PluginsCommand.getPluginTestPath()
33 28
34 const env = getEnvCli(server) 29 await server.cli.execWithEnv(`npm run plugin:install -- --plugin-path ${packagePath}`)
35 await execCLI(`${env} npm run plugin:install -- --plugin-path ${packagePath}`)
36 }) 30 })
37 31
38 it('Should install a theme from stateless CLI', async function () { 32 it('Should install a theme from stateless CLI', async function () {
39 this.timeout(60000) 33 this.timeout(60000)
40 34
41 const env = getEnvCli(server) 35 await server.cli.execWithEnv(`npm run plugin:install -- --npm-name peertube-theme-background-red`)
42 await execCLI(`${env} npm run plugin:install -- --npm-name peertube-theme-background-red`)
43 }) 36 })
44 37
45 it('Should have the theme and the plugin registered when we restart peertube', async function () { 38 it('Should have the theme and the plugin registered when we restart peertube', async function () {
46 this.timeout(30000) 39 this.timeout(30000)
47 40
48 killallServers([ server ]) 41 await killallServers([ server ])
49 await reRunServer(server) 42 await server.run()
50 43
51 const res = await getConfig(server.url) 44 const config = await server.config.getConfig()
52 const config: ServerConfig = res.body
53 45
54 const plugin = config.plugin.registered 46 const plugin = config.plugin.registered
55 .find(p => p.name === 'test') 47 .find(p => p.name === 'test')
@@ -63,18 +55,16 @@ describe('Test plugin scripts', function () {
63 it('Should uninstall a plugin from stateless CLI', async function () { 55 it('Should uninstall a plugin from stateless CLI', async function () {
64 this.timeout(60000) 56 this.timeout(60000)
65 57
66 const env = getEnvCli(server) 58 await server.cli.execWithEnv(`npm run plugin:uninstall -- --npm-name peertube-plugin-test`)
67 await execCLI(`${env} npm run plugin:uninstall -- --npm-name peertube-plugin-test`)
68 }) 59 })
69 60
70 it('Should have removed the plugin on another peertube restart', async function () { 61 it('Should have removed the plugin on another peertube restart', async function () {
71 this.timeout(30000) 62 this.timeout(30000)
72 63
73 killallServers([ server ]) 64 await killallServers([ server ])
74 await reRunServer(server) 65 await server.run()
75 66
76 const res = await getConfig(server.url) 67 const config = await server.config.getConfig()
77 const config: ServerConfig = res.body
78 68
79 const plugin = config.plugin.registered 69 const plugin = config.plugin.registered
80 .find(p => p.name === 'test') 70 .find(p => p.name === 'test')
diff --git a/server/tests/cli/print-transcode-command.ts b/server/tests/cli/print-transcode-command.ts
index 2d7255db7..3a7969e68 100644
--- a/server/tests/cli/print-transcode-command.ts
+++ b/server/tests/cli/print-transcode-command.ts
@@ -2,14 +2,15 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { execCLI } from '../../../shared/extra-utils' 5import { getVideoFileBitrate, getVideoFileFPS } from '@server/helpers/ffprobe-utils'
6import { CLICommand } from '@shared/extra-utils'
6import { getTargetBitrate, VideoResolution } from '../../../shared/models/videos' 7import { getTargetBitrate, VideoResolution } from '../../../shared/models/videos'
7import { VIDEO_TRANSCODING_FPS } from '../../initializers/constants' 8import { VIDEO_TRANSCODING_FPS } from '../../initializers/constants'
8import { getVideoFileBitrate, getVideoFileFPS } from '@server/helpers/ffprobe-utils'
9 9
10const expect = chai.expect 10const expect = chai.expect
11 11
12describe('Test create transcoding jobs', function () { 12describe('Test create transcoding jobs', function () {
13
13 it('Should print the correct command for each resolution', async function () { 14 it('Should print the correct command for each resolution', async function () {
14 const fixturePath = 'server/tests/fixtures/video_short.webm' 15 const fixturePath = 'server/tests/fixtures/video_short.webm'
15 const fps = await getVideoFileFPS(fixturePath) 16 const fps = await getVideoFileFPS(fixturePath)
@@ -19,7 +20,7 @@ describe('Test create transcoding jobs', function () {
19 VideoResolution.H_720P, 20 VideoResolution.H_720P,
20 VideoResolution.H_1080P 21 VideoResolution.H_1080P
21 ]) { 22 ]) {
22 const command = await execCLI(`npm run print-transcode-command -- ${fixturePath} -r ${resolution}`) 23 const command = await CLICommand.exec(`npm run print-transcode-command -- ${fixturePath} -r ${resolution}`)
23 const targetBitrate = Math.min(getTargetBitrate(resolution, fps, VIDEO_TRANSCODING_FPS), bitrate) 24 const targetBitrate = Math.min(getTargetBitrate(resolution, fps, VIDEO_TRANSCODING_FPS), bitrate)
24 25
25 expect(command).to.includes(`-vf scale=w=-2:h=${resolution}`) 26 expect(command).to.includes(`-vf scale=w=-2:h=${resolution}`)
diff --git a/server/tests/cli/prune-storage.ts b/server/tests/cli/prune-storage.ts
index a0af09de8..954a87833 100644
--- a/server/tests/cli/prune-storage.ts
+++ b/server/tests/cli/prune-storage.ts
@@ -5,87 +5,78 @@ import * as chai from 'chai'
5import { createFile, readdir } from 'fs-extra' 5import { createFile, readdir } from 'fs-extra'
6import { join } from 'path' 6import { join } from 'path'
7import { buildUUID } from '@server/helpers/uuid' 7import { buildUUID } from '@server/helpers/uuid'
8import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
9import { 8import {
10 buildServerDirectory,
11 cleanupTests, 9 cleanupTests,
12 createVideoPlaylist, 10 CLICommand,
11 createMultipleServers,
13 doubleFollow, 12 doubleFollow,
14 execCLI,
15 flushAndRunMultipleServers,
16 getAccount,
17 getEnvCli,
18 killallServers, 13 killallServers,
19 makeGetRequest, 14 makeGetRequest,
20 ServerInfo, 15 PeerTubeServer,
21 setAccessTokensToServers, 16 setAccessTokensToServers,
22 setDefaultVideoChannel, 17 setDefaultVideoChannel,
23 updateMyAvatar, 18 wait,
24 uploadVideo, 19 waitJobs
25 wait 20} from '@shared/extra-utils'
26} from '../../../shared/extra-utils' 21import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
27import { waitJobs } from '../../../shared/extra-utils/server/jobs'
28import { Account, VideoPlaylistPrivacy } from '../../../shared/models'
29 22
30const expect = chai.expect 23const expect = chai.expect
31 24
32async function countFiles (internalServerNumber: number, directory: string) { 25async function countFiles (server: PeerTubeServer, directory: string) {
33 const files = await readdir(buildServerDirectory({ internalServerNumber }, directory)) 26 const files = await readdir(server.servers.buildDirectory(directory))
34 27
35 return files.length 28 return files.length
36} 29}
37 30
38async function assertNotExists (internalServerNumber: number, directory: string, substring: string) { 31async function assertNotExists (server: PeerTubeServer, directory: string, substring: string) {
39 const files = await readdir(buildServerDirectory({ internalServerNumber }, directory)) 32 const files = await readdir(server.servers.buildDirectory(directory))
40 33
41 for (const f of files) { 34 for (const f of files) {
42 expect(f).to.not.contain(substring) 35 expect(f).to.not.contain(substring)
43 } 36 }
44} 37}
45 38
46async function assertCountAreOkay (servers: ServerInfo[]) { 39async function assertCountAreOkay (servers: PeerTubeServer[]) {
47 for (const server of servers) { 40 for (const server of servers) {
48 const videosCount = await countFiles(server.internalServerNumber, 'videos') 41 const videosCount = await countFiles(server, 'videos')
49 expect(videosCount).to.equal(8) 42 expect(videosCount).to.equal(8)
50 43
51 const torrentsCount = await countFiles(server.internalServerNumber, 'torrents') 44 const torrentsCount = await countFiles(server, 'torrents')
52 expect(torrentsCount).to.equal(16) 45 expect(torrentsCount).to.equal(16)
53 46
54 const previewsCount = await countFiles(server.internalServerNumber, 'previews') 47 const previewsCount = await countFiles(server, 'previews')
55 expect(previewsCount).to.equal(2) 48 expect(previewsCount).to.equal(2)
56 49
57 const thumbnailsCount = await countFiles(server.internalServerNumber, 'thumbnails') 50 const thumbnailsCount = await countFiles(server, 'thumbnails')
58 expect(thumbnailsCount).to.equal(6) 51 expect(thumbnailsCount).to.equal(6)
59 52
60 const avatarsCount = await countFiles(server.internalServerNumber, 'avatars') 53 const avatarsCount = await countFiles(server, 'avatars')
61 expect(avatarsCount).to.equal(2) 54 expect(avatarsCount).to.equal(2)
62 } 55 }
63} 56}
64 57
65describe('Test prune storage scripts', function () { 58describe('Test prune storage scripts', function () {
66 let servers: ServerInfo[] 59 let servers: PeerTubeServer[]
67 const badNames: { [directory: string]: string[] } = {} 60 const badNames: { [directory: string]: string[] } = {}
68 61
69 before(async function () { 62 before(async function () {
70 this.timeout(120000) 63 this.timeout(120000)
71 64
72 servers = await flushAndRunMultipleServers(2, { transcoding: { enabled: true } }) 65 servers = await createMultipleServers(2, { transcoding: { enabled: true } })
73 await setAccessTokensToServers(servers) 66 await setAccessTokensToServers(servers)
74 await setDefaultVideoChannel(servers) 67 await setDefaultVideoChannel(servers)
75 68
76 for (const server of servers) { 69 for (const server of servers) {
77 await uploadVideo(server.url, server.accessToken, { name: 'video 1' }) 70 await server.videos.upload({ attributes: { name: 'video 1' } })
78 await uploadVideo(server.url, server.accessToken, { name: 'video 2' }) 71 await server.videos.upload({ attributes: { name: 'video 2' } })
79 72
80 await updateMyAvatar({ url: server.url, accessToken: server.accessToken, fixture: 'avatar.png' }) 73 await server.users.updateMyAvatar({ fixture: 'avatar.png' })
81 74
82 await createVideoPlaylist({ 75 await server.playlists.create({
83 url: server.url, 76 attributes: {
84 token: server.accessToken,
85 playlistAttrs: {
86 displayName: 'playlist', 77 displayName: 'playlist',
87 privacy: VideoPlaylistPrivacy.PUBLIC, 78 privacy: VideoPlaylistPrivacy.PUBLIC,
88 videoChannelId: server.videoChannel.id, 79 videoChannelId: server.store.channel.id,
89 thumbnailfile: 'thumbnail.jpg' 80 thumbnailfile: 'thumbnail.jpg'
90 } 81 }
91 }) 82 })
@@ -95,29 +86,27 @@ describe('Test prune storage scripts', function () {
95 86
96 // Lazy load the remote avatar 87 // Lazy load the remote avatar
97 { 88 {
98 const res = await getAccount(servers[0].url, 'root@localhost:' + servers[1].port) 89 const account = await servers[0].accounts.get({ accountName: 'root@localhost:' + servers[1].port })
99 const account: Account = res.body
100 await makeGetRequest({ 90 await makeGetRequest({
101 url: servers[0].url, 91 url: servers[0].url,
102 path: account.avatar.path, 92 path: account.avatar.path,
103 statusCodeExpected: HttpStatusCode.OK_200 93 expectedStatus: HttpStatusCode.OK_200
104 }) 94 })
105 } 95 }
106 96
107 { 97 {
108 const res = await getAccount(servers[1].url, 'root@localhost:' + servers[0].port) 98 const account = await servers[1].accounts.get({ accountName: 'root@localhost:' + servers[0].port })
109 const account: Account = res.body
110 await makeGetRequest({ 99 await makeGetRequest({
111 url: servers[1].url, 100 url: servers[1].url,
112 path: account.avatar.path, 101 path: account.avatar.path,
113 statusCodeExpected: HttpStatusCode.OK_200 102 expectedStatus: HttpStatusCode.OK_200
114 }) 103 })
115 } 104 }
116 105
117 await wait(1000) 106 await wait(1000)
118 107
119 await waitJobs(servers) 108 await waitJobs(servers)
120 killallServers(servers) 109 await killallServers(servers)
121 110
122 await wait(1000) 111 await wait(1000)
123 }) 112 })
@@ -129,7 +118,7 @@ describe('Test prune storage scripts', function () {
129 it('Should create some dirty files', async function () { 118 it('Should create some dirty files', async function () {
130 for (let i = 0; i < 2; i++) { 119 for (let i = 0; i < 2; i++) {
131 { 120 {
132 const base = buildServerDirectory(servers[0], 'videos') 121 const base = servers[0].servers.buildDirectory('videos')
133 122
134 const n1 = buildUUID() + '.mp4' 123 const n1 = buildUUID() + '.mp4'
135 const n2 = buildUUID() + '.webm' 124 const n2 = buildUUID() + '.webm'
@@ -141,7 +130,7 @@ describe('Test prune storage scripts', function () {
141 } 130 }
142 131
143 { 132 {
144 const base = buildServerDirectory(servers[0], 'torrents') 133 const base = servers[0].servers.buildDirectory('torrents')
145 134
146 const n1 = buildUUID() + '-240.torrent' 135 const n1 = buildUUID() + '-240.torrent'
147 const n2 = buildUUID() + '-480.torrent' 136 const n2 = buildUUID() + '-480.torrent'
@@ -153,7 +142,7 @@ describe('Test prune storage scripts', function () {
153 } 142 }
154 143
155 { 144 {
156 const base = buildServerDirectory(servers[0], 'thumbnails') 145 const base = servers[0].servers.buildDirectory('thumbnails')
157 146
158 const n1 = buildUUID() + '.jpg' 147 const n1 = buildUUID() + '.jpg'
159 const n2 = buildUUID() + '.jpg' 148 const n2 = buildUUID() + '.jpg'
@@ -165,7 +154,7 @@ describe('Test prune storage scripts', function () {
165 } 154 }
166 155
167 { 156 {
168 const base = buildServerDirectory(servers[0], 'previews') 157 const base = servers[0].servers.buildDirectory('previews')
169 158
170 const n1 = buildUUID() + '.jpg' 159 const n1 = buildUUID() + '.jpg'
171 const n2 = buildUUID() + '.jpg' 160 const n2 = buildUUID() + '.jpg'
@@ -177,7 +166,7 @@ describe('Test prune storage scripts', function () {
177 } 166 }
178 167
179 { 168 {
180 const base = buildServerDirectory(servers[0], 'avatars') 169 const base = servers[0].servers.buildDirectory('avatars')
181 170
182 const n1 = buildUUID() + '.png' 171 const n1 = buildUUID() + '.png'
183 const n2 = buildUUID() + '.jpg' 172 const n2 = buildUUID() + '.jpg'
@@ -193,8 +182,8 @@ describe('Test prune storage scripts', function () {
193 it('Should run prune storage', async function () { 182 it('Should run prune storage', async function () {
194 this.timeout(30000) 183 this.timeout(30000)
195 184
196 const env = getEnvCli(servers[0]) 185 const env = servers[0].cli.getEnv()
197 await execCLI(`echo y | ${env} npm run prune-storage`) 186 await CLICommand.exec(`echo y | ${env} npm run prune-storage`)
198 }) 187 })
199 188
200 it('Should have removed files', async function () { 189 it('Should have removed files', async function () {
@@ -202,7 +191,7 @@ describe('Test prune storage scripts', function () {
202 191
203 for (const directory of Object.keys(badNames)) { 192 for (const directory of Object.keys(badNames)) {
204 for (const name of badNames[directory]) { 193 for (const name of badNames[directory]) {
205 await assertNotExists(servers[0].internalServerNumber, directory, name) 194 await assertNotExists(servers[0], directory, name)
206 } 195 }
207 } 196 }
208 }) 197 })
diff --git a/server/tests/cli/regenerate-thumbnails.ts b/server/tests/cli/regenerate-thumbnails.ts
index 8acb9f263..780c9b4bd 100644
--- a/server/tests/cli/regenerate-thumbnails.ts
+++ b/server/tests/cli/regenerate-thumbnails.ts
@@ -2,36 +2,33 @@ import 'mocha'
2import { expect } from 'chai' 2import { expect } from 'chai'
3import { writeFile } from 'fs-extra' 3import { writeFile } from 'fs-extra'
4import { basename, join } from 'path' 4import { basename, join } from 'path'
5import { Video, VideoDetails } from '@shared/models' 5import { HttpStatusCode, Video } from '@shared/models'
6import { 6import {
7 buildServerDirectory,
8 cleanupTests, 7 cleanupTests,
8 createMultipleServers,
9 doubleFollow, 9 doubleFollow,
10 execCLI,
11 flushAndRunMultipleServers,
12 getEnvCli,
13 getVideo,
14 makeRawRequest, 10 makeRawRequest,
15 ServerInfo, 11 PeerTubeServer,
16 setAccessTokensToServers, 12 setAccessTokensToServers,
17 uploadVideoAndGetId,
18 waitJobs 13 waitJobs
19} from '../../../shared/extra-utils' 14} from '../../../shared/extra-utils'
20import { HttpStatusCode } from '@shared/core-utils'
21 15
22async function testThumbnail (server: ServerInfo, videoId: number | string) { 16async function testThumbnail (server: PeerTubeServer, videoId: number | string) {
23 const res = await getVideo(server.url, videoId) 17 const video = await server.videos.get({ id: videoId })
24 const video: VideoDetails = res.body
25 18
26 const res1 = await makeRawRequest(join(server.url, video.thumbnailPath), HttpStatusCode.OK_200) 19 const requests = [
27 expect(res1.body).to.not.have.lengthOf(0) 20 makeRawRequest(join(server.url, video.thumbnailPath), HttpStatusCode.OK_200),
21 makeRawRequest(join(server.url, video.thumbnailPath), HttpStatusCode.OK_200)
22 ]
28 23
29 const res2 = await makeRawRequest(join(server.url, video.thumbnailPath), HttpStatusCode.OK_200) 24 for (const req of requests) {
30 expect(res2.body).to.not.have.lengthOf(0) 25 const res = await req
26 expect(res.body).to.not.have.lengthOf(0)
27 }
31} 28}
32 29
33describe('Test regenerate thumbnails script', function () { 30describe('Test regenerate thumbnails script', function () {
34 let servers: ServerInfo[] 31 let servers: PeerTubeServer[]
35 32
36 let video1: Video 33 let video1: Video
37 let video2: Video 34 let video2: Video
@@ -43,28 +40,28 @@ describe('Test regenerate thumbnails script', function () {
43 before(async function () { 40 before(async function () {
44 this.timeout(60000) 41 this.timeout(60000)
45 42
46 servers = await flushAndRunMultipleServers(2) 43 servers = await createMultipleServers(2)
47 await setAccessTokensToServers(servers) 44 await setAccessTokensToServers(servers)
48 45
49 await doubleFollow(servers[0], servers[1]) 46 await doubleFollow(servers[0], servers[1])
50 47
51 { 48 {
52 const videoUUID1 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 1' })).uuid 49 const videoUUID1 = (await servers[0].videos.quickUpload({ name: 'video 1' })).uuid
53 video1 = await (getVideo(servers[0].url, videoUUID1).then(res => res.body)) 50 video1 = await servers[0].videos.get({ id: videoUUID1 })
54 51
55 thumbnail1Path = join(buildServerDirectory(servers[0], 'thumbnails'), basename(video1.thumbnailPath)) 52 thumbnail1Path = join(servers[0].servers.buildDirectory('thumbnails'), basename(video1.thumbnailPath))
56 53
57 const videoUUID2 = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video 2' })).uuid 54 const videoUUID2 = (await servers[0].videos.quickUpload({ name: 'video 2' })).uuid
58 video2 = await (getVideo(servers[0].url, videoUUID2).then(res => res.body)) 55 video2 = await servers[0].videos.get({ id: videoUUID2 })
59 } 56 }
60 57
61 { 58 {
62 const videoUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video 3' })).uuid 59 const videoUUID = (await servers[1].videos.quickUpload({ name: 'video 3' })).uuid
63 await waitJobs(servers) 60 await waitJobs(servers)
64 61
65 remoteVideo = await (getVideo(servers[0].url, videoUUID).then(res => res.body)) 62 remoteVideo = await servers[0].videos.get({ id: videoUUID })
66 63
67 thumbnailRemotePath = join(buildServerDirectory(servers[0], 'thumbnails'), basename(remoteVideo.thumbnailPath)) 64 thumbnailRemotePath = join(servers[0].servers.buildDirectory('thumbnails'), basename(remoteVideo.thumbnailPath))
68 } 65 }
69 66
70 await writeFile(thumbnail1Path, '') 67 await writeFile(thumbnail1Path, '')
@@ -91,8 +88,7 @@ describe('Test regenerate thumbnails script', function () {
91 it('Should regenerate local thumbnails from the CLI', async function () { 88 it('Should regenerate local thumbnails from the CLI', async function () {
92 this.timeout(15000) 89 this.timeout(15000)
93 90
94 const env = getEnvCli(servers[0]) 91 await servers[0].cli.execWithEnv(`npm run regenerate-thumbnails`)
95 await execCLI(`${env} npm run regenerate-thumbnails`)
96 }) 92 })
97 93
98 it('Should have generated new thumbnail files', async function () { 94 it('Should have generated new thumbnail files', async function () {
diff --git a/server/tests/cli/reset-password.ts b/server/tests/cli/reset-password.ts
index a84463b33..4a02db35d 100644
--- a/server/tests/cli/reset-password.ts
+++ b/server/tests/cli/reset-password.ts
@@ -1,35 +1,24 @@
1import 'mocha' 1import 'mocha'
2 2import { cleanupTests, CLICommand, createSingleServer, PeerTubeServer, setAccessTokensToServers } from '../../../shared/extra-utils'
3import {
4 cleanupTests,
5 createUser,
6 execCLI,
7 flushAndRunServer,
8 getEnvCli,
9 login,
10 ServerInfo,
11 setAccessTokensToServers
12} from '../../../shared/extra-utils'
13import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
14 3
15describe('Test reset password scripts', function () { 4describe('Test reset password scripts', function () {
16 let server: ServerInfo 5 let server: PeerTubeServer
17 6
18 before(async function () { 7 before(async function () {
19 this.timeout(30000) 8 this.timeout(30000)
20 server = await flushAndRunServer(1) 9 server = await createSingleServer(1)
21 await setAccessTokensToServers([ server ]) 10 await setAccessTokensToServers([ server ])
22 11
23 await createUser({ url: server.url, accessToken: server.accessToken, username: 'user_1', password: 'super password' }) 12 await server.users.create({ username: 'user_1', password: 'super password' })
24 }) 13 })
25 14
26 it('Should change the user password from CLI', async function () { 15 it('Should change the user password from CLI', async function () {
27 this.timeout(60000) 16 this.timeout(60000)
28 17
29 const env = getEnvCli(server) 18 const env = server.cli.getEnv()
30 await execCLI(`echo coucou | ${env} npm run reset-password -- -u user_1`) 19 await CLICommand.exec(`echo coucou | ${env} npm run reset-password -- -u user_1`)
31 20
32 await login(server.url, server.client, { username: 'user_1', password: 'coucou' }, HttpStatusCode.OK_200) 21 await server.login.login({ user: { username: 'user_1', password: 'coucou' } })
33 }) 22 })
34 23
35 after(async function () { 24 after(async function () {
diff --git a/server/tests/cli/update-host.ts b/server/tests/cli/update-host.ts
index 2070f16f5..fcbcb55ba 100644
--- a/server/tests/cli/update-host.ts
+++ b/server/tests/cli/update-host.ts
@@ -1,33 +1,20 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import { expect } from 'chai'
5import { VideoDetails } from '../../../shared/models/videos'
6import { waitJobs } from '../../../shared/extra-utils/server/jobs'
7import { addVideoCommentThread } from '../../../shared/extra-utils/videos/video-comments'
8import { 5import {
9 addVideoChannel,
10 cleanupTests, 6 cleanupTests,
11 createUser, 7 createSingleServer,
12 execCLI,
13 flushAndRunServer,
14 getEnvCli,
15 getVideo,
16 getVideoChannelsList,
17 getVideosList,
18 killallServers, 8 killallServers,
19 makeActivityPubGetRequest, 9 makeActivityPubGetRequest,
20 parseTorrentVideo, reRunServer, 10 parseTorrentVideo,
21 ServerInfo, 11 PeerTubeServer,
22 setAccessTokensToServers, 12 setAccessTokensToServers,
23 uploadVideo 13 waitJobs
24} from '../../../shared/extra-utils' 14} from '@shared/extra-utils'
25import { getAccountsList } from '../../../shared/extra-utils/users/accounts'
26
27const expect = chai.expect
28 15
29describe('Test update host scripts', function () { 16describe('Test update host scripts', function () {
30 let server: ServerInfo 17 let server: PeerTubeServer
31 18
32 before(async function () { 19 before(async function () {
33 this.timeout(60000) 20 this.timeout(60000)
@@ -38,17 +25,15 @@ describe('Test update host scripts', function () {
38 } 25 }
39 } 26 }
40 // Run server 2 to have transcoding enabled 27 // Run server 2 to have transcoding enabled
41 server = await flushAndRunServer(2, overrideConfig) 28 server = await createSingleServer(2, overrideConfig)
42 await setAccessTokensToServers([ server ]) 29 await setAccessTokensToServers([ server ])
43 30
44 // Upload two videos for our needs 31 // Upload two videos for our needs
45 const videoAttributes = {} 32 const { uuid: video1UUID } = await server.videos.upload()
46 const resVideo1 = await uploadVideo(server.url, server.accessToken, videoAttributes) 33 await server.videos.upload()
47 const video1UUID = resVideo1.body.video.uuid
48 await uploadVideo(server.url, server.accessToken, videoAttributes)
49 34
50 // Create a user 35 // Create a user
51 await createUser({ url: server.url, accessToken: server.accessToken, username: 'toto', password: 'coucou' }) 36 await server.users.create({ username: 'toto', password: 'coucou' })
52 37
53 // Create channel 38 // Create channel
54 const videoChannel = { 39 const videoChannel = {
@@ -56,11 +41,11 @@ describe('Test update host scripts', function () {
56 displayName: 'second video channel', 41 displayName: 'second video channel',
57 description: 'super video channel description' 42 description: 'super video channel description'
58 } 43 }
59 await addVideoChannel(server.url, server.accessToken, videoChannel) 44 await server.channels.create({ attributes: videoChannel })
60 45
61 // Create comments 46 // Create comments
62 const text = 'my super first comment' 47 const text = 'my super first comment'
63 await addVideoCommentThread(server.url, server.accessToken, video1UUID, text) 48 await server.comments.createThread({ videoId: video1UUID, text })
64 49
65 await waitJobs(server) 50 await waitJobs(server)
66 }) 51 })
@@ -68,25 +53,23 @@ describe('Test update host scripts', function () {
68 it('Should run update host', async function () { 53 it('Should run update host', async function () {
69 this.timeout(30000) 54 this.timeout(30000)
70 55
71 killallServers([ server ]) 56 await killallServers([ server ])
72 // Run server with standard configuration 57 // Run server with standard configuration
73 await reRunServer(server) 58 await server.run()
74 59
75 const env = getEnvCli(server) 60 await server.cli.execWithEnv(`npm run update-host`)
76 await execCLI(`${env} npm run update-host`)
77 }) 61 })
78 62
79 it('Should have updated videos url', async function () { 63 it('Should have updated videos url', async function () {
80 const res = await getVideosList(server.url) 64 const { total, data } = await server.videos.list()
81 expect(res.body.total).to.equal(2) 65 expect(total).to.equal(2)
82 66
83 for (const video of res.body.data) { 67 for (const video of data) {
84 const { body } = await makeActivityPubGetRequest(server.url, '/videos/watch/' + video.uuid) 68 const { body } = await makeActivityPubGetRequest(server.url, '/videos/watch/' + video.uuid)
85 69
86 expect(body.id).to.equal('http://localhost:9002/videos/watch/' + video.uuid) 70 expect(body.id).to.equal('http://localhost:9002/videos/watch/' + video.uuid)
87 71
88 const res = await getVideo(server.url, video.uuid) 72 const videoDetails = await server.videos.get({ id: video.uuid })
89 const videoDetails: VideoDetails = res.body
90 73
91 expect(videoDetails.trackerUrls[0]).to.include(server.host) 74 expect(videoDetails.trackerUrls[0]).to.include(server.host)
92 expect(videoDetails.streamingPlaylists[0].playlistUrl).to.include(server.host) 75 expect(videoDetails.streamingPlaylists[0].playlistUrl).to.include(server.host)
@@ -95,10 +78,10 @@ describe('Test update host scripts', function () {
95 }) 78 })
96 79
97 it('Should have updated video channels url', async function () { 80 it('Should have updated video channels url', async function () {
98 const res = await getVideoChannelsList(server.url, 0, 5, '-name') 81 const { data, total } = await server.channels.list({ sort: '-name' })
99 expect(res.body.total).to.equal(3) 82 expect(total).to.equal(3)
100 83
101 for (const channel of res.body.data) { 84 for (const channel of data) {
102 const { body } = await makeActivityPubGetRequest(server.url, '/video-channels/' + channel.name) 85 const { body } = await makeActivityPubGetRequest(server.url, '/video-channels/' + channel.name)
103 86
104 expect(body.id).to.equal('http://localhost:9002/video-channels/' + channel.name) 87 expect(body.id).to.equal('http://localhost:9002/video-channels/' + channel.name)
@@ -106,10 +89,10 @@ describe('Test update host scripts', function () {
106 }) 89 })
107 90
108 it('Should have updated accounts url', async function () { 91 it('Should have updated accounts url', async function () {
109 const res = await getAccountsList(server.url) 92 const body = await server.accounts.list()
110 expect(res.body.total).to.equal(3) 93 expect(body.total).to.equal(3)
111 94
112 for (const account of res.body.data) { 95 for (const account of body.data) {
113 const usernameWithDomain = account.name 96 const usernameWithDomain = account.name
114 const { body } = await makeActivityPubGetRequest(server.url, '/accounts/' + usernameWithDomain) 97 const { body } = await makeActivityPubGetRequest(server.url, '/accounts/' + usernameWithDomain)
115 98
@@ -120,13 +103,11 @@ describe('Test update host scripts', function () {
120 it('Should have updated torrent hosts', async function () { 103 it('Should have updated torrent hosts', async function () {
121 this.timeout(30000) 104 this.timeout(30000)
122 105
123 const res = await getVideosList(server.url) 106 const { data } = await server.videos.list()
124 const videos = res.body.data 107 expect(data).to.have.lengthOf(2)
125 expect(videos).to.have.lengthOf(2)
126 108
127 for (const video of videos) { 109 for (const video of data) {
128 const res2 = await getVideo(server.url, video.id) 110 const videoDetails = await server.videos.get({ id: video.id })
129 const videoDetails: VideoDetails = res2.body
130 111
131 expect(videoDetails.files).to.have.lengthOf(4) 112 expect(videoDetails.files).to.have.lengthOf(4)
132 113