]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/cli/peertube.ts
348438533473bc64531f6b1a3c93a15b321e9f52
[github/Chocobozzz/PeerTube.git] / server / tests / cli / peertube.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import { expect } from 'chai'
5 import { Video, VideoDetails } from '../../../shared'
6 import {
7 addVideoChannel,
8 areHttpImportTestsDisabled,
9 buildAbsoluteFixturePath,
10 cleanupTests,
11 createUser,
12 doubleFollow,
13 execCLI,
14 flushAndRunServer,
15 getEnvCli,
16 getLocalIdByUUID,
17 getVideo,
18 getVideosList,
19 removeVideo,
20 ServerInfo,
21 setAccessTokensToServers,
22 testHelloWorldRegisteredSettings,
23 uploadVideoAndGetId,
24 userLogin,
25 waitJobs
26 } from '../../../shared/extra-utils'
27 import { getYoutubeVideoUrl } from '../../../shared/extra-utils/videos/video-imports'
28
29 describe('Test CLI wrapper', function () {
30 let server: ServerInfo
31 let userAccessToken: string
32
33 const cmd = 'node ./dist/server/tools/peertube.js'
34
35 before(async function () {
36 this.timeout(30000)
37
38 server = await flushAndRunServer(1)
39 await setAccessTokensToServers([ server ])
40
41 await createUser({ url: server.url, accessToken: server.accessToken, username: 'user_1', password: 'super_password' })
42
43 userAccessToken = await userLogin(server, { username: 'user_1', password: 'super_password' })
44
45 {
46 const args = { name: 'user_channel', displayName: 'User channel', support: 'super support text' }
47 await addVideoChannel(server.url, userAccessToken, args)
48 }
49 })
50
51 describe('Authentication and instance selection', function () {
52
53 it('Should display no selected instance', async function () {
54 this.timeout(60000)
55
56 const env = getEnvCli(server)
57 const stdout = await execCLI(`${env} ${cmd} --help`)
58
59 expect(stdout).to.contain('no instance selected')
60 })
61
62 it('Should add a user', async function () {
63 this.timeout(60000)
64
65 const env = getEnvCli(server)
66 await execCLI(`${env} ${cmd} auth add -u ${server.url} -U user_1 -p super_password`)
67 })
68
69 it('Should default to this user', async function () {
70 this.timeout(60000)
71
72 const env = getEnvCli(server)
73 const stdout = await execCLI(`${env} ${cmd} --help`)
74
75 expect(stdout).to.contain(`instance ${server.url} selected`)
76 })
77
78 it('Should remember the user', async function () {
79 this.timeout(60000)
80
81 const env = getEnvCli(server)
82 const stdout = await execCLI(`${env} ${cmd} auth list`)
83
84 expect(stdout).to.contain(server.url)
85 })
86 })
87
88 describe('Video upload/import', function () {
89
90 it('Should upload a video', async function () {
91 this.timeout(60000)
92
93 const env = getEnvCli(server)
94
95 const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4')
96
97 const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'`
98
99 await execCLI(`${env} ${cmd} upload ${params}`)
100 })
101
102 it('Should have the video uploaded', async function () {
103 const res = await getVideosList(server.url)
104
105 expect(res.body.total).to.equal(1)
106
107 const videos: Video[] = res.body.data
108
109 const video: VideoDetails = (await getVideo(server.url, videos[0].uuid)).body
110
111 expect(video.name).to.equal('test upload')
112 expect(video.support).to.equal('support_text')
113 expect(video.channel.name).to.equal('user_channel')
114 })
115
116 it('Should import a video', async function () {
117 if (areHttpImportTestsDisabled()) return
118
119 this.timeout(60000)
120
121 const env = getEnvCli(server)
122
123 const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel`
124
125 await execCLI(`${env} ${cmd} import ${params}`)
126 })
127
128 it('Should have imported the video', async function () {
129 if (areHttpImportTestsDisabled()) return
130
131 this.timeout(60000)
132
133 await waitJobs([ server ])
134
135 const res = await getVideosList(server.url)
136
137 expect(res.body.total).to.equal(2)
138
139 const videos: Video[] = res.body.data
140 const video = videos.find(v => v.name === 'small video - youtube')
141 expect(video).to.not.be.undefined
142
143 const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
144 expect(videoDetails.channel.name).to.equal('user_channel')
145 expect(videoDetails.support).to.equal('super support text')
146 expect(videoDetails.nsfw).to.be.false
147
148 // So we can reimport it
149 await removeVideo(server.url, userAccessToken, video.id)
150 })
151
152 it('Should import and override some imported attributes', async function () {
153 if (areHttpImportTestsDisabled()) return
154
155 this.timeout(60000)
156
157 const env = getEnvCli(server)
158
159 const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel --video-name toto --nsfw --support support`
160
161 await execCLI(`${env} ${cmd} import ${params}`)
162
163 await waitJobs([ server ])
164
165 {
166 const res = await getVideosList(server.url)
167 expect(res.body.total).to.equal(2)
168
169 const videos: Video[] = res.body.data
170 const video = videos.find(v => v.name === 'toto')
171 expect(video).to.not.be.undefined
172
173 const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
174 expect(videoDetails.channel.name).to.equal('user_channel')
175 expect(videoDetails.support).to.equal('support')
176 expect(videoDetails.nsfw).to.be.true
177 expect(videoDetails.commentsEnabled).to.be.true
178 }
179 })
180 })
181
182 describe('Admin auth', function () {
183
184 it('Should remove the auth user', async function () {
185 const env = getEnvCli(server)
186
187 await execCLI(`${env} ${cmd} auth del ${server.url}`)
188
189 const stdout = await execCLI(`${env} ${cmd} --help`)
190
191 expect(stdout).to.contain('no instance selected')
192 })
193
194 it('Should add the admin user', async function () {
195 const env = getEnvCli(server)
196 await execCLI(`${env} ${cmd} auth add -u ${server.url} -U root -p test${server.internalServerNumber}`)
197 })
198 })
199
200 describe('Manage plugins', function () {
201
202 it('Should install a plugin', async function () {
203 this.timeout(60000)
204
205 const env = getEnvCli(server)
206 await execCLI(`${env} ${cmd} plugins install --npm-name peertube-plugin-hello-world`)
207 })
208
209 it('Should have registered settings', async function () {
210 await testHelloWorldRegisteredSettings(server)
211 })
212
213 it('Should list installed plugins', async function () {
214 const env = getEnvCli(server)
215 const res = await execCLI(`${env} ${cmd} plugins list`)
216
217 expect(res).to.contain('peertube-plugin-hello-world')
218 })
219
220 it('Should uninstall the plugin', async function () {
221 const env = getEnvCli(server)
222 const res = await execCLI(`${env} ${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`)
223
224 expect(res).to.not.contain('peertube-plugin-hello-world')
225 })
226 })
227
228 describe('Manage video redundancies', function () {
229 let anotherServer: ServerInfo
230 let video1Server2: number
231 let servers: ServerInfo[]
232
233 before(async function () {
234 this.timeout(120000)
235
236 anotherServer = await flushAndRunServer(2)
237 await setAccessTokensToServers([ anotherServer ])
238
239 await doubleFollow(server, anotherServer)
240
241 servers = [ server, anotherServer ]
242 await waitJobs(servers)
243
244 const uuid = (await uploadVideoAndGetId({ server: anotherServer, videoName: 'super video' })).uuid
245 await waitJobs(servers)
246
247 video1Server2 = await getLocalIdByUUID(server.url, uuid)
248 })
249
250 it('Should add a redundancy', async function () {
251 this.timeout(60000)
252
253 const env = getEnvCli(server)
254
255 const params = `add --video ${video1Server2}`
256
257 await execCLI(`${env} ${cmd} redundancy ${params}`)
258
259 await waitJobs(servers)
260 })
261
262 it('Should list redundancies', async function () {
263 this.timeout(60000)
264
265 {
266 const env = getEnvCli(server)
267
268 const params = 'list-my-redundancies'
269 const stdout = await execCLI(`${env} ${cmd} redundancy ${params}`)
270
271 expect(stdout).to.contain('super video')
272 expect(stdout).to.contain(`localhost:${server.port}`)
273 }
274 })
275
276 it('Should remove a redundancy', async function () {
277 this.timeout(60000)
278
279 const env = getEnvCli(server)
280
281 const params = `remove --video ${video1Server2}`
282
283 await execCLI(`${env} ${cmd} redundancy ${params}`)
284
285 await waitJobs(servers)
286
287 {
288 const env = getEnvCli(server)
289 const params = 'list-my-redundancies'
290 const stdout = await execCLI(`${env} ${cmd} redundancy ${params}`)
291
292 expect(stdout).to.not.contain('super video')
293 }
294 })
295
296 after(async function () {
297 this.timeout(10000)
298
299 await cleanupTests([ anotherServer ])
300 })
301 })
302
303 after(async function () {
304 this.timeout(10000)
305
306 await cleanupTests([ server ])
307 })
308 })