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)
28 await setAccessTokensToServers([ server ])
30 await server.users.create({ username: 'user_1', password: 'super_password' })
32 userAccessToken = await server.login.getAccessToken({ username: 'user_1', password: 'super_password' })
35 const attributes = { name: 'user_channel', displayName: 'User channel', support: 'super support text' }
36 await server.channels.create({ token: userAccessToken, attributes })
39 cliCommand = server.cli
42 describe('Authentication and instance selection', function () {
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()
48 const body = await server.users.getMyInfo({ token })
49 expect(body.username).to.equal('user_1')
52 it('Should display no selected instance', async function () {
55 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
56 expect(stdout).to.contain('no instance selected')
59 it('Should add a user', async function () {
62 await cliCommand.execWithEnv(`${cmd} auth add -u ${server.url} -U user_1 -p super_password`)
65 it('Should not fail to add a user if there is a slash at the end of the instance URL', async function () {
68 let fullServerURL = server.url + '/'
70 await cliCommand.execWithEnv(`${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
72 fullServerURL = server.url + '/asdfasdf'
73 await cliCommand.execWithEnv(`${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
76 it('Should default to this user', async function () {
79 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
80 expect(stdout).to.contain(`instance ${server.url} selected`)
83 it('Should remember the user', async function () {
86 const stdout = await cliCommand.execWithEnv(`${cmd} auth list`)
87 expect(stdout).to.contain(server.url)
91 describe('Video upload/import', function () {
93 it('Should upload a video', async function () {
96 const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4')
97 const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'`
99 await cliCommand.execWithEnv(`${cmd} upload ${params}`)
102 it('Should have the video uploaded', async function () {
103 const { total, data } = await server.videos.list()
104 expect(total).to.equal(1)
106 const video = await server.videos.get({ id: data[0].uuid })
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')
112 it('Should import a video', async function () {
113 if (areHttpImportTestsDisabled()) return
117 const params = `--target-url ${FIXTURE_URLS.youtube} --channel-name user_channel`
118 await cliCommand.execWithEnv(`${cmd} import ${params}`)
121 it('Should have imported the video', async function () {
122 if (areHttpImportTestsDisabled()) return
126 await waitJobs([ server ])
128 const { total, data } = await server.videos.list()
129 expect(total).to.equal(2)
131 const video = data.find(v => v.name === 'small video - youtube')
132 expect(video).to.not.be.undefined
134 const videoDetails = await server.videos.get({ id: video.id })
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
140 it('Should not import again the same video', async function () {
141 if (areHttpImportTestsDisabled()) return
145 const params = `--target-url ${FIXTURE_URLS.youtube} --channel-name user_channel`
146 await cliCommand.execWithEnv(`${cmd} import ${params}`)
148 await waitJobs([ server ])
150 const { total, data } = await server.videos.list()
151 expect(total).to.equal(2)
153 const videos = data.filter(v => v.name === 'small video - youtube')
154 expect(videos).to.have.lengthOf(1)
156 // So we can reimport it
157 await server.videos.remove({ token: userAccessToken, id: videos[0].id })
160 it('Should import and override some imported attributes', async function () {
161 if (areHttpImportTestsDisabled()) return
165 const params = `--target-url ${FIXTURE_URLS.youtube} ` +
166 `--channel-name user_channel --video-name toto --nsfw --support support`
167 await cliCommand.execWithEnv(`${cmd} import ${params}`)
169 await waitJobs([ server ])
172 const { total, data } = await server.videos.list()
173 expect(total).to.equal(2)
175 const video = data.find(v => v.name === 'toto')
176 expect(video).to.not.be.undefined
178 const videoDetails = await server.videos.get({ id: video.id })
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
187 describe('Admin auth', function () {
189 it('Should remove the auth user', async function () {
190 await cliCommand.execWithEnv(`${cmd} auth del ${server.url}`)
192 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
193 expect(stdout).to.contain('no instance selected')
196 it('Should add the admin user', async function () {
197 await cliCommand.execWithEnv(`${cmd} auth add -u ${server.url} -U root -p test${server.internalServerNumber}`)
201 describe('Manage plugins', function () {
203 it('Should install a plugin', async function () {
206 await cliCommand.execWithEnv(`${cmd} plugins install --npm-name peertube-plugin-hello-world`)
209 it('Should have registered settings', async function () {
210 await testHelloWorldRegisteredSettings(server)
213 it('Should list installed plugins', async function () {
214 const res = await cliCommand.execWithEnv(`${cmd} plugins list`)
216 expect(res).to.contain('peertube-plugin-hello-world')
219 it('Should uninstall the plugin', async function () {
220 const res = await cliCommand.execWithEnv(`${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`)
222 expect(res).to.not.contain('peertube-plugin-hello-world')
225 it('Should install a plugin in requested version', async function () {
228 await cliCommand.execWithEnv(`${cmd} plugins install --npm-name peertube-plugin-hello-world --plugin-version 0.0.17`)
231 it('Should list installed plugins, in correct version', async function () {
232 const res = await cliCommand.execWithEnv(`${cmd} plugins list`)
234 expect(res).to.contain('peertube-plugin-hello-world')
235 expect(res).to.contain('0.0.17')
238 it('Should uninstall the plugin again', async function () {
239 const res = await cliCommand.execWithEnv(`${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`)
241 expect(res).to.not.contain('peertube-plugin-hello-world')
245 describe('Manage video redundancies', function () {
246 let anotherServer: PeerTubeServer
247 let video1Server2: number
248 let servers: PeerTubeServer[]
250 before(async function () {
253 anotherServer = await createSingleServer(2)
254 await setAccessTokensToServers([ anotherServer ])
256 await doubleFollow(server, anotherServer)
258 servers = [ server, anotherServer ]
259 await waitJobs(servers)
261 const { uuid } = await anotherServer.videos.quickUpload({ name: 'super video' })
262 await waitJobs(servers)
264 video1Server2 = await server.videos.getId({ uuid })
267 it('Should add a redundancy', async function () {
270 const params = `add --video ${video1Server2}`
271 await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
273 await waitJobs(servers)
276 it('Should list redundancies', async function () {
280 const params = 'list-my-redundancies'
281 const stdout = await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
283 expect(stdout).to.contain('super video')
284 expect(stdout).to.contain(`localhost:${server.port}`)
288 it('Should remove a redundancy', async function () {
291 const params = `remove --video ${video1Server2}`
292 await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
294 await waitJobs(servers)
297 const params = 'list-my-redundancies'
298 const stdout = await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
300 expect(stdout).to.not.contain('super video')
304 after(async function () {
307 await cleanupTests([ anotherServer ])
311 after(async function () {
314 await cleanupTests([ server ])