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