]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/cli/peertube.ts
Add more CLI tests
[github/Chocobozzz/PeerTube.git] / server / tests / cli / peertube.ts
1 /* tslint:disable:no-unused-expression */
2
3 import 'mocha'
4 import { expect } from 'chai'
5 import {
6 addVideoChannel,
7 buildAbsoluteFixturePath,
8 cleanupTests,
9 createUser,
10 execCLI,
11 flushAndRunServer,
12 getEnvCli,
13 getMyUserInformation,
14 getVideosList,
15 ServerInfo,
16 setAccessTokensToServers,
17 userLogin, waitJobs
18 } from '../../../shared/extra-utils'
19 import { User, Video } from '../../../shared'
20 import { getYoutubeVideoUrl } from '../../../shared/extra-utils/videos/video-imports'
21
22 describe('Test CLI wrapper', function () {
23 let server: ServerInfo
24 let channelId: number
25
26 const cmd = 'node ./dist/server/tools/peertube.js'
27
28 before(async function () {
29 this.timeout(30000)
30
31 server = await flushAndRunServer(1)
32 await setAccessTokensToServers([ server ])
33
34 await createUser({ url: server.url, accessToken: server.accessToken, username: 'user_1', password: 'super_password' })
35
36 const userAccessToken = await userLogin(server, { username: 'user_1', password: 'super_password' })
37
38 {
39 const res = await addVideoChannel(server.url, userAccessToken, { name: 'user_channel', displayName: 'User channel' })
40 channelId = res.body.videoChannel.id
41 }
42 })
43
44 it('Should display no selected instance', async function () {
45 this.timeout(60000)
46
47 const env = getEnvCli(server)
48 const stdout = await execCLI(`${env} ${cmd} --help`)
49
50 expect(stdout).to.contain('no instance selected')
51 })
52
53 it('Should add a user', async function () {
54 this.timeout(60000)
55
56 const env = getEnvCli(server)
57 await execCLI(`${env} ${cmd} auth add -u ${server.url} -U user_1 -p super_password`)
58 })
59
60 it('Should default to this user', async function () {
61 this.timeout(60000)
62
63 const env = getEnvCli(server)
64 const stdout = await execCLI(`${env} ${cmd} --help`)
65
66 expect(stdout).to.contain(`instance ${server.url} selected`)
67 })
68
69 it('Should remember the user', async function () {
70 this.timeout(60000)
71
72 const env = getEnvCli(server)
73 const stdout = await execCLI(`${env} ${cmd} auth list`)
74
75 expect(stdout).to.contain(server.url)
76 })
77
78 it('Should upload a video', async function () {
79 this.timeout(60000)
80
81 const env = getEnvCli(server)
82
83 const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4')
84
85 const params = `-f ${fixture} --video-name 'test upload' --channel-id ${channelId}`
86
87 await execCLI(`${env} ${cmd} upload ${params}`)
88 })
89
90 it('Should have the video uploaded', async function () {
91 const res = await getVideosList(server.url)
92
93 expect(res.body.total).to.equal(1)
94
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')
98 })
99
100 it('Should import a video', async function () {
101 this.timeout(60000)
102
103 const env = getEnvCli(server)
104
105 const params = `--target-url ${getYoutubeVideoUrl()} --channel-id ${channelId}`
106
107 await execCLI(`${env} ${cmd} import ${params}`)
108 })
109
110 it('Should have imported the video', async function () {
111 this.timeout(60000)
112
113 await waitJobs([ server ])
114
115 const res = await getVideosList(server.url)
116
117 expect(res.body.total).to.equal(2)
118
119 const videos: Video[] = res.body.data
120 const video = videos.find(v => v.name === 'small video - youtube')
121
122 expect(video).to.not.be.undefined
123 expect(video.channel.name).to.equal('user_channel')
124 })
125
126 it('Should remove the auth user', async function () {
127 const env = getEnvCli(server)
128
129 await execCLI(`${env} ${cmd} auth del ${server.url}`)
130
131 const stdout = await execCLI(`${env} ${cmd} --help`)
132
133 expect(stdout).to.contain('no instance selected')
134 })
135
136 after(async function () {
137 this.timeout(10000)
138
139 await cleanupTests([ server ])
140 })
141 })