1 /* tslint:disable:no-unused-expression */
4 import { expect } from 'chai'
7 buildAbsoluteFixturePath,
15 getVideosListWithToken, removeVideo,
17 setAccessTokensToServers,
20 } from '../../../shared/extra-utils'
21 import { Video, VideoDetails } from '../../../shared'
22 import { getYoutubeVideoUrl } from '../../../shared/extra-utils/videos/video-imports'
24 describe('Test CLI wrapper', function () {
25 let server: ServerInfo
26 let userAccessToken: string
28 const cmd = 'node ./dist/server/tools/peertube.js'
30 before(async function () {
33 server = await flushAndRunServer(1)
34 await setAccessTokensToServers([ server ])
36 await createUser({ url: server.url, accessToken: server.accessToken, username: 'user_1', password: 'super_password' })
38 userAccessToken = await userLogin(server, { username: 'user_1', password: 'super_password' })
41 const args = { name: 'user_channel', displayName: 'User channel', support: 'super support text' }
42 await addVideoChannel(server.url, userAccessToken, args)
46 describe('Authentication and instance selection', function () {
48 it('Should display no selected instance', async function () {
51 const env = getEnvCli(server)
52 const stdout = await execCLI(`${env} ${cmd} --help`)
54 expect(stdout).to.contain('no instance selected')
57 it('Should add a user', async function () {
60 const env = getEnvCli(server)
61 await execCLI(`${env} ${cmd} auth add -u ${server.url} -U user_1 -p super_password`)
64 it('Should default to this user', async function () {
67 const env = getEnvCli(server)
68 const stdout = await execCLI(`${env} ${cmd} --help`)
70 expect(stdout).to.contain(`instance ${server.url} selected`)
73 it('Should remember the user', async function () {
76 const env = getEnvCli(server)
77 const stdout = await execCLI(`${env} ${cmd} auth list`)
79 expect(stdout).to.contain(server.url)
83 describe('Video upload/import', function () {
85 it('Should upload a video', async function () {
88 const env = getEnvCli(server)
90 const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4')
92 const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'`
94 await execCLI(`${env} ${cmd} upload ${params}`)
97 it('Should have the video uploaded', async function () {
98 const res = await getVideosList(server.url)
100 expect(res.body.total).to.equal(1)
102 const videos: Video[] = res.body.data
104 const video: VideoDetails = (await getVideo(server.url, videos[ 0 ].uuid)).body
106 expect(video.name).to.equal('test upload')
107 expect(video.support).to.equal('support_text')
108 expect(video.channel.name).to.equal('user_channel')
111 it('Should import a video', async function () {
114 const env = getEnvCli(server)
116 const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel`
118 await execCLI(`${env} ${cmd} import ${params}`)
121 it('Should have imported the video', async function () {
124 await waitJobs([ server ])
126 const res = await getVideosList(server.url)
128 expect(res.body.total).to.equal(2)
130 const videos: Video[] = res.body.data
131 const video = videos.find(v => v.name === 'small video - youtube')
132 expect(video).to.not.be.undefined
134 const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
135 expect(videoDetails.channel.name).to.equal('user_channel')
136 expect(videoDetails.support).to.equal('super support text')
137 expect(videoDetails.nsfw).to.be.false
139 // So we can reimport it
140 await removeVideo(server.url, userAccessToken, video.id)
143 it('Should import and override some imported attributes', async function () {
146 const env = getEnvCli(server)
148 const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel --video-name toto --nsfw --support support`
150 await execCLI(`${env} ${cmd} import ${params}`)
152 await waitJobs([ server ])
155 const res = await getVideosList(server.url)
156 expect(res.body.total).to.equal(2)
158 const videos: Video[] = res.body.data
159 const video = videos.find(v => v.name === 'toto')
160 expect(video).to.not.be.undefined
162 const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
163 expect(videoDetails.channel.name).to.equal('user_channel')
164 expect(videoDetails.support).to.equal('support')
165 expect(videoDetails.nsfw).to.be.true
166 expect(videoDetails.commentsEnabled).to.be.true
171 describe('Admin auth', function () {
173 it('Should remove the auth user', async function () {
174 const env = getEnvCli(server)
176 await execCLI(`${env} ${cmd} auth del ${server.url}`)
178 const stdout = await execCLI(`${env} ${cmd} --help`)
180 expect(stdout).to.contain('no instance selected')
183 it('Should add the admin user', async function () {
184 const env = getEnvCli(server)
185 await execCLI(`${env} ${cmd} auth add -u ${server.url} -U root -p test${server.internalServerNumber}`)
189 describe('Manage plugins', function () {
191 it('Should install a plugin', async function () {
194 const env = getEnvCli(server)
195 await execCLI(`${env} ${cmd} plugins install --npm-name peertube-plugin-hello-world`)
198 it('Should list installed plugins', async function () {
199 const env = getEnvCli(server)
200 const res = await execCLI(`${env} ${cmd} plugins list`)
202 expect(res).to.contain('peertube-plugin-hello-world')
205 it('Should uninstall the plugin', async function () {
206 const env = getEnvCli(server)
207 const res = await execCLI(`${env} ${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`)
209 expect(res).to.not.contain('peertube-plugin-hello-world')
213 after(async function () {
216 await cleanupTests([ server ])