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