1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { expect } from 'chai'
5 import { Video, VideoDetails } from '../../../shared'
7 areHttpImportTestsDisabled,
8 buildAbsoluteFixturePath,
19 setAccessTokensToServers,
20 testHelloWorldRegisteredSettings,
23 } from '../../../shared/extra-utils'
25 describe('Test CLI wrapper', function () {
26 let server: ServerInfo
27 let userAccessToken: string
29 let cliCommand: CLICommand
31 const cmd = 'node ./dist/server/tools/peertube.js'
33 before(async function () {
36 server = await flushAndRunServer(1)
37 await setAccessTokensToServers([ server ])
39 await server.usersCommand.create({ username: 'user_1', password: 'super_password' })
41 userAccessToken = await server.loginCommand.getAccessToken({ username: 'user_1', password: 'super_password' })
44 const attributes = { name: 'user_channel', displayName: 'User channel', support: 'super support text' }
45 await server.channelsCommand.create({ token: userAccessToken, attributes })
48 cliCommand = server.cliCommand
51 describe('Authentication and instance selection', function () {
53 it('Should get an access token', async function () {
54 const stdout = await cliCommand.execWithEnv(`${cmd} token --url ${server.url} --username user_1 --password super_password`)
55 const token = stdout.trim()
57 const body = await server.usersCommand.getMyInfo({ token })
58 expect(body.username).to.equal('user_1')
61 it('Should display no selected instance', async function () {
64 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
65 expect(stdout).to.contain('no instance selected')
68 it('Should add a user', async function () {
71 await cliCommand.execWithEnv(`${cmd} auth add -u ${server.url} -U user_1 -p super_password`)
74 it('Should not fail to add a user if there is a slash at the end of the instance URL', async function () {
77 let fullServerURL = server.url + '/'
79 await cliCommand.execWithEnv(`${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
81 fullServerURL = server.url + '/asdfasdf'
82 await cliCommand.execWithEnv(`${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
85 it('Should default to this user', async function () {
88 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
89 expect(stdout).to.contain(`instance ${server.url} selected`)
92 it('Should remember the user', async function () {
95 const stdout = await cliCommand.execWithEnv(`${cmd} auth list`)
96 expect(stdout).to.contain(server.url)
100 describe('Video upload/import', function () {
102 it('Should upload a video', async function () {
105 const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4')
106 const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'`
108 await cliCommand.execWithEnv(`${cmd} upload ${params}`)
111 it('Should have the video uploaded', async function () {
112 const res = await getVideosList(server.url)
114 expect(res.body.total).to.equal(1)
116 const videos: Video[] = res.body.data
118 const video: VideoDetails = (await getVideo(server.url, videos[0].uuid)).body
120 expect(video.name).to.equal('test upload')
121 expect(video.support).to.equal('support_text')
122 expect(video.channel.name).to.equal('user_channel')
125 it('Should import a video', async function () {
126 if (areHttpImportTestsDisabled()) return
130 const params = `--target-url ${ImportsCommand.getYoutubeVideoUrl()} --channel-name user_channel`
131 await cliCommand.execWithEnv(`${cmd} import ${params}`)
134 it('Should have imported the video', async function () {
135 if (areHttpImportTestsDisabled()) return
139 await waitJobs([ server ])
141 const res = await getVideosList(server.url)
143 expect(res.body.total).to.equal(2)
145 const videos: Video[] = res.body.data
146 const video = videos.find(v => v.name === 'small video - youtube')
147 expect(video).to.not.be.undefined
149 const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
150 expect(videoDetails.channel.name).to.equal('user_channel')
151 expect(videoDetails.support).to.equal('super support text')
152 expect(videoDetails.nsfw).to.be.false
154 // So we can reimport it
155 await removeVideo(server.url, userAccessToken, video.id)
158 it('Should import and override some imported attributes', async function () {
159 if (areHttpImportTestsDisabled()) return
163 const params = `--target-url ${ImportsCommand.getYoutubeVideoUrl()} ` +
164 `--channel-name user_channel --video-name toto --nsfw --support support`
165 await cliCommand.execWithEnv(`${cmd} import ${params}`)
167 await waitJobs([ server ])
170 const res = await getVideosList(server.url)
171 expect(res.body.total).to.equal(2)
173 const videos: Video[] = res.body.data
174 const video = videos.find(v => v.name === 'toto')
175 expect(video).to.not.be.undefined
177 const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
178 expect(videoDetails.channel.name).to.equal('user_channel')
179 expect(videoDetails.support).to.equal('support')
180 expect(videoDetails.nsfw).to.be.true
181 expect(videoDetails.commentsEnabled).to.be.true
186 describe('Admin auth', function () {
188 it('Should remove the auth user', async function () {
189 await cliCommand.execWithEnv(`${cmd} auth del ${server.url}`)
191 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
192 expect(stdout).to.contain('no instance selected')
195 it('Should add the admin user', async function () {
196 await cliCommand.execWithEnv(`${cmd} auth add -u ${server.url} -U root -p test${server.internalServerNumber}`)
200 describe('Manage plugins', function () {
202 it('Should install a plugin', async function () {
205 await cliCommand.execWithEnv(`${cmd} plugins install --npm-name peertube-plugin-hello-world`)
208 it('Should have registered settings', async function () {
209 await testHelloWorldRegisteredSettings(server)
212 it('Should list installed plugins', async function () {
213 const res = await cliCommand.execWithEnv(`${cmd} plugins list`)
215 expect(res).to.contain('peertube-plugin-hello-world')
218 it('Should uninstall the plugin', async function () {
219 const res = await cliCommand.execWithEnv(`${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`)
221 expect(res).to.not.contain('peertube-plugin-hello-world')
225 describe('Manage video redundancies', function () {
226 let anotherServer: ServerInfo
227 let video1Server2: number
228 let servers: ServerInfo[]
230 before(async function () {
233 anotherServer = await flushAndRunServer(2)
234 await setAccessTokensToServers([ anotherServer ])
236 await doubleFollow(server, anotherServer)
238 servers = [ server, anotherServer ]
239 await waitJobs(servers)
241 const uuid = (await uploadVideoAndGetId({ server: anotherServer, videoName: 'super video' })).uuid
242 await waitJobs(servers)
244 video1Server2 = await getLocalIdByUUID(server.url, uuid)
247 it('Should add a redundancy', async function () {
250 const params = `add --video ${video1Server2}`
251 await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
253 await waitJobs(servers)
256 it('Should list redundancies', async function () {
260 const params = 'list-my-redundancies'
261 const stdout = await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
263 expect(stdout).to.contain('super video')
264 expect(stdout).to.contain(`localhost:${server.port}`)
268 it('Should remove a redundancy', async function () {
271 const params = `remove --video ${video1Server2}`
272 await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
274 await waitJobs(servers)
277 const params = 'list-my-redundancies'
278 const stdout = await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
280 expect(stdout).to.not.contain('super video')
284 after(async function () {
287 await cleanupTests([ anotherServer ])
291 after(async function () {
294 await cleanupTests([ server ])