1 /* tslint:disable:no-unused-expression */
4 import { expect } from 'chai'
7 buildAbsoluteFixturePath,
16 setAccessTokensToServers,
18 } from '../../../shared/extra-utils'
19 import { User, Video } from '../../../shared'
20 import { getYoutubeVideoUrl } from '../../../shared/extra-utils/videos/video-imports'
22 describe('Test CLI wrapper', function () {
23 let server: ServerInfo
26 const cmd = 'node ./dist/server/tools/peertube.js'
28 before(async function () {
31 server = await flushAndRunServer(1)
32 await setAccessTokensToServers([ server ])
34 await createUser({ url: server.url, accessToken: server.accessToken, username: 'user_1', password: 'super_password' })
36 const userAccessToken = await userLogin(server, { username: 'user_1', password: 'super_password' })
39 const res = await addVideoChannel(server.url, userAccessToken, { name: 'user_channel', displayName: 'User channel' })
40 channelId = res.body.videoChannel.id
44 it('Should display no selected instance', async function () {
47 const env = getEnvCli(server)
48 const stdout = await execCLI(`${env} ${cmd} --help`)
50 expect(stdout).to.contain('no instance selected')
53 it('Should add a user', async function () {
56 const env = getEnvCli(server)
57 await execCLI(`${env} ${cmd} auth add -u ${server.url} -U user_1 -p super_password`)
60 it('Should default to this user', async function () {
63 const env = getEnvCli(server)
64 const stdout = await execCLI(`${env} ${cmd} --help`)
66 expect(stdout).to.contain(`instance ${server.url} selected`)
69 it('Should remember the user', async function () {
72 const env = getEnvCli(server)
73 const stdout = await execCLI(`${env} ${cmd} auth list`)
75 expect(stdout).to.contain(server.url)
78 it('Should upload a video', async function () {
81 const env = getEnvCli(server)
83 const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4')
85 const params = `-f ${fixture} --video-name 'test upload' --channel-id ${channelId}`
87 await execCLI(`${env} ${cmd} upload ${params}`)
90 it('Should have the video uploaded', async function () {
91 const res = await getVideosList(server.url)
93 expect(res.body.total).to.equal(1)
95 const videos: Video[] = res.body.data
96 expect(videos[0].name).to.equal('test upload')
97 expect(videos[0].channel.name).to.equal('user_channel')
100 it('Should import a video', async function () {
103 const env = getEnvCli(server)
105 const params = `--target-url ${getYoutubeVideoUrl()} --channel-id ${channelId}`
107 await execCLI(`${env} ${cmd} import ${params}`)
110 it('Should have imported the video', async function () {
113 await waitJobs([ server ])
115 const res = await getVideosList(server.url)
117 expect(res.body.total).to.equal(2)
119 const videos: Video[] = res.body.data
120 const video = videos.find(v => v.name === 'small video - youtube')
122 expect(video).to.not.be.undefined
123 expect(video.channel.name).to.equal('user_channel')
126 it('Should remove the auth user', async function () {
127 const env = getEnvCli(server)
129 await execCLI(`${env} ${cmd} auth del ${server.url}`)
131 const stdout = await execCLI(`${env} ${cmd} --help`)
133 expect(stdout).to.contain('no instance selected')
136 after(async function () {
139 await cleanupTests([ server ])