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