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