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'
28 describe('Test CLI wrapper', function () {
29 let server: ServerInfo
30 let userAccessToken: string
32 let cliCommand: CLICommand
34 const cmd = 'node ./dist/server/tools/peertube.js'
36 before(async function () {
39 server = await flushAndRunServer(1)
40 await setAccessTokensToServers([ server ])
42 await createUser({ url: server.url, accessToken: server.accessToken, username: 'user_1', password: 'super_password' })
44 userAccessToken = await userLogin(server, { username: 'user_1', password: 'super_password' })
47 const args = { name: 'user_channel', displayName: 'User channel', support: 'super support text' }
48 await addVideoChannel(server.url, userAccessToken, args)
51 cliCommand = server.cliCommand
54 describe('Authentication and instance selection', function () {
56 it('Should display no selected instance', async function () {
59 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
60 expect(stdout).to.contain('no instance selected')
63 it('Should add a user', async function () {
66 await cliCommand.execWithEnv(`${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 let fullServerURL = server.url + '/'
74 await cliCommand.execWithEnv(`${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
76 fullServerURL = server.url + '/asdfasdf'
77 await cliCommand.execWithEnv(`${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
80 it('Should default to this user', async function () {
83 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
84 expect(stdout).to.contain(`instance ${server.url} selected`)
87 it('Should remember the user', async function () {
90 const stdout = await cliCommand.execWithEnv(`${cmd} auth list`)
91 expect(stdout).to.contain(server.url)
95 describe('Video upload/import', function () {
97 it('Should upload a video', async function () {
100 const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4')
101 const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'`
103 await cliCommand.execWithEnv(`${cmd} upload ${params}`)
106 it('Should have the video uploaded', async function () {
107 const res = await getVideosList(server.url)
109 expect(res.body.total).to.equal(1)
111 const videos: Video[] = res.body.data
113 const video: VideoDetails = (await getVideo(server.url, videos[0].uuid)).body
115 expect(video.name).to.equal('test upload')
116 expect(video.support).to.equal('support_text')
117 expect(video.channel.name).to.equal('user_channel')
120 it('Should import a video', async function () {
121 if (areHttpImportTestsDisabled()) return
125 const params = `--target-url ${ImportsCommand.getYoutubeVideoUrl()} --channel-name user_channel`
126 await cliCommand.execWithEnv(`${cmd} import ${params}`)
129 it('Should have imported the video', async function () {
130 if (areHttpImportTestsDisabled()) return
134 await waitJobs([ server ])
136 const res = await getVideosList(server.url)
138 expect(res.body.total).to.equal(2)
140 const videos: Video[] = res.body.data
141 const video = videos.find(v => v.name === 'small video - youtube')
142 expect(video).to.not.be.undefined
144 const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
145 expect(videoDetails.channel.name).to.equal('user_channel')
146 expect(videoDetails.support).to.equal('super support text')
147 expect(videoDetails.nsfw).to.be.false
149 // So we can reimport it
150 await removeVideo(server.url, userAccessToken, video.id)
153 it('Should import and override some imported attributes', async function () {
154 if (areHttpImportTestsDisabled()) return
158 const params = `--target-url ${ImportsCommand.getYoutubeVideoUrl()} ` +
159 `--channel-name user_channel --video-name toto --nsfw --support support`
160 await cliCommand.execWithEnv(`${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 await cliCommand.execWithEnv(`${cmd} auth del ${server.url}`)
186 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
187 expect(stdout).to.contain('no instance selected')
190 it('Should add the admin user', async function () {
191 await cliCommand.execWithEnv(`${cmd} auth add -u ${server.url} -U root -p test${server.internalServerNumber}`)
195 describe('Manage plugins', function () {
197 it('Should install a plugin', async function () {
200 await cliCommand.execWithEnv(`${cmd} plugins install --npm-name peertube-plugin-hello-world`)
203 it('Should have registered settings', async function () {
204 await testHelloWorldRegisteredSettings(server)
207 it('Should list installed plugins', async function () {
208 const res = await cliCommand.execWithEnv(`${cmd} plugins list`)
210 expect(res).to.contain('peertube-plugin-hello-world')
213 it('Should uninstall the plugin', async function () {
214 const res = await cliCommand.execWithEnv(`${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`)
216 expect(res).to.not.contain('peertube-plugin-hello-world')
220 describe('Manage video redundancies', function () {
221 let anotherServer: ServerInfo
222 let video1Server2: number
223 let servers: ServerInfo[]
225 before(async function () {
228 anotherServer = await flushAndRunServer(2)
229 await setAccessTokensToServers([ anotherServer ])
231 await doubleFollow(server, anotherServer)
233 servers = [ server, anotherServer ]
234 await waitJobs(servers)
236 const uuid = (await uploadVideoAndGetId({ server: anotherServer, videoName: 'super video' })).uuid
237 await waitJobs(servers)
239 video1Server2 = await getLocalIdByUUID(server.url, uuid)
242 it('Should add a redundancy', async function () {
245 const params = `add --video ${video1Server2}`
246 await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
248 await waitJobs(servers)
251 it('Should list redundancies', async function () {
255 const params = 'list-my-redundancies'
256 const stdout = await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
258 expect(stdout).to.contain('super video')
259 expect(stdout).to.contain(`localhost:${server.port}`)
263 it('Should remove a redundancy', async function () {
266 const params = `remove --video ${video1Server2}`
267 await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
269 await waitJobs(servers)
272 const params = 'list-my-redundancies'
273 const stdout = await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
275 expect(stdout).to.not.contain('super video')
279 after(async function () {
282 await cleanupTests([ anotherServer ])
286 after(async function () {
289 await cleanupTests([ server ])