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