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