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