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