1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { expect } from 'chai'
5 import { Video, VideoDetails } from '../../../shared'
8 areHttpImportTestsDisabled,
9 buildAbsoluteFixturePath,
21 setAccessTokensToServers,
22 testHelloWorldRegisteredSettings,
26 } from '../../../shared/extra-utils'
27 import { getYoutubeVideoUrl } from '../../../shared/extra-utils/videos/video-imports'
29 describe('Test CLI wrapper', function () {
30 let server: ServerInfo
31 let userAccessToken: string
33 const cmd = 'node ./dist/server/tools/peertube.js'
35 before(async function () {
38 server = await flushAndRunServer(1)
39 await setAccessTokensToServers([ server ])
41 await createUser({ url: server.url, accessToken: server.accessToken, username: 'user_1', password: 'super_password' })
43 userAccessToken = await userLogin(server, { username: 'user_1', password: 'super_password' })
46 const args = { name: 'user_channel', displayName: 'User channel', support: 'super support text' }
47 await addVideoChannel(server.url, userAccessToken, args)
51 describe('Authentication and instance selection', function () {
53 it('Should display no selected instance', async function () {
56 const env = getEnvCli(server)
57 const stdout = await execCLI(`${env} ${cmd} --help`)
59 expect(stdout).to.contain('no instance selected')
62 it('Should add a user', async function () {
65 const env = getEnvCli(server)
66 await execCLI(`${env} ${cmd} auth add -u ${server.url} -U user_1 -p super_password`)
69 it('Should not fail to add a user if there is a slash at the end of the instance URL', async function () {
72 const env = getEnvCli(server)
74 fullServerURL = server.url + '/'
75 await execCLI(`${env} ${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
77 fullServerURL = server.url + '/asdfasdf'
78 await execCLI(`${env} ${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
81 it('Should default to this user', async function () {
84 const env = getEnvCli(server)
85 const stdout = await execCLI(`${env} ${cmd} --help`)
87 expect(stdout).to.contain(`instance ${server.url} selected`)
90 it('Should remember the user', async function () {
93 const env = getEnvCli(server)
94 const stdout = await execCLI(`${env} ${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 env = getEnvCli(server)
107 const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4')
109 const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'`
111 await execCLI(`${env} ${cmd} upload ${params}`)
114 it('Should have the video uploaded', async function () {
115 const res = await getVideosList(server.url)
117 expect(res.body.total).to.equal(1)
119 const videos: Video[] = res.body.data
121 const video: VideoDetails = (await getVideo(server.url, videos[0].uuid)).body
123 expect(video.name).to.equal('test upload')
124 expect(video.support).to.equal('support_text')
125 expect(video.channel.name).to.equal('user_channel')
128 it('Should import a video', async function () {
129 if (areHttpImportTestsDisabled()) return
133 const env = getEnvCli(server)
135 const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel`
137 await execCLI(`${env} ${cmd} import ${params}`)
140 it('Should have imported the video', async function () {
141 if (areHttpImportTestsDisabled()) return
145 await waitJobs([ server ])
147 const res = await getVideosList(server.url)
149 expect(res.body.total).to.equal(2)
151 const videos: Video[] = res.body.data
152 const video = videos.find(v => v.name === 'small video - youtube')
153 expect(video).to.not.be.undefined
155 const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
156 expect(videoDetails.channel.name).to.equal('user_channel')
157 expect(videoDetails.support).to.equal('super support text')
158 expect(videoDetails.nsfw).to.be.false
160 // So we can reimport it
161 await removeVideo(server.url, userAccessToken, video.id)
164 it('Should import and override some imported attributes', async function () {
165 if (areHttpImportTestsDisabled()) return
169 const env = getEnvCli(server)
171 const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel --video-name toto --nsfw --support support`
173 await execCLI(`${env} ${cmd} import ${params}`)
175 await waitJobs([ server ])
178 const res = await getVideosList(server.url)
179 expect(res.body.total).to.equal(2)
181 const videos: Video[] = res.body.data
182 const video = videos.find(v => v.name === 'toto')
183 expect(video).to.not.be.undefined
185 const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
186 expect(videoDetails.channel.name).to.equal('user_channel')
187 expect(videoDetails.support).to.equal('support')
188 expect(videoDetails.nsfw).to.be.true
189 expect(videoDetails.commentsEnabled).to.be.true
194 describe('Admin auth', function () {
196 it('Should remove the auth user', async function () {
197 const env = getEnvCli(server)
199 await execCLI(`${env} ${cmd} auth del ${server.url}`)
201 const stdout = await execCLI(`${env} ${cmd} --help`)
203 expect(stdout).to.contain('no instance selected')
206 it('Should add the admin user', async function () {
207 const env = getEnvCli(server)
208 await execCLI(`${env} ${cmd} auth add -u ${server.url} -U root -p test${server.internalServerNumber}`)
212 describe('Manage plugins', function () {
214 it('Should install a plugin', async function () {
217 const env = getEnvCli(server)
218 await execCLI(`${env} ${cmd} plugins install --npm-name peertube-plugin-hello-world`)
221 it('Should have registered settings', async function () {
222 await testHelloWorldRegisteredSettings(server)
225 it('Should list installed plugins', async function () {
226 const env = getEnvCli(server)
227 const res = await execCLI(`${env} ${cmd} plugins list`)
229 expect(res).to.contain('peertube-plugin-hello-world')
232 it('Should uninstall the plugin', async function () {
233 const env = getEnvCli(server)
234 const res = await execCLI(`${env} ${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`)
236 expect(res).to.not.contain('peertube-plugin-hello-world')
240 describe('Manage video redundancies', function () {
241 let anotherServer: ServerInfo
242 let video1Server2: number
243 let servers: ServerInfo[]
245 before(async function () {
248 anotherServer = await flushAndRunServer(2)
249 await setAccessTokensToServers([ anotherServer ])
251 await doubleFollow(server, anotherServer)
253 servers = [ server, anotherServer ]
254 await waitJobs(servers)
256 const uuid = (await uploadVideoAndGetId({ server: anotherServer, videoName: 'super video' })).uuid
257 await waitJobs(servers)
259 video1Server2 = await getLocalIdByUUID(server.url, uuid)
262 it('Should add a redundancy', async function () {
265 const env = getEnvCli(server)
267 const params = `add --video ${video1Server2}`
269 await execCLI(`${env} ${cmd} redundancy ${params}`)
271 await waitJobs(servers)
274 it('Should list redundancies', async function () {
278 const env = getEnvCli(server)
280 const params = 'list-my-redundancies'
281 const stdout = await execCLI(`${env} ${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 env = getEnvCli(server)
293 const params = `remove --video ${video1Server2}`
295 await execCLI(`${env} ${cmd} redundancy ${params}`)
297 await waitJobs(servers)
300 const env = getEnvCli(server)
301 const params = 'list-my-redundancies'
302 const stdout = await execCLI(`${env} ${cmd} redundancy ${params}`)
304 expect(stdout).to.not.contain('super video')
308 after(async function () {
311 await cleanupTests([ anotherServer ])
315 after(async function () {
318 await cleanupTests([ server ])