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