]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/cli/peertube.ts
Translated using Weblate (Spanish)
[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 not fail to add a user if there is a slash at the end of the instance URL', async function () {
70 this.timeout(60000)
71
72 const env = getEnvCli(server)
73 let fullServerURL
74 fullServerURL = server.url + '/'
75 await execCLI(`${env} ${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
76
77 fullServerURL = server.url + '/asdfasdf'
78 await execCLI(`${env} ${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
79 })
80
81 it('Should default to this user', async function () {
82 this.timeout(60000)
83
84 const env = getEnvCli(server)
85 const stdout = await execCLI(`${env} ${cmd} --help`)
86
87 expect(stdout).to.contain(`instance ${server.url} selected`)
88 })
89
90 it('Should remember the user', async function () {
91 this.timeout(60000)
92
93 const env = getEnvCli(server)
94 const stdout = await execCLI(`${env} ${cmd} auth list`)
95
96 expect(stdout).to.contain(server.url)
97 })
98 })
99
100 describe('Video upload/import', function () {
101
102 it('Should upload a video', async function () {
103 this.timeout(60000)
104
105 const env = getEnvCli(server)
106
107 const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4')
108
109 const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'`
110
111 await execCLI(`${env} ${cmd} upload ${params}`)
112 })
113
114 it('Should have the video uploaded', async function () {
115 const res = await getVideosList(server.url)
116
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
123 expect(video.name).to.equal('test upload')
124 expect(video.support).to.equal('support_text')
125 expect(video.channel.name).to.equal('user_channel')
126 })
127
128 it('Should import a video', async function () {
129 if (areHttpImportTestsDisabled()) return
130
131 this.timeout(60000)
132
133 const env = getEnvCli(server)
134
135 const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel`
136
137 await execCLI(`${env} ${cmd} import ${params}`)
138 })
139
140 it('Should have imported the video', async function () {
141 if (areHttpImportTestsDisabled()) return
142
143 this.timeout(60000)
144
145 await waitJobs([ server ])
146
147 const res = await getVideosList(server.url)
148
149 expect(res.body.total).to.equal(2)
150
151 const videos: Video[] = res.body.data
152 const video = videos.find(v => v.name === 'small video - youtube')
153 expect(video).to.not.be.undefined
154
155 const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
156 expect(videoDetails.channel.name).to.equal('user_channel')
157 expect(videoDetails.support).to.equal('super support text')
158 expect(videoDetails.nsfw).to.be.false
159
160 // So we can reimport it
161 await removeVideo(server.url, userAccessToken, video.id)
162 })
163
164 it('Should import and override some imported attributes', async function () {
165 if (areHttpImportTestsDisabled()) return
166
167 this.timeout(60000)
168
169 const env = getEnvCli(server)
170
171 const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel --video-name toto --nsfw --support support`
172
173 await execCLI(`${env} ${cmd} import ${params}`)
174
175 await waitJobs([ server ])
176
177 {
178 const res = await getVideosList(server.url)
179 expect(res.body.total).to.equal(2)
180
181 const videos: Video[] = res.body.data
182 const video = videos.find(v => v.name === 'toto')
183 expect(video).to.not.be.undefined
184
185 const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
186 expect(videoDetails.channel.name).to.equal('user_channel')
187 expect(videoDetails.support).to.equal('support')
188 expect(videoDetails.nsfw).to.be.true
189 expect(videoDetails.commentsEnabled).to.be.true
190 }
191 })
192 })
193
194 describe('Admin auth', function () {
195
196 it('Should remove the auth user', async function () {
197 const env = getEnvCli(server)
198
199 await execCLI(`${env} ${cmd} auth del ${server.url}`)
200
201 const stdout = await execCLI(`${env} ${cmd} --help`)
202
203 expect(stdout).to.contain('no instance selected')
204 })
205
206 it('Should add the admin user', async function () {
207 const env = getEnvCli(server)
208 await execCLI(`${env} ${cmd} auth add -u ${server.url} -U root -p test${server.internalServerNumber}`)
209 })
210 })
211
212 describe('Manage plugins', function () {
213
214 it('Should install a plugin', async function () {
215 this.timeout(60000)
216
217 const env = getEnvCli(server)
218 await execCLI(`${env} ${cmd} plugins install --npm-name peertube-plugin-hello-world`)
219 })
220
221 it('Should have registered settings', async function () {
222 await testHelloWorldRegisteredSettings(server)
223 })
224
225 it('Should list installed plugins', async function () {
226 const env = getEnvCli(server)
227 const res = await execCLI(`${env} ${cmd} plugins list`)
228
229 expect(res).to.contain('peertube-plugin-hello-world')
230 })
231
232 it('Should uninstall the plugin', async function () {
233 const env = getEnvCli(server)
234 const res = await execCLI(`${env} ${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`)
235
236 expect(res).to.not.contain('peertube-plugin-hello-world')
237 })
238 })
239
240 describe('Manage video redundancies', function () {
241 let anotherServer: ServerInfo
242 let video1Server2: number
243 let servers: ServerInfo[]
244
245 before(async function () {
246 this.timeout(120000)
247
248 anotherServer = await flushAndRunServer(2)
249 await setAccessTokensToServers([ anotherServer ])
250
251 await doubleFollow(server, anotherServer)
252
253 servers = [ server, anotherServer ]
254 await waitJobs(servers)
255
256 const uuid = (await uploadVideoAndGetId({ server: anotherServer, videoName: 'super video' })).uuid
257 await waitJobs(servers)
258
259 video1Server2 = await getLocalIdByUUID(server.url, uuid)
260 })
261
262 it('Should add a redundancy', async function () {
263 this.timeout(60000)
264
265 const env = getEnvCli(server)
266
267 const params = `add --video ${video1Server2}`
268
269 await execCLI(`${env} ${cmd} redundancy ${params}`)
270
271 await waitJobs(servers)
272 })
273
274 it('Should list redundancies', async function () {
275 this.timeout(60000)
276
277 {
278 const env = getEnvCli(server)
279
280 const params = 'list-my-redundancies'
281 const stdout = await execCLI(`${env} ${cmd} redundancy ${params}`)
282
283 expect(stdout).to.contain('super video')
284 expect(stdout).to.contain(`localhost:${server.port}`)
285 }
286 })
287
288 it('Should remove a redundancy', async function () {
289 this.timeout(60000)
290
291 const env = getEnvCli(server)
292
293 const params = `remove --video ${video1Server2}`
294
295 await execCLI(`${env} ${cmd} redundancy ${params}`)
296
297 await waitJobs(servers)
298
299 {
300 const env = getEnvCli(server)
301 const params = 'list-my-redundancies'
302 const stdout = await execCLI(`${env} ${cmd} redundancy ${params}`)
303
304 expect(stdout).to.not.contain('super video')
305 }
306 })
307
308 after(async function () {
309 this.timeout(10000)
310
311 await cleanupTests([ anotherServer ])
312 })
313 })
314
315 after(async function () {
316 this.timeout(10000)
317
318 await cleanupTests([ server ])
319 })
320 })