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 default to this user', async function () {
72 const env = getEnvCli(server)
73 const stdout = await execCLI(`${env} ${cmd} --help`)
75 expect(stdout).to.contain(`instance ${server.url} selected`)
78 it('Should remember the user', async function () {
81 const env = getEnvCli(server)
82 const stdout = await execCLI(`${env} ${cmd} auth list`)
84 expect(stdout).to.contain(server.url)
88 describe('Video upload/import', function () {
90 it('Should upload a video', async function () {
93 const env = getEnvCli(server)
95 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 execCLI(`${env} ${cmd} upload ${params}`)
102 it('Should have the video uploaded', async function () {
103 const res = await getVideosList(server.url)
105 expect(res.body.total).to.equal(1)
107 const videos: Video[] = res.body.data
109 const video: VideoDetails = (await getVideo(server.url, videos[0].uuid)).body
111 expect(video.name).to.equal('test upload')
112 expect(video.support).to.equal('support_text')
113 expect(video.channel.name).to.equal('user_channel')
116 it('Should import a video', async function () {
117 if (areHttpImportTestsDisabled()) return
121 const env = getEnvCli(server)
123 const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel`
125 await execCLI(`${env} ${cmd} import ${params}`)
128 it('Should have imported the video', async function () {
129 if (areHttpImportTestsDisabled()) return
133 await waitJobs([ server ])
135 const res = await getVideosList(server.url)
137 expect(res.body.total).to.equal(2)
139 const videos: Video[] = res.body.data
140 const video = videos.find(v => v.name === 'small video - youtube')
141 expect(video).to.not.be.undefined
143 const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
144 expect(videoDetails.channel.name).to.equal('user_channel')
145 expect(videoDetails.support).to.equal('super support text')
146 expect(videoDetails.nsfw).to.be.false
148 // So we can reimport it
149 await removeVideo(server.url, userAccessToken, video.id)
152 it('Should import and override some imported attributes', async function () {
153 if (areHttpImportTestsDisabled()) return
157 const env = getEnvCli(server)
159 const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel --video-name toto --nsfw --support support`
161 await execCLI(`${env} ${cmd} import ${params}`)
163 await waitJobs([ server ])
166 const res = await getVideosList(server.url)
167 expect(res.body.total).to.equal(2)
169 const videos: Video[] = res.body.data
170 const video = videos.find(v => v.name === 'toto')
171 expect(video).to.not.be.undefined
173 const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
174 expect(videoDetails.channel.name).to.equal('user_channel')
175 expect(videoDetails.support).to.equal('support')
176 expect(videoDetails.nsfw).to.be.true
177 expect(videoDetails.commentsEnabled).to.be.true
182 describe('Admin auth', function () {
184 it('Should remove the auth user', async function () {
185 const env = getEnvCli(server)
187 await execCLI(`${env} ${cmd} auth del ${server.url}`)
189 const stdout = await execCLI(`${env} ${cmd} --help`)
191 expect(stdout).to.contain('no instance selected')
194 it('Should add the admin user', async function () {
195 const env = getEnvCli(server)
196 await execCLI(`${env} ${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 const env = getEnvCli(server)
206 await execCLI(`${env} ${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 env = getEnvCli(server)
215 const res = await execCLI(`${env} ${cmd} plugins list`)
217 expect(res).to.contain('peertube-plugin-hello-world')
220 it('Should uninstall the plugin', async function () {
221 const env = getEnvCli(server)
222 const res = await execCLI(`${env} ${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`)
224 expect(res).to.not.contain('peertube-plugin-hello-world')
228 describe('Manage video redundancies', function () {
229 let anotherServer: ServerInfo
230 let video1Server2: number
231 let servers: ServerInfo[]
233 before(async function () {
236 anotherServer = await flushAndRunServer(2)
237 await setAccessTokensToServers([ anotherServer ])
239 await doubleFollow(server, anotherServer)
241 servers = [ server, anotherServer ]
242 await waitJobs(servers)
244 const uuid = (await uploadVideoAndGetId({ server: anotherServer, videoName: 'super video' })).uuid
245 await waitJobs(servers)
247 video1Server2 = await getLocalIdByUUID(server.url, uuid)
250 it('Should add a redundancy', async function () {
253 const env = getEnvCli(server)
255 const params = `add --video ${video1Server2}`
257 await execCLI(`${env} ${cmd} redundancy ${params}`)
259 await waitJobs(servers)
262 it('Should list redundancies', async function () {
266 const env = getEnvCli(server)
268 const params = 'list-my-redundancies'
269 const stdout = await execCLI(`${env} ${cmd} redundancy ${params}`)
271 expect(stdout).to.contain('super video')
272 expect(stdout).to.contain(`localhost:${server.port}`)
276 it('Should remove a redundancy', async function () {
279 const env = getEnvCli(server)
281 const params = `remove --video ${video1Server2}`
283 await execCLI(`${env} ${cmd} redundancy ${params}`)
285 await waitJobs(servers)
288 const env = getEnvCli(server)
289 const params = 'list-my-redundancies'
290 const stdout = await execCLI(`${env} ${cmd} redundancy ${params}`)
292 expect(stdout).to.not.contain('super video')
296 after(async function () {
299 await cleanupTests([ anotherServer ])
303 after(async function () {
306 await cleanupTests([ server ])