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