1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { areHttpImportTestsDisabled, buildAbsoluteFixturePath } from '@shared/core-utils'
11 setAccessTokensToServers,
13 } from '@shared/server-commands'
14 import { FIXTURE_URLS, testHelloWorldRegisteredSettings } from '../shared'
16 describe('Test CLI wrapper', function () {
17 let server: PeerTubeServer
18 let userAccessToken: string
20 let cliCommand: CLICommand
22 const cmd = 'node ./dist/server/tools/peertube.js'
24 before(async function () {
27 server = await createSingleServer(1, {
34 await setAccessTokensToServers([ server ])
36 await server.users.create({ username: 'user_1', password: 'super_password' })
38 userAccessToken = await server.login.getAccessToken({ username: 'user_1', password: 'super_password' })
41 const attributes = { name: 'user_channel', displayName: 'User channel', support: 'super support text' }
42 await server.channels.create({ token: userAccessToken, attributes })
45 cliCommand = server.cli
48 describe('Authentication and instance selection', function () {
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()
54 const body = await server.users.getMyInfo({ token })
55 expect(body.username).to.equal('user_1')
58 it('Should display no selected instance', async function () {
61 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
62 expect(stdout).to.contain('no instance selected')
65 it('Should add a user', async function () {
68 await cliCommand.execWithEnv(`${cmd} auth add -u ${server.url} -U user_1 -p super_password`)
71 it('Should not fail to add a user if there is a slash at the end of the instance URL', async function () {
74 let fullServerURL = server.url + '/'
76 await cliCommand.execWithEnv(`${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
78 fullServerURL = server.url + '/asdfasdf'
79 await cliCommand.execWithEnv(`${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
82 it('Should default to this user', async function () {
85 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
86 expect(stdout).to.contain(`instance ${server.url} selected`)
89 it('Should remember the user', async function () {
92 const stdout = await cliCommand.execWithEnv(`${cmd} auth list`)
93 expect(stdout).to.contain(server.url)
97 describe('Video upload/import', function () {
99 it('Should upload a video', async function () {
102 const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4')
103 const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'`
105 await cliCommand.execWithEnv(`${cmd} upload ${params}`)
108 it('Should have the video uploaded', async function () {
109 const { total, data } = await server.videos.list()
110 expect(total).to.equal(1)
112 const video = await server.videos.get({ id: data[0].uuid })
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')
118 it('Should import a video', async function () {
119 if (areHttpImportTestsDisabled()) return
123 const params = `--target-url ${FIXTURE_URLS.youtube} --channel-name user_channel`
124 await cliCommand.execWithEnv(`${cmd} import ${params}`)
127 it('Should have imported the video', async function () {
128 if (areHttpImportTestsDisabled()) return
132 await waitJobs([ server ])
134 const { total, data } = await server.videos.list()
135 expect(total).to.equal(2)
137 const video = data.find(v => v.name === 'small video - youtube')
138 expect(video).to.not.be.undefined
140 const videoDetails = await server.videos.get({ id: video.id })
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
146 it('Should not import again the same video', async function () {
147 if (areHttpImportTestsDisabled()) return
151 const params = `--target-url ${FIXTURE_URLS.youtube} --channel-name user_channel`
152 await cliCommand.execWithEnv(`${cmd} import ${params}`)
154 await waitJobs([ server ])
156 const { total, data } = await server.videos.list()
157 expect(total).to.equal(2)
159 const videos = data.filter(v => v.name === 'small video - youtube')
160 expect(videos).to.have.lengthOf(1)
162 // So we can reimport it
163 await server.videos.remove({ token: userAccessToken, id: videos[0].id })
166 it('Should import and override some imported attributes', async function () {
167 if (areHttpImportTestsDisabled()) return
171 const params = `--target-url ${FIXTURE_URLS.youtube} ` +
172 `--channel-name user_channel --video-name toto --nsfw --support support`
173 await cliCommand.execWithEnv(`${cmd} import ${params}`)
175 await waitJobs([ server ])
178 const { total, data } = await server.videos.list()
179 expect(total).to.equal(2)
181 const video = data.find(v => v.name === 'toto')
182 expect(video).to.not.be.undefined
184 const videoDetails = await server.videos.get({ id: video.id })
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
193 describe('Admin auth', function () {
195 it('Should remove the auth user', async function () {
196 await cliCommand.execWithEnv(`${cmd} auth del ${server.url}`)
198 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
199 expect(stdout).to.contain('no instance selected')
202 it('Should add the admin user', async function () {
203 await cliCommand.execWithEnv(`${cmd} auth add -u ${server.url} -U root -p test${server.internalServerNumber}`)
207 describe('Manage plugins', function () {
209 it('Should install a plugin', async function () {
212 await cliCommand.execWithEnv(`${cmd} plugins install --npm-name peertube-plugin-hello-world`)
215 it('Should have registered settings', async function () {
216 await testHelloWorldRegisteredSettings(server)
219 it('Should list installed plugins', async function () {
220 const res = await cliCommand.execWithEnv(`${cmd} plugins list`)
222 expect(res).to.contain('peertube-plugin-hello-world')
225 it('Should uninstall the plugin', async function () {
226 const res = await cliCommand.execWithEnv(`${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`)
228 expect(res).to.not.contain('peertube-plugin-hello-world')
231 it('Should install a plugin in requested version', async function () {
234 await cliCommand.execWithEnv(`${cmd} plugins install --npm-name peertube-plugin-hello-world --plugin-version 0.0.17`)
237 it('Should list installed plugins, in correct version', async function () {
238 const res = await cliCommand.execWithEnv(`${cmd} plugins list`)
240 expect(res).to.contain('peertube-plugin-hello-world')
241 expect(res).to.contain('0.0.17')
244 it('Should uninstall the plugin again', async function () {
245 const res = await cliCommand.execWithEnv(`${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`)
247 expect(res).to.not.contain('peertube-plugin-hello-world')
250 it('Should install a plugin in requested beta version', async function () {
253 await cliCommand.execWithEnv(`${cmd} plugins install --npm-name peertube-plugin-hello-world --plugin-version 0.0.21-beta.1`)
255 const res = await cliCommand.execWithEnv(`${cmd} plugins list`)
257 expect(res).to.contain('peertube-plugin-hello-world')
258 expect(res).to.contain('0.0.21-beta.1')
260 await cliCommand.execWithEnv(`${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`)
264 describe('Manage video redundancies', function () {
265 let anotherServer: PeerTubeServer
266 let video1Server2: number
267 let servers: PeerTubeServer[]
269 before(async function () {
272 anotherServer = await createSingleServer(2)
273 await setAccessTokensToServers([ anotherServer ])
275 await doubleFollow(server, anotherServer)
277 servers = [ server, anotherServer ]
278 await waitJobs(servers)
280 const { uuid } = await anotherServer.videos.quickUpload({ name: 'super video' })
281 await waitJobs(servers)
283 video1Server2 = await server.videos.getId({ uuid })
286 it('Should add a redundancy', async function () {
289 const params = `add --video ${video1Server2}`
290 await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
292 await waitJobs(servers)
295 it('Should list redundancies', async function () {
299 const params = 'list-my-redundancies'
300 const stdout = await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
302 expect(stdout).to.contain('super video')
303 expect(stdout).to.contain(server.host)
307 it('Should remove a redundancy', async function () {
310 const params = `remove --video ${video1Server2}`
311 await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
313 await waitJobs(servers)
316 const params = 'list-my-redundancies'
317 const stdout = await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
319 expect(stdout).to.not.contain('super video')
323 after(async function () {
326 await cleanupTests([ anotherServer ])
330 after(async function () {
333 await cleanupTests([ server ])