]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/cli/peertube.ts
Merge branch 'master' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / cli / peertube.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
1a12f66d 2
8704acf4 3import 'mocha'
1a12f66d 4import { expect } from 'chai'
8704acf4 5import {
1a12f66d
C
6 addVideoChannel,
7 buildAbsoluteFixturePath,
8 cleanupTests,
a1587156
C
9 createUser,
10 doubleFollow,
8704acf4 11 execCLI,
210feb6c 12 flushAndRunServer,
a1587156
C
13 getEnvCli,
14 getLocalIdByUUID,
1205823f 15 getVideo,
1a12f66d 16 getVideosList,
a1587156 17 removeVideo,
8704acf4 18 ServerInfo,
a1587156
C
19 setAccessTokensToServers,
20 uploadVideoAndGetId,
1205823f
C
21 userLogin,
22 waitJobs
94565d52 23} from '../../../shared/extra-utils'
1205823f 24import { Video, VideoDetails } from '../../../shared'
1a12f66d 25import { getYoutubeVideoUrl } from '../../../shared/extra-utils/videos/video-imports'
8704acf4
RK
26
27describe('Test CLI wrapper', function () {
28 let server: ServerInfo
1205823f 29 let userAccessToken: string
1a12f66d 30
8704acf4
RK
31 const cmd = 'node ./dist/server/tools/peertube.js'
32
33 before(async function () {
34 this.timeout(30000)
1a12f66d 35
210feb6c 36 server = await flushAndRunServer(1)
8704acf4
RK
37 await setAccessTokensToServers([ server ])
38
1a12f66d
C
39 await createUser({ url: server.url, accessToken: server.accessToken, username: 'user_1', password: 'super_password' })
40
1205823f 41 userAccessToken = await userLogin(server, { username: 'user_1', password: 'super_password' })
1a12f66d
C
42
43 {
1205823f
C
44 const args = { name: 'user_channel', displayName: 'User channel', support: 'super support text' }
45 await addVideoChannel(server.url, userAccessToken, args)
1a12f66d 46 }
8704acf4
RK
47 })
48
9b474844 49 describe('Authentication and instance selection', function () {
8704acf4 50
9b474844
C
51 it('Should display no selected instance', async function () {
52 this.timeout(60000)
8704acf4 53
9b474844
C
54 const env = getEnvCli(server)
55 const stdout = await execCLI(`${env} ${cmd} --help`)
1a12f66d 56
9b474844
C
57 expect(stdout).to.contain('no instance selected')
58 })
1a12f66d 59
9b474844
C
60 it('Should add a user', async function () {
61 this.timeout(60000)
1a12f66d 62
9b474844
C
63 const env = getEnvCli(server)
64 await execCLI(`${env} ${cmd} auth add -u ${server.url} -U user_1 -p super_password`)
65 })
1a12f66d 66
9b474844
C
67 it('Should default to this user', async function () {
68 this.timeout(60000)
1a12f66d 69
9b474844
C
70 const env = getEnvCli(server)
71 const stdout = await execCLI(`${env} ${cmd} --help`)
1a12f66d 72
9b474844
C
73 expect(stdout).to.contain(`instance ${server.url} selected`)
74 })
1a12f66d 75
9b474844
C
76 it('Should remember the user', async function () {
77 this.timeout(60000)
1a12f66d 78
9b474844
C
79 const env = getEnvCli(server)
80 const stdout = await execCLI(`${env} ${cmd} auth list`)
81
82 expect(stdout).to.contain(server.url)
83 })
1a12f66d
C
84 })
85
9b474844 86 describe('Video upload/import', function () {
1a12f66d 87
9b474844
C
88 it('Should upload a video', async function () {
89 this.timeout(60000)
1a12f66d 90
9b474844 91 const env = getEnvCli(server)
1a12f66d 92
9b474844 93 const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4')
1a12f66d 94
9b474844 95 const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'`
1a12f66d 96
9b474844
C
97 await execCLI(`${env} ${cmd} upload ${params}`)
98 })
1a12f66d 99
9b474844
C
100 it('Should have the video uploaded', async function () {
101 const res = await getVideosList(server.url)
1a12f66d 102
9b474844 103 expect(res.body.total).to.equal(1)
1205823f 104
9b474844 105 const videos: Video[] = res.body.data
1205823f 106
a1587156 107 const video: VideoDetails = (await getVideo(server.url, videos[0].uuid)).body
1a12f66d 108
9b474844
C
109 expect(video.name).to.equal('test upload')
110 expect(video.support).to.equal('support_text')
111 expect(video.channel.name).to.equal('user_channel')
112 })
1a12f66d 113
9b474844
C
114 it('Should import a video', async function () {
115 this.timeout(60000)
1a12f66d 116
9b474844 117 const env = getEnvCli(server)
1a12f66d 118
9b474844 119 const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel`
8704acf4 120
9b474844
C
121 await execCLI(`${env} ${cmd} import ${params}`)
122 })
8704acf4 123
9b474844
C
124 it('Should have imported the video', async function () {
125 this.timeout(60000)
1a12f66d 126
9b474844 127 await waitJobs([ server ])
1a12f66d 128
9b474844 129 const res = await getVideosList(server.url)
1a12f66d 130
9b474844 131 expect(res.body.total).to.equal(2)
1205823f 132
9b474844
C
133 const videos: Video[] = res.body.data
134 const video = videos.find(v => v.name === 'small video - youtube')
135 expect(video).to.not.be.undefined
1205823f 136
9b474844
C
137 const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
138 expect(videoDetails.channel.name).to.equal('user_channel')
139 expect(videoDetails.support).to.equal('super support text')
140 expect(videoDetails.nsfw).to.be.false
1205823f 141
9b474844
C
142 // So we can reimport it
143 await removeVideo(server.url, userAccessToken, video.id)
144 })
1205823f 145
9b474844
C
146 it('Should import and override some imported attributes', async function () {
147 this.timeout(60000)
1205823f 148
9b474844 149 const env = getEnvCli(server)
1205823f 150
9b474844 151 const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel --video-name toto --nsfw --support support`
1205823f 152
9b474844 153 await execCLI(`${env} ${cmd} import ${params}`)
1205823f 154
9b474844 155 await waitJobs([ server ])
1205823f 156
9b474844
C
157 {
158 const res = await getVideosList(server.url)
159 expect(res.body.total).to.equal(2)
1205823f 160
9b474844
C
161 const videos: Video[] = res.body.data
162 const video = videos.find(v => v.name === 'toto')
163 expect(video).to.not.be.undefined
164
165 const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
166 expect(videoDetails.channel.name).to.equal('user_channel')
167 expect(videoDetails.support).to.equal('support')
168 expect(videoDetails.nsfw).to.be.true
169 expect(videoDetails.commentsEnabled).to.be.true
170 }
171 })
1a12f66d
C
172 })
173
9b474844
C
174 describe('Admin auth', function () {
175
176 it('Should remove the auth user', async function () {
177 const env = getEnvCli(server)
178
179 await execCLI(`${env} ${cmd} auth del ${server.url}`)
180
181 const stdout = await execCLI(`${env} ${cmd} --help`)
182
183 expect(stdout).to.contain('no instance selected')
184 })
185
186 it('Should add the admin user', async function () {
187 const env = getEnvCli(server)
188 await execCLI(`${env} ${cmd} auth add -u ${server.url} -U root -p test${server.internalServerNumber}`)
189 })
190 })
191
192 describe('Manage plugins', function () {
193
194 it('Should install a plugin', async function () {
195 this.timeout(60000)
196
197 const env = getEnvCli(server)
198 await execCLI(`${env} ${cmd} plugins install --npm-name peertube-plugin-hello-world`)
199 })
200
201 it('Should list installed plugins', async function () {
202 const env = getEnvCli(server)
203 const res = await execCLI(`${env} ${cmd} plugins list`)
1a12f66d 204
9b474844
C
205 expect(res).to.contain('peertube-plugin-hello-world')
206 })
1a12f66d 207
9b474844
C
208 it('Should uninstall the plugin', async function () {
209 const env = getEnvCli(server)
210 const res = await execCLI(`${env} ${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`)
1a12f66d 211
9b474844
C
212 expect(res).to.not.contain('peertube-plugin-hello-world')
213 })
8704acf4
RK
214 })
215
26fcf2ef
C
216 describe('Manage video redundancies', function () {
217 let anotherServer: ServerInfo
218 let video1Server2: number
219 let servers: ServerInfo[]
220
221 before(async function () {
222 this.timeout(120000)
223
224 anotherServer = await flushAndRunServer(2)
225 await setAccessTokensToServers([ anotherServer ])
226
227 await doubleFollow(server, anotherServer)
228
229 servers = [ server, anotherServer ]
230 await waitJobs(servers)
231
232 const uuid = (await uploadVideoAndGetId({ server: anotherServer, videoName: 'super video' })).uuid
233 await waitJobs(servers)
234
235 video1Server2 = await getLocalIdByUUID(server.url, uuid)
236 })
237
238 it('Should add a redundancy', async function () {
239 this.timeout(60000)
240
241 const env = getEnvCli(server)
242
243 const params = `add --video ${video1Server2}`
244
245 await execCLI(`${env} ${cmd} redundancy ${params}`)
246
247 await waitJobs(servers)
248 })
249
250 it('Should list redundancies', async function () {
251 this.timeout(60000)
252
253 {
254 const env = getEnvCli(server)
255
a1587156 256 const params = 'list-my-redundancies'
26fcf2ef
C
257 const stdout = await execCLI(`${env} ${cmd} redundancy ${params}`)
258
259 expect(stdout).to.contain('super video')
260 expect(stdout).to.contain(`localhost:${server.port}`)
261 }
262 })
263
264 it('Should remove a redundancy', async function () {
265 this.timeout(60000)
266
267 const env = getEnvCli(server)
268
269 const params = `remove --video ${video1Server2}`
270
271 await execCLI(`${env} ${cmd} redundancy ${params}`)
272
273 await waitJobs(servers)
274
275 {
276 const env = getEnvCli(server)
a1587156 277 const params = 'list-my-redundancies'
26fcf2ef
C
278 const stdout = await execCLI(`${env} ${cmd} redundancy ${params}`)
279
280 expect(stdout).to.not.contain('super video')
281 }
282 })
e669ff58
C
283
284 after(async function () {
285 this.timeout(10000)
286
287 await cleanupTests([ anotherServer ])
288 })
26fcf2ef
C
289 })
290
8704acf4 291 after(async function () {
e5cb43e0
C
292 this.timeout(10000)
293
7c3b7976 294 await cleanupTests([ server ])
8704acf4
RK
295 })
296})