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