1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { expect } from 'chai'
7 buildAbsoluteFixturePath,
19 setAccessTokensToServers,
23 } from '../../../shared/extra-utils'
24 import { Video, VideoDetails } from '../../../shared'
25 import { getYoutubeVideoUrl } from '../../../shared/extra-utils/videos/video-imports'
27 describe('Test CLI wrapper', function () {
28 let server: ServerInfo
29 let userAccessToken: string
31 const cmd = 'node ./dist/server/tools/peertube.js'
33 before(async function () {
36 server = await flushAndRunServer(1)
37 await setAccessTokensToServers([ server ])
39 await createUser({ url: server.url, accessToken: server.accessToken, username: 'user_1', password: 'super_password' })
41 userAccessToken = await userLogin(server, { username: 'user_1', password: 'super_password' })
44 const args = { name: 'user_channel', displayName: 'User channel', support: 'super support text' }
45 await addVideoChannel(server.url, userAccessToken, args)
49 describe('Authentication and instance selection', function () {
51 it('Should display no selected instance', async function () {
54 const env = getEnvCli(server)
55 const stdout = await execCLI(`${env} ${cmd} --help`)
57 expect(stdout).to.contain('no instance selected')
60 it('Should add a user', async function () {
63 const env = getEnvCli(server)
64 await execCLI(`${env} ${cmd} auth add -u ${server.url} -U user_1 -p super_password`)
67 it('Should default to this user', async function () {
70 const env = getEnvCli(server)
71 const stdout = await execCLI(`${env} ${cmd} --help`)
73 expect(stdout).to.contain(`instance ${server.url} selected`)
76 it('Should remember the user', async function () {
79 const env = getEnvCli(server)
80 const stdout = await execCLI(`${env} ${cmd} auth list`)
82 expect(stdout).to.contain(server.url)
86 describe('Video upload/import', function () {
88 it('Should upload a video', async function () {
91 const env = getEnvCli(server)
93 const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4')
95 const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'`
97 await execCLI(`${env} ${cmd} upload ${params}`)
100 it('Should have the video uploaded', async function () {
101 const res = await getVideosList(server.url)
103 expect(res.body.total).to.equal(1)
105 const videos: Video[] = res.body.data
107 const video: VideoDetails = (await getVideo(server.url, videos[0].uuid)).body
109 expect(video.name).to.equal('test upload')
110 expect(video.support).to.equal('support_text')
111 expect(video.channel.name).to.equal('user_channel')
114 it('Should import a video', async function () {
117 const env = getEnvCli(server)
119 const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel`
121 await execCLI(`${env} ${cmd} import ${params}`)
124 it('Should have imported the video', async function () {
127 await waitJobs([ server ])
129 const res = await getVideosList(server.url)
131 expect(res.body.total).to.equal(2)
133 const videos: Video[] = res.body.data
134 const video = videos.find(v => v.name === 'small video - youtube')
135 expect(video).to.not.be.undefined
137 const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
138 expect(videoDetails.channel.name).to.equal('user_channel')
139 expect(videoDetails.support).to.equal('super support text')
140 expect(videoDetails.nsfw).to.be.false
142 // So we can reimport it
143 await removeVideo(server.url, userAccessToken, video.id)
146 it('Should import and override some imported attributes', async function () {
149 const env = getEnvCli(server)
151 const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel --video-name toto --nsfw --support support`
153 await execCLI(`${env} ${cmd} import ${params}`)
155 await waitJobs([ server ])
158 const res = await getVideosList(server.url)
159 expect(res.body.total).to.equal(2)
161 const videos: Video[] = res.body.data
162 const video = videos.find(v => v.name === 'toto')
163 expect(video).to.not.be.undefined
165 const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
166 expect(videoDetails.channel.name).to.equal('user_channel')
167 expect(videoDetails.support).to.equal('support')
168 expect(videoDetails.nsfw).to.be.true
169 expect(videoDetails.commentsEnabled).to.be.true
174 describe('Admin auth', function () {
176 it('Should remove the auth user', async function () {
177 const env = getEnvCli(server)
179 await execCLI(`${env} ${cmd} auth del ${server.url}`)
181 const stdout = await execCLI(`${env} ${cmd} --help`)
183 expect(stdout).to.contain('no instance selected')
186 it('Should add the admin user', async function () {
187 const env = getEnvCli(server)
188 await execCLI(`${env} ${cmd} auth add -u ${server.url} -U root -p test${server.internalServerNumber}`)
192 describe('Manage plugins', function () {
194 it('Should install a plugin', async function () {
197 const env = getEnvCli(server)
198 await execCLI(`${env} ${cmd} plugins install --npm-name peertube-plugin-hello-world`)
201 it('Should list installed plugins', async function () {
202 const env = getEnvCli(server)
203 const res = await execCLI(`${env} ${cmd} plugins list`)
205 expect(res).to.contain('peertube-plugin-hello-world')
208 it('Should uninstall the plugin', async function () {
209 const env = getEnvCli(server)
210 const res = await execCLI(`${env} ${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`)
212 expect(res).to.not.contain('peertube-plugin-hello-world')
216 describe('Manage video redundancies', function () {
217 let anotherServer: ServerInfo
218 let video1Server2: number
219 let servers: ServerInfo[]
221 before(async function () {
224 anotherServer = await flushAndRunServer(2)
225 await setAccessTokensToServers([ anotherServer ])
227 await doubleFollow(server, anotherServer)
229 servers = [ server, anotherServer ]
230 await waitJobs(servers)
232 const uuid = (await uploadVideoAndGetId({ server: anotherServer, videoName: 'super video' })).uuid
233 await waitJobs(servers)
235 video1Server2 = await getLocalIdByUUID(server.url, uuid)
238 it('Should add a redundancy', async function () {
241 const env = getEnvCli(server)
243 const params = `add --video ${video1Server2}`
245 await execCLI(`${env} ${cmd} redundancy ${params}`)
247 await waitJobs(servers)
250 it('Should list redundancies', async function () {
254 const env = getEnvCli(server)
256 const params = 'list-my-redundancies'
257 const stdout = await execCLI(`${env} ${cmd} redundancy ${params}`)
259 expect(stdout).to.contain('super video')
260 expect(stdout).to.contain(`localhost:${server.port}`)
264 it('Should remove a redundancy', async function () {
267 const env = getEnvCli(server)
269 const params = `remove --video ${video1Server2}`
271 await execCLI(`${env} ${cmd} redundancy ${params}`)
273 await waitJobs(servers)
276 const env = getEnvCli(server)
277 const params = 'list-my-redundancies'
278 const stdout = await execCLI(`${env} ${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 ])