1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { expect } from 'chai'
5 import { Video, VideoDetails } from '../../../shared'
7 areHttpImportTestsDisabled,
8 buildAbsoluteFixturePath,
21 setAccessTokensToServers,
22 testHelloWorldRegisteredSettings,
25 } from '../../../shared/extra-utils'
27 describe('Test CLI wrapper', function () {
28 let server: ServerInfo
29 let userAccessToken: string
31 let cliCommand: CLICommand
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 server.loginCommand.getAccessToken({ username: 'user_1', password: 'super_password' })
46 const attributes = { name: 'user_channel', displayName: 'User channel', support: 'super support text' }
47 await server.channelsCommand.create({ token: userAccessToken, attributes })
50 cliCommand = server.cliCommand
53 describe('Authentication and instance selection', function () {
55 it('Should get an access token', async function () {
56 const stdout = await cliCommand.execWithEnv(`${cmd} token --url ${server.url} --username user_1 --password super_password`)
57 const token = stdout.trim()
59 const res = await getMyUserInformation(server.url, token)
60 expect(res.body.username).to.equal('user_1')
63 it('Should display no selected instance', async function () {
66 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
67 expect(stdout).to.contain('no instance selected')
70 it('Should add a user', async function () {
73 await cliCommand.execWithEnv(`${cmd} auth add -u ${server.url} -U user_1 -p super_password`)
76 it('Should not fail to add a user if there is a slash at the end of the instance URL', async function () {
79 let fullServerURL = server.url + '/'
81 await cliCommand.execWithEnv(`${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
83 fullServerURL = server.url + '/asdfasdf'
84 await cliCommand.execWithEnv(`${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
87 it('Should default to this user', async function () {
90 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
91 expect(stdout).to.contain(`instance ${server.url} selected`)
94 it('Should remember the user', async function () {
97 const stdout = await cliCommand.execWithEnv(`${cmd} auth list`)
98 expect(stdout).to.contain(server.url)
102 describe('Video upload/import', function () {
104 it('Should upload a video', async function () {
107 const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4')
108 const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'`
110 await cliCommand.execWithEnv(`${cmd} upload ${params}`)
113 it('Should have the video uploaded', async function () {
114 const res = await getVideosList(server.url)
116 expect(res.body.total).to.equal(1)
118 const videos: Video[] = res.body.data
120 const video: VideoDetails = (await getVideo(server.url, videos[0].uuid)).body
122 expect(video.name).to.equal('test upload')
123 expect(video.support).to.equal('support_text')
124 expect(video.channel.name).to.equal('user_channel')
127 it('Should import a video', async function () {
128 if (areHttpImportTestsDisabled()) return
132 const params = `--target-url ${ImportsCommand.getYoutubeVideoUrl()} --channel-name user_channel`
133 await cliCommand.execWithEnv(`${cmd} import ${params}`)
136 it('Should have imported the video', async function () {
137 if (areHttpImportTestsDisabled()) return
141 await waitJobs([ server ])
143 const res = await getVideosList(server.url)
145 expect(res.body.total).to.equal(2)
147 const videos: Video[] = res.body.data
148 const video = videos.find(v => v.name === 'small video - youtube')
149 expect(video).to.not.be.undefined
151 const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
152 expect(videoDetails.channel.name).to.equal('user_channel')
153 expect(videoDetails.support).to.equal('super support text')
154 expect(videoDetails.nsfw).to.be.false
156 // So we can reimport it
157 await removeVideo(server.url, userAccessToken, video.id)
160 it('Should import and override some imported attributes', async function () {
161 if (areHttpImportTestsDisabled()) return
165 const params = `--target-url ${ImportsCommand.getYoutubeVideoUrl()} ` +
166 `--channel-name user_channel --video-name toto --nsfw --support support`
167 await cliCommand.execWithEnv(`${cmd} import ${params}`)
169 await waitJobs([ server ])
172 const res = await getVideosList(server.url)
173 expect(res.body.total).to.equal(2)
175 const videos: Video[] = res.body.data
176 const video = videos.find(v => v.name === 'toto')
177 expect(video).to.not.be.undefined
179 const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
180 expect(videoDetails.channel.name).to.equal('user_channel')
181 expect(videoDetails.support).to.equal('support')
182 expect(videoDetails.nsfw).to.be.true
183 expect(videoDetails.commentsEnabled).to.be.true
188 describe('Admin auth', function () {
190 it('Should remove the auth user', async function () {
191 await cliCommand.execWithEnv(`${cmd} auth del ${server.url}`)
193 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
194 expect(stdout).to.contain('no instance selected')
197 it('Should add the admin user', async function () {
198 await cliCommand.execWithEnv(`${cmd} auth add -u ${server.url} -U root -p test${server.internalServerNumber}`)
202 describe('Manage plugins', function () {
204 it('Should install a plugin', async function () {
207 await cliCommand.execWithEnv(`${cmd} plugins install --npm-name peertube-plugin-hello-world`)
210 it('Should have registered settings', async function () {
211 await testHelloWorldRegisteredSettings(server)
214 it('Should list installed plugins', async function () {
215 const res = await cliCommand.execWithEnv(`${cmd} plugins list`)
217 expect(res).to.contain('peertube-plugin-hello-world')
220 it('Should uninstall the plugin', async function () {
221 const res = await cliCommand.execWithEnv(`${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`)
223 expect(res).to.not.contain('peertube-plugin-hello-world')
227 describe('Manage video redundancies', function () {
228 let anotherServer: ServerInfo
229 let video1Server2: number
230 let servers: ServerInfo[]
232 before(async function () {
235 anotherServer = await flushAndRunServer(2)
236 await setAccessTokensToServers([ anotherServer ])
238 await doubleFollow(server, anotherServer)
240 servers = [ server, anotherServer ]
241 await waitJobs(servers)
243 const uuid = (await uploadVideoAndGetId({ server: anotherServer, videoName: 'super video' })).uuid
244 await waitJobs(servers)
246 video1Server2 = await getLocalIdByUUID(server.url, uuid)
249 it('Should add a redundancy', async function () {
252 const params = `add --video ${video1Server2}`
253 await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
255 await waitJobs(servers)
258 it('Should list redundancies', async function () {
262 const params = 'list-my-redundancies'
263 const stdout = await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
265 expect(stdout).to.contain('super video')
266 expect(stdout).to.contain(`localhost:${server.port}`)
270 it('Should remove a redundancy', async function () {
273 const params = `remove --video ${video1Server2}`
274 await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
276 await waitJobs(servers)
279 const params = 'list-my-redundancies'
280 const stdout = await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
282 expect(stdout).to.not.contain('super video')
286 after(async function () {
289 await cleanupTests([ anotherServer ])
293 after(async function () {
296 await cleanupTests([ server ])