1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { expect } from 'chai'
6 areHttpImportTestsDisabled,
7 buildAbsoluteFixturePath,
14 setAccessTokensToServers,
15 testHelloWorldRegisteredSettings,
17 } from '../../../shared/extra-utils'
19 describe('Test CLI wrapper', function () {
20 let server: PeerTubeServer
21 let userAccessToken: string
23 let cliCommand: CLICommand
25 const cmd = 'node ./dist/server/tools/peertube.js'
27 before(async function () {
30 server = await createSingleServer(1)
31 await setAccessTokensToServers([ server ])
33 await server.users.create({ username: 'user_1', password: 'super_password' })
35 userAccessToken = await server.login.getAccessToken({ username: 'user_1', password: 'super_password' })
38 const attributes = { name: 'user_channel', displayName: 'User channel', support: 'super support text' }
39 await server.channels.create({ token: userAccessToken, attributes })
42 cliCommand = server.cli
45 describe('Authentication and instance selection', function () {
47 it('Should get an access token', async function () {
48 const stdout = await cliCommand.execWithEnv(`${cmd} token --url ${server.url} --username user_1 --password super_password`)
49 const token = stdout.trim()
51 const body = await server.users.getMyInfo({ token })
52 expect(body.username).to.equal('user_1')
55 it('Should display no selected instance', async function () {
58 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
59 expect(stdout).to.contain('no instance selected')
62 it('Should add a user', async function () {
65 await cliCommand.execWithEnv(`${cmd} auth add -u ${server.url} -U user_1 -p super_password`)
68 it('Should not fail to add a user if there is a slash at the end of the instance URL', async function () {
71 let fullServerURL = server.url + '/'
73 await cliCommand.execWithEnv(`${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
75 fullServerURL = server.url + '/asdfasdf'
76 await cliCommand.execWithEnv(`${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
79 it('Should default to this user', async function () {
82 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
83 expect(stdout).to.contain(`instance ${server.url} selected`)
86 it('Should remember the user', async function () {
89 const stdout = await cliCommand.execWithEnv(`${cmd} auth list`)
90 expect(stdout).to.contain(server.url)
94 describe('Video upload/import', function () {
96 it('Should upload a video', async function () {
99 const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4')
100 const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'`
102 await cliCommand.execWithEnv(`${cmd} upload ${params}`)
105 it('Should have the video uploaded', async function () {
106 const { total, data } = await server.videos.list()
107 expect(total).to.equal(1)
109 const video = await server.videos.get({ id: data[0].uuid })
110 expect(video.name).to.equal('test upload')
111 expect(video.support).to.equal('support_text')
112 expect(video.channel.name).to.equal('user_channel')
115 it('Should import a video', async function () {
116 if (areHttpImportTestsDisabled()) return
120 const params = `--target-url ${FIXTURE_URLS.youtube} --channel-name user_channel`
121 await cliCommand.execWithEnv(`${cmd} import ${params}`)
124 it('Should have imported the video', async function () {
125 if (areHttpImportTestsDisabled()) return
129 await waitJobs([ server ])
131 const { total, data } = await server.videos.list()
132 expect(total).to.equal(2)
134 const video = data.find(v => v.name === 'small video - youtube')
135 expect(video).to.not.be.undefined
137 const videoDetails = await server.videos.get({ id: video.id })
138 expect(videoDetails.channel.name).to.equal('user_channel')
139 expect(videoDetails.support).to.equal('super support text')
140 expect(videoDetails.nsfw).to.be.false
142 // So we can reimport it
143 await server.videos.remove({ token: userAccessToken, id: video.id })
146 it('Should import and override some imported attributes', async function () {
147 if (areHttpImportTestsDisabled()) return
151 const params = `--target-url ${FIXTURE_URLS.youtube} ` +
152 `--channel-name user_channel --video-name toto --nsfw --support support`
153 await cliCommand.execWithEnv(`${cmd} import ${params}`)
155 await waitJobs([ server ])
158 const { total, data } = await server.videos.list()
159 expect(total).to.equal(2)
161 const video = data.find(v => v.name === 'toto')
162 expect(video).to.not.be.undefined
164 const videoDetails = await server.videos.get({ id: video.id })
165 expect(videoDetails.channel.name).to.equal('user_channel')
166 expect(videoDetails.support).to.equal('support')
167 expect(videoDetails.nsfw).to.be.true
168 expect(videoDetails.commentsEnabled).to.be.true
173 describe('Admin auth', function () {
175 it('Should remove the auth user', async function () {
176 await cliCommand.execWithEnv(`${cmd} auth del ${server.url}`)
178 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
179 expect(stdout).to.contain('no instance selected')
182 it('Should add the admin user', async function () {
183 await cliCommand.execWithEnv(`${cmd} auth add -u ${server.url} -U root -p test${server.internalServerNumber}`)
187 describe('Manage plugins', function () {
189 it('Should install a plugin', async function () {
192 await cliCommand.execWithEnv(`${cmd} plugins install --npm-name peertube-plugin-hello-world`)
195 it('Should have registered settings', async function () {
196 await testHelloWorldRegisteredSettings(server)
199 it('Should list installed plugins', async function () {
200 const res = await cliCommand.execWithEnv(`${cmd} plugins list`)
202 expect(res).to.contain('peertube-plugin-hello-world')
205 it('Should uninstall the plugin', async function () {
206 const res = await cliCommand.execWithEnv(`${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`)
208 expect(res).to.not.contain('peertube-plugin-hello-world')
212 describe('Manage video redundancies', function () {
213 let anotherServer: PeerTubeServer
214 let video1Server2: number
215 let servers: PeerTubeServer[]
217 before(async function () {
220 anotherServer = await createSingleServer(2)
221 await setAccessTokensToServers([ anotherServer ])
223 await doubleFollow(server, anotherServer)
225 servers = [ server, anotherServer ]
226 await waitJobs(servers)
228 const { uuid } = await anotherServer.videos.quickUpload({ name: 'super video' })
229 await waitJobs(servers)
231 video1Server2 = await server.videos.getId({ uuid })
234 it('Should add a redundancy', async function () {
237 const params = `add --video ${video1Server2}`
238 await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
240 await waitJobs(servers)
243 it('Should list redundancies', async function () {
247 const params = 'list-my-redundancies'
248 const stdout = await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
250 expect(stdout).to.contain('super video')
251 expect(stdout).to.contain(`localhost:${server.port}`)
255 it('Should remove a redundancy', async function () {
258 const params = `remove --video ${video1Server2}`
259 await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
261 await waitJobs(servers)
264 const params = 'list-my-redundancies'
265 const stdout = await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
267 expect(stdout).to.not.contain('super video')
271 after(async function () {
274 await cleanupTests([ anotherServer ])
278 after(async function () {
281 await cleanupTests([ server ])