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 it('Should display no selected instance', async function () {
49 const env = getEnvCli(server)
50 const stdout = await execCLI(`${env} ${cmd} --help`)
52 expect(stdout).to.contain('no instance selected')
55 it('Should add a user', async function () {
58 const env = getEnvCli(server)
59 await execCLI(`${env} ${cmd} auth add -u ${server.url} -U user_1 -p super_password`)
62 it('Should default to this user', async function () {
65 const env = getEnvCli(server)
66 const stdout = await execCLI(`${env} ${cmd} --help`)
68 expect(stdout).to.contain(`instance ${server.url} selected`)
71 it('Should remember the user', async function () {
74 const env = getEnvCli(server)
75 const stdout = await execCLI(`${env} ${cmd} auth list`)
77 expect(stdout).to.contain(server.url)
80 it('Should upload a video', async function () {
83 const env = getEnvCli(server)
85 const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4')
87 const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'`
89 await execCLI(`${env} ${cmd} upload ${params}`)
92 it('Should have the video uploaded', async function () {
93 const res = await getVideosList(server.url)
95 expect(res.body.total).to.equal(1)
97 const videos: Video[] = res.body.data
99 const video: VideoDetails = (await getVideo(server.url, videos[0].uuid)).body
101 expect(video.name).to.equal('test upload')
102 expect(video.support).to.equal('support_text')
103 expect(video.channel.name).to.equal('user_channel')
106 it('Should import a video', async function () {
109 const env = getEnvCli(server)
111 const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel`
113 await execCLI(`${env} ${cmd} import ${params}`)
116 it('Should have imported the video', async function () {
119 await waitJobs([ server ])
121 const res = await getVideosList(server.url)
123 expect(res.body.total).to.equal(2)
125 const videos: Video[] = res.body.data
126 const video = videos.find(v => v.name === 'small video - youtube')
127 expect(video).to.not.be.undefined
129 const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
130 expect(videoDetails.channel.name).to.equal('user_channel')
131 expect(videoDetails.support).to.equal('super support text')
132 expect(videoDetails.nsfw).to.be.false
134 // So we can reimport it
135 await removeVideo(server.url, userAccessToken, video.id)
138 it('Should import and override some imported attributes', async function () {
141 const env = getEnvCli(server)
143 const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel --video-name toto --nsfw --support support`
145 await execCLI(`${env} ${cmd} import ${params}`)
147 await waitJobs([ server ])
150 const res = await getVideosList(server.url)
151 expect(res.body.total).to.equal(2)
153 const videos: Video[] = res.body.data
154 const video = videos.find(v => v.name === 'toto')
155 expect(video).to.not.be.undefined
157 const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
158 expect(videoDetails.channel.name).to.equal('user_channel')
159 expect(videoDetails.support).to.equal('support')
160 expect(videoDetails.nsfw).to.be.true
164 it('Should remove the auth user', async function () {
165 const env = getEnvCli(server)
167 await execCLI(`${env} ${cmd} auth del ${server.url}`)
169 const stdout = await execCLI(`${env} ${cmd} --help`)
171 expect(stdout).to.contain('no instance selected')
174 after(async function () {
177 await cleanupTests([ server ])