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,
25 } from '../../../shared/extra-utils'
26 import { getYoutubeVideoUrl } from '../../../shared/extra-utils/videos/video-imports'
28 describe('Test CLI wrapper', function () {
29 let server: ServerInfo
30 let userAccessToken: string
32 const cmd = 'node ./dist/server/tools/peertube.js'
34 before(async function () {
37 server = await flushAndRunServer(1)
38 await setAccessTokensToServers([ server ])
40 await createUser({ url: server.url, accessToken: server.accessToken, username: 'user_1', password: 'super_password' })
42 userAccessToken = await userLogin(server, { username: 'user_1', password: 'super_password' })
45 const args = { name: 'user_channel', displayName: 'User channel', support: 'super support text' }
46 await addVideoChannel(server.url, userAccessToken, args)
50 describe('Authentication and instance selection', function () {
52 it('Should display no selected instance', async function () {
55 const env = getEnvCli(server)
56 const stdout = await execCLI(`${env} ${cmd} --help`)
58 expect(stdout).to.contain('no instance selected')
61 it('Should add a user', async function () {
64 const env = getEnvCli(server)
65 await execCLI(`${env} ${cmd} auth add -u ${server.url} -U user_1 -p super_password`)
68 it('Should default to this user', async function () {
71 const env = getEnvCli(server)
72 const stdout = await execCLI(`${env} ${cmd} --help`)
74 expect(stdout).to.contain(`instance ${server.url} selected`)
77 it('Should remember the user', async function () {
80 const env = getEnvCli(server)
81 const stdout = await execCLI(`${env} ${cmd} auth list`)
83 expect(stdout).to.contain(server.url)
87 describe('Video upload/import', function () {
89 it('Should upload a video', async function () {
92 const env = getEnvCli(server)
94 const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4')
96 const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'`
98 await execCLI(`${env} ${cmd} upload ${params}`)
101 it('Should have the video uploaded', async function () {
102 const res = await getVideosList(server.url)
104 expect(res.body.total).to.equal(1)
106 const videos: Video[] = res.body.data
108 const video: VideoDetails = (await getVideo(server.url, videos[0].uuid)).body
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 env = getEnvCli(server)
122 const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel`
124 await execCLI(`${env} ${cmd} import ${params}`)
127 it('Should have imported the video', async function () {
128 if (areHttpImportTestsDisabled()) return
132 await waitJobs([ server ])
134 const res = await getVideosList(server.url)
136 expect(res.body.total).to.equal(2)
138 const videos: Video[] = res.body.data
139 const video = videos.find(v => v.name === 'small video - youtube')
140 expect(video).to.not.be.undefined
142 const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
143 expect(videoDetails.channel.name).to.equal('user_channel')
144 expect(videoDetails.support).to.equal('super support text')
145 expect(videoDetails.nsfw).to.be.false
147 // So we can reimport it
148 await removeVideo(server.url, userAccessToken, video.id)
151 it('Should import and override some imported attributes', async function () {
152 if (areHttpImportTestsDisabled()) return
156 const env = getEnvCli(server)
158 const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel --video-name toto --nsfw --support support`
160 await execCLI(`${env} ${cmd} import ${params}`)
162 await waitJobs([ server ])
165 const res = await getVideosList(server.url)
166 expect(res.body.total).to.equal(2)
168 const videos: Video[] = res.body.data
169 const video = videos.find(v => v.name === 'toto')
170 expect(video).to.not.be.undefined
172 const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
173 expect(videoDetails.channel.name).to.equal('user_channel')
174 expect(videoDetails.support).to.equal('support')
175 expect(videoDetails.nsfw).to.be.true
176 expect(videoDetails.commentsEnabled).to.be.true
181 describe('Admin auth', function () {
183 it('Should remove the auth user', async function () {
184 const env = getEnvCli(server)
186 await execCLI(`${env} ${cmd} auth del ${server.url}`)
188 const stdout = await execCLI(`${env} ${cmd} --help`)
190 expect(stdout).to.contain('no instance selected')
193 it('Should add the admin user', async function () {
194 const env = getEnvCli(server)
195 await execCLI(`${env} ${cmd} auth add -u ${server.url} -U root -p test${server.internalServerNumber}`)
199 describe('Manage plugins', function () {
201 it('Should install a plugin', async function () {
204 const env = getEnvCli(server)
205 await execCLI(`${env} ${cmd} plugins install --npm-name peertube-plugin-hello-world`)
208 it('Should list installed plugins', async function () {
209 const env = getEnvCli(server)
210 const res = await execCLI(`${env} ${cmd} plugins list`)
212 expect(res).to.contain('peertube-plugin-hello-world')
215 it('Should uninstall the plugin', async function () {
216 const env = getEnvCli(server)
217 const res = await execCLI(`${env} ${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`)
219 expect(res).to.not.contain('peertube-plugin-hello-world')
223 describe('Manage video redundancies', function () {
224 let anotherServer: ServerInfo
225 let video1Server2: number
226 let servers: ServerInfo[]
228 before(async function () {
231 anotherServer = await flushAndRunServer(2)
232 await setAccessTokensToServers([ anotherServer ])
234 await doubleFollow(server, anotherServer)
236 servers = [ server, anotherServer ]
237 await waitJobs(servers)
239 const uuid = (await uploadVideoAndGetId({ server: anotherServer, videoName: 'super video' })).uuid
240 await waitJobs(servers)
242 video1Server2 = await getLocalIdByUUID(server.url, uuid)
245 it('Should add a redundancy', async function () {
248 const env = getEnvCli(server)
250 const params = `add --video ${video1Server2}`
252 await execCLI(`${env} ${cmd} redundancy ${params}`)
254 await waitJobs(servers)
257 it('Should list redundancies', async function () {
261 const env = getEnvCli(server)
263 const params = 'list-my-redundancies'
264 const stdout = await execCLI(`${env} ${cmd} redundancy ${params}`)
266 expect(stdout).to.contain('super video')
267 expect(stdout).to.contain(`localhost:${server.port}`)
271 it('Should remove a redundancy', async function () {
274 const env = getEnvCli(server)
276 const params = `remove --video ${video1Server2}`
278 await execCLI(`${env} ${cmd} redundancy ${params}`)
280 await waitJobs(servers)
283 const env = getEnvCli(server)
284 const params = 'list-my-redundancies'
285 const stdout = await execCLI(`${env} ${cmd} redundancy ${params}`)
287 expect(stdout).to.not.contain('super video')
291 after(async function () {
294 await cleanupTests([ anotherServer ])
298 after(async function () {
301 await cleanupTests([ server ])