]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/cli/peertube.ts
Introduce channels command
[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 {
5c0ecc34 7 areHttpImportTestsDisabled,
1a12f66d
C
8 buildAbsoluteFixturePath,
9 cleanupTests,
329619b3 10 CLICommand,
a1587156
C
11 createUser,
12 doubleFollow,
210feb6c 13 flushAndRunServer,
a1587156 14 getLocalIdByUUID,
1205823f 15 getVideo,
1a12f66d 16 getVideosList,
6910f20f 17 ImportsCommand,
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'
8704acf4
RK
26
27describe('Test CLI wrapper', function () {
28 let server: ServerInfo
1205823f 29 let userAccessToken: string
1a12f66d 30
329619b3
C
31 let cliCommand: CLICommand
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 {
a5461888
C
46 const attributes = { name: 'user_channel', displayName: 'User channel', support: 'super support text' }
47 await server.channelsCommand.create({ token: userAccessToken, attributes })
1a12f66d 48 }
329619b3
C
49
50 cliCommand = server.cliCommand
8704acf4
RK
51 })
52
9b474844 53 describe('Authentication and instance selection', function () {
8704acf4 54
9b474844
C
55 it('Should display no selected instance', async function () {
56 this.timeout(60000)
8704acf4 57
329619b3 58 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
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
329619b3 65 await cliCommand.execWithEnv(`${cmd} auth add -u ${server.url} -U user_1 -p super_password`)
9b474844 66 })
1a12f66d 67
8e76aa1d
TS
68 it('Should not fail to add a user if there is a slash at the end of the instance URL', async function () {
69 this.timeout(60000)
70
329619b3
C
71 let fullServerURL = server.url + '/'
72
73 await cliCommand.execWithEnv(`${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
8e76aa1d
TS
74
75 fullServerURL = server.url + '/asdfasdf'
329619b3 76 await cliCommand.execWithEnv(`${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`)
8e76aa1d
TS
77 })
78
9b474844
C
79 it('Should default to this user', async function () {
80 this.timeout(60000)
1a12f66d 81
329619b3 82 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
9b474844
C
83 expect(stdout).to.contain(`instance ${server.url} selected`)
84 })
1a12f66d 85
9b474844
C
86 it('Should remember the user', async function () {
87 this.timeout(60000)
1a12f66d 88
329619b3 89 const stdout = await cliCommand.execWithEnv(`${cmd} auth list`)
9b474844
C
90 expect(stdout).to.contain(server.url)
91 })
1a12f66d
C
92 })
93
9b474844 94 describe('Video upload/import', function () {
1a12f66d 95
9b474844
C
96 it('Should upload a video', async function () {
97 this.timeout(60000)
1a12f66d 98
9b474844 99 const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4')
9b474844 100 const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'`
1a12f66d 101
329619b3 102 await cliCommand.execWithEnv(`${cmd} upload ${params}`)
9b474844 103 })
1a12f66d 104
9b474844
C
105 it('Should have the video uploaded', async function () {
106 const res = await getVideosList(server.url)
1a12f66d 107
9b474844 108 expect(res.body.total).to.equal(1)
1205823f 109
9b474844 110 const videos: Video[] = res.body.data
1205823f 111
a1587156 112 const video: VideoDetails = (await getVideo(server.url, videos[0].uuid)).body
1a12f66d 113
9b474844
C
114 expect(video.name).to.equal('test upload')
115 expect(video.support).to.equal('support_text')
116 expect(video.channel.name).to.equal('user_channel')
117 })
1a12f66d 118
9b474844 119 it('Should import a video', async function () {
5c0ecc34
C
120 if (areHttpImportTestsDisabled()) return
121
9b474844 122 this.timeout(60000)
1a12f66d 123
6910f20f 124 const params = `--target-url ${ImportsCommand.getYoutubeVideoUrl()} --channel-name user_channel`
329619b3 125 await cliCommand.execWithEnv(`${cmd} import ${params}`)
9b474844 126 })
8704acf4 127
9b474844 128 it('Should have imported the video', async function () {
5c0ecc34
C
129 if (areHttpImportTestsDisabled()) return
130
9b474844 131 this.timeout(60000)
1a12f66d 132
9b474844 133 await waitJobs([ server ])
1a12f66d 134
9b474844 135 const res = await getVideosList(server.url)
1a12f66d 136
9b474844 137 expect(res.body.total).to.equal(2)
1205823f 138
9b474844
C
139 const videos: Video[] = res.body.data
140 const video = videos.find(v => v.name === 'small video - youtube')
141 expect(video).to.not.be.undefined
1205823f 142
9b474844
C
143 const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body
144 expect(videoDetails.channel.name).to.equal('user_channel')
145 expect(videoDetails.support).to.equal('super support text')
146 expect(videoDetails.nsfw).to.be.false
1205823f 147
9b474844
C
148 // So we can reimport it
149 await removeVideo(server.url, userAccessToken, video.id)
150 })
1205823f 151
9b474844 152 it('Should import and override some imported attributes', async function () {
5c0ecc34
C
153 if (areHttpImportTestsDisabled()) return
154
9b474844 155 this.timeout(60000)
1205823f 156
6910f20f
C
157 const params = `--target-url ${ImportsCommand.getYoutubeVideoUrl()} ` +
158 `--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})