1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { expect } from 'chai'
5 import { areHttpImportTestsDisabled, buildAbsoluteFixturePath } from '@shared/core-utils'
12 setAccessTokensToServers,
14 } from '@shared/server-commands'
15 import { FIXTURE_URLS, testHelloWorldRegisteredSettings } from '../shared'
17 describe('Test CLI wrapper', function () {
18 let server: PeerTubeServer
19 let userAccessToken: string
21 let cliCommand: CLICommand
23 const cmd = 'node ./dist/server/tools/peertube.js'
25 before(async function () {
28 server = await createSingleServer(1)
29 await setAccessTokensToServers([ server ])
31 await server.users.create({ username: 'user_1', password: 'super_password' })
33 userAccessToken = await server.login.getAccessToken({ username: 'user_1', password: 'super_password' })
36 const attributes = { name: 'user_channel', displayName: 'User channel', support: 'super support text' }
37 await server.channels.create({ token: userAccessToken, attributes })
40 cliCommand = server.cli
43 describe('Authentication and instance selection', function () {
45 it('Should get an access token', async function () {
46 const stdout = await cliCommand.execWithEnv(`${cmd} token --url ${server.url} --username user_1 --password super_password`)
47 const token = stdout.trim()
49 const body = await server.users.getMyInfo({ token })
50 expect(body.username).to.equal('user_1')
53 it('Should display no selected instance', async function () {
56 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
57 expect(stdout).to.contain('no instance selected')
60 it('Should add a user', async function () {
63 await cliCommand.execWithEnv(`${cmd} auth add -u ${server.url} -U user_1 -p super_password`)
66 it('Should not fail to add a user if there is a slash at the end of the instance URL', async function () {
69 let fullServerURL = server.url + '/'
71 await cliCommand.execWithEnv(`${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
73 fullServerURL = server.url + '/asdfasdf'
74 await cliCommand.execWithEnv(`${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
77 it('Should default to this user', async function () {
80 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
81 expect(stdout).to.contain(`instance ${server.url} selected`)
84 it('Should remember the user', async function () {
87 const stdout = await cliCommand.execWithEnv(`${cmd} auth list`)
88 expect(stdout).to.contain(server.url)
92 describe('Video upload/import', function () {
94 it('Should upload a video', async function () {
97 const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4')
98 const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'`
100 await cliCommand.execWithEnv(`${cmd} upload ${params}`)
103 it('Should have the video uploaded', async function () {
104 const { total, data } = await server.videos.list()
105 expect(total).to.equal(1)
107 const video = await server.videos.get({ id: data[0].uuid })
108 expect(video.name).to.equal('test upload')
109 expect(video.support).to.equal('support_text')
110 expect(video.channel.name).to.equal('user_channel')
113 it('Should import a video', async function () {
114 if (areHttpImportTestsDisabled()) return
118 const params = `--target-url ${FIXTURE_URLS.youtube} --channel-name user_channel`
119 await cliCommand.execWithEnv(`${cmd} import ${params}`)
122 it('Should have imported the video', async function () {
123 if (areHttpImportTestsDisabled()) return
127 await waitJobs([ server ])
129 const { total, data } = await server.videos.list()
130 expect(total).to.equal(2)
132 const video = data.find(v => v.name === 'small video - youtube')
133 expect(video).to.not.be.undefined
135 const videoDetails = await server.videos.get({ id: video.id })
136 expect(videoDetails.channel.name).to.equal('user_channel')
137 expect(videoDetails.support).to.equal('super support text')
138 expect(videoDetails.nsfw).to.be.false
141 it('Should not import again the same video', async function () {
142 if (areHttpImportTestsDisabled()) return
146 const params = `--target-url ${FIXTURE_URLS.youtube} --channel-name user_channel`
147 await cliCommand.execWithEnv(`${cmd} import ${params}`)
149 await waitJobs([ server ])
151 const { total, data } = await server.videos.list()
152 expect(total).to.equal(2)
154 const videos = data.filter(v => v.name === 'small video - youtube')
155 expect(videos).to.have.lengthOf(1)
157 // So we can reimport it
158 await server.videos.remove({ token: userAccessToken, id: videos[0].id })
161 it('Should import and override some imported attributes', async function () {
162 if (areHttpImportTestsDisabled()) return
166 const params = `--target-url ${FIXTURE_URLS.youtube} ` +
167 `--channel-name user_channel --video-name toto --nsfw --support support`
168 await cliCommand.execWithEnv(`${cmd} import ${params}`)
170 await waitJobs([ server ])
173 const { total, data } = await server.videos.list()
174 expect(total).to.equal(2)
176 const video = data.find(v => v.name === 'toto')
177 expect(video).to.not.be.undefined
179 const videoDetails = await server.videos.get({ id: video.id })
180 expect(videoDetails.channel.name).to.equal('user_channel')
181 expect(videoDetails.support).to.equal('support')
182 expect(videoDetails.nsfw).to.be.true
183 expect(videoDetails.commentsEnabled).to.be.true
188 describe('Admin auth', function () {
190 it('Should remove the auth user', async function () {
191 await cliCommand.execWithEnv(`${cmd} auth del ${server.url}`)
193 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
194 expect(stdout).to.contain('no instance selected')
197 it('Should add the admin user', async function () {
198 await cliCommand.execWithEnv(`${cmd} auth add -u ${server.url} -U root -p test${server.internalServerNumber}`)
202 describe('Manage plugins', function () {
204 it('Should install a plugin', async function () {
207 await cliCommand.execWithEnv(`${cmd} plugins install --npm-name peertube-plugin-hello-world`)
210 it('Should have registered settings', async function () {
211 await testHelloWorldRegisteredSettings(server)
214 it('Should list installed plugins', async function () {
215 const res = await cliCommand.execWithEnv(`${cmd} plugins list`)
217 expect(res).to.contain('peertube-plugin-hello-world')
220 it('Should uninstall the plugin', async function () {
221 const res = await cliCommand.execWithEnv(`${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`)
223 expect(res).to.not.contain('peertube-plugin-hello-world')
226 it('Should install a plugin in requested version', async function () {
229 await cliCommand.execWithEnv(`${cmd} plugins install --npm-name peertube-plugin-hello-world --plugin-version 0.0.17`)
232 it('Should list installed plugins, in correct version', async function () {
233 const res = await cliCommand.execWithEnv(`${cmd} plugins list`)
235 expect(res).to.contain('peertube-plugin-hello-world')
236 expect(res).to.contain('0.0.17')
239 it('Should uninstall the plugin again', async function () {
240 const res = await cliCommand.execWithEnv(`${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`)
242 expect(res).to.not.contain('peertube-plugin-hello-world')
246 describe('Manage video redundancies', function () {
247 let anotherServer: PeerTubeServer
248 let video1Server2: number
249 let servers: PeerTubeServer[]
251 before(async function () {
254 anotherServer = await createSingleServer(2)
255 await setAccessTokensToServers([ anotherServer ])
257 await doubleFollow(server, anotherServer)
259 servers = [ server, anotherServer ]
260 await waitJobs(servers)
262 const { uuid } = await anotherServer.videos.quickUpload({ name: 'super video' })
263 await waitJobs(servers)
265 video1Server2 = await server.videos.getId({ uuid })
268 it('Should add a redundancy', async function () {
271 const params = `add --video ${video1Server2}`
272 await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
274 await waitJobs(servers)
277 it('Should list redundancies', async function () {
281 const params = 'list-my-redundancies'
282 const stdout = await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
284 expect(stdout).to.contain('super video')
285 expect(stdout).to.contain(`localhost:${server.port}`)
289 it('Should remove a redundancy', async function () {
292 const params = `remove --video ${video1Server2}`
293 await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
295 await waitJobs(servers)
298 const params = 'list-my-redundancies'
299 const stdout = await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
301 expect(stdout).to.not.contain('super video')
305 after(async function () {
308 await cleanupTests([ anotherServer ])
312 after(async function () {
315 await cleanupTests([ server ])