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,
20 setAccessTokensToServers,
21 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 userLogin(server, { 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 display no selected instance', async function () {
58 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
59 expect(stdout).to.contain('no instance selected')
62 it('Should add a user', async function () {
65 await cliCommand.execWithEnv(`${cmd} auth add -u ${server.url} -U user_1 -p super_password`)
68 it('Should not fail to add a user if there is a slash at the end of the instance URL', async function () {
71 let fullServerURL = server.url + '/'
73 await cliCommand.execWithEnv(`${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
75 fullServerURL = server.url + '/asdfasdf'
76 await cliCommand.execWithEnv(`${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
79 it('Should default to this user', async function () {
82 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
83 expect(stdout).to.contain(`instance ${server.url} selected`)
86 it('Should remember the user', async function () {
89 const stdout = await cliCommand.execWithEnv(`${cmd} auth list`)
90 expect(stdout).to.contain(server.url)
94 describe('Video upload/import', function () {
96 it('Should upload a video', async function () {
99 const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4')
100 const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'`
102 await cliCommand.execWithEnv(`${cmd} upload ${params}`)
105 it('Should have the video uploaded', async function () {
106 const res = await getVideosList(server.url)
108 expect(res.body.total).to.equal(1)
110 const videos: Video[] = res.body.data
112 const video: VideoDetails = (await getVideo(server.url, videos[0].uuid)).body
114 expect(video.name).to.equal('test upload')
115 expect(video.support).to.equal('support_text')
116 expect(video.channel.name).to.equal('user_channel')
119 it('Should import a video', async function () {
120 if (areHttpImportTestsDisabled()) return
124 const params = `--target-url ${ImportsCommand.getYoutubeVideoUrl()} --channel-name user_channel`
125 await cliCommand.execWithEnv(`${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 params = `--target-url ${ImportsCommand.getYoutubeVideoUrl()} ` +
158 `--channel-name user_channel --video-name toto --nsfw --support support`
159 await cliCommand.execWithEnv(`${cmd} import ${params}`)
161 await waitJobs([ server ])
164 const res = await getVideosList(server.url)
165 expect(res.body.total).to.equal(2)
167 const videos: Video[] = res.body.data
168 const video = videos.find(v => v.name === 'toto')
169 expect(video).to.not.be.undefined
171 const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
172 expect(videoDetails.channel.name).to.equal('user_channel')
173 expect(videoDetails.support).to.equal('support')
174 expect(videoDetails.nsfw).to.be.true
175 expect(videoDetails.commentsEnabled).to.be.true
180 describe('Admin auth', function () {
182 it('Should remove the auth user', async function () {
183 await cliCommand.execWithEnv(`${cmd} auth del ${server.url}`)
185 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
186 expect(stdout).to.contain('no instance selected')
189 it('Should add the admin user', async function () {
190 await cliCommand.execWithEnv(`${cmd} auth add -u ${server.url} -U root -p test${server.internalServerNumber}`)
194 describe('Manage plugins', function () {
196 it('Should install a plugin', async function () {
199 await cliCommand.execWithEnv(`${cmd} plugins install --npm-name peertube-plugin-hello-world`)
202 it('Should have registered settings', async function () {
203 await testHelloWorldRegisteredSettings(server)
206 it('Should list installed plugins', async function () {
207 const res = await cliCommand.execWithEnv(`${cmd} plugins list`)
209 expect(res).to.contain('peertube-plugin-hello-world')
212 it('Should uninstall the plugin', async function () {
213 const res = await cliCommand.execWithEnv(`${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`)
215 expect(res).to.not.contain('peertube-plugin-hello-world')
219 describe('Manage video redundancies', function () {
220 let anotherServer: ServerInfo
221 let video1Server2: number
222 let servers: ServerInfo[]
224 before(async function () {
227 anotherServer = await flushAndRunServer(2)
228 await setAccessTokensToServers([ anotherServer ])
230 await doubleFollow(server, anotherServer)
232 servers = [ server, anotherServer ]
233 await waitJobs(servers)
235 const uuid = (await uploadVideoAndGetId({ server: anotherServer, videoName: 'super video' })).uuid
236 await waitJobs(servers)
238 video1Server2 = await getLocalIdByUUID(server.url, uuid)
241 it('Should add a redundancy', async function () {
244 const params = `add --video ${video1Server2}`
245 await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
247 await waitJobs(servers)
250 it('Should list redundancies', async function () {
254 const params = 'list-my-redundancies'
255 const stdout = await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
257 expect(stdout).to.contain('super video')
258 expect(stdout).to.contain(`localhost:${server.port}`)
262 it('Should remove a redundancy', async function () {
265 const params = `remove --video ${video1Server2}`
266 await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
268 await waitJobs(servers)
271 const params = 'list-my-redundancies'
272 const stdout = await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
274 expect(stdout).to.not.contain('super video')
278 after(async function () {
281 await cleanupTests([ anotherServer ])
285 after(async function () {
288 await cleanupTests([ server ])