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