]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/cli/peertube.ts
f2a9849628547a11b853a35b05e13c96297a9f68
[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 {
6 areHttpImportTestsDisabled,
7 buildAbsoluteFixturePath,
8 cleanupTests,
9 CLICommand,
10 createSingleServer,
11 doubleFollow,
12 FIXTURE_URLS,
13 PeerTubeServer,
14 setAccessTokensToServers,
15 testHelloWorldRegisteredSettings,
16 waitJobs
17 } from '../../../shared/extra-utils'
18
19 describe('Test CLI wrapper', function () {
20 let server: PeerTubeServer
21 let userAccessToken: string
22
23 let cliCommand: CLICommand
24
25 const cmd = 'node ./dist/server/tools/peertube.js'
26
27 before(async function () {
28 this.timeout(30000)
29
30 server = await createSingleServer(1)
31 await setAccessTokensToServers([ server ])
32
33 await server.users.create({ username: 'user_1', password: 'super_password' })
34
35 userAccessToken = await server.login.getAccessToken({ username: 'user_1', password: 'super_password' })
36
37 {
38 const attributes = { name: 'user_channel', displayName: 'User channel', support: 'super support text' }
39 await server.channels.create({ token: userAccessToken, attributes })
40 }
41
42 cliCommand = server.cli
43 })
44
45 describe('Authentication and instance selection', function () {
46
47 it('Should get an access token', async function () {
48 const stdout = await cliCommand.execWithEnv(`${cmd} token --url ${server.url} --username user_1 --password super_password`)
49 const token = stdout.trim()
50
51 const body = await server.users.getMyInfo({ token })
52 expect(body.username).to.equal('user_1')
53 })
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 { total, data } = await server.videos.list()
107 expect(total).to.equal(1)
108
109 const video = await server.videos.get({ id: data[0].uuid })
110 expect(video.name).to.equal('test upload')
111 expect(video.support).to.equal('support_text')
112 expect(video.channel.name).to.equal('user_channel')
113 })
114
115 it('Should import a video', async function () {
116 if (areHttpImportTestsDisabled()) return
117
118 this.timeout(60000)
119
120 const params = `--target-url ${FIXTURE_URLS.youtube} --channel-name user_channel`
121 await cliCommand.execWithEnv(`${cmd} import ${params}`)
122 })
123
124 it('Should have imported the video', async function () {
125 if (areHttpImportTestsDisabled()) return
126
127 this.timeout(60000)
128
129 await waitJobs([ server ])
130
131 const { total, data } = await server.videos.list()
132 expect(total).to.equal(2)
133
134 const video = data.find(v => v.name === 'small video - youtube')
135 expect(video).to.not.be.undefined
136
137 const videoDetails = await server.videos.get({ id: video.id })
138 expect(videoDetails.channel.name).to.equal('user_channel')
139 expect(videoDetails.support).to.equal('super support text')
140 expect(videoDetails.nsfw).to.be.false
141
142 // So we can reimport it
143 await server.videos.remove({ token: userAccessToken, id: video.id })
144 })
145
146 it('Should import and override some imported attributes', async function () {
147 if (areHttpImportTestsDisabled()) return
148
149 this.timeout(60000)
150
151 const params = `--target-url ${FIXTURE_URLS.youtube} ` +
152 `--channel-name user_channel --video-name toto --nsfw --support support`
153 await cliCommand.execWithEnv(`${cmd} import ${params}`)
154
155 await waitJobs([ server ])
156
157 {
158 const { total, data } = await server.videos.list()
159 expect(total).to.equal(2)
160
161 const video = data.find(v => v.name === 'toto')
162 expect(video).to.not.be.undefined
163
164 const videoDetails = await server.videos.get({ id: video.id })
165 expect(videoDetails.channel.name).to.equal('user_channel')
166 expect(videoDetails.support).to.equal('support')
167 expect(videoDetails.nsfw).to.be.true
168 expect(videoDetails.commentsEnabled).to.be.true
169 }
170 })
171 })
172
173 describe('Admin auth', function () {
174
175 it('Should remove the auth user', async function () {
176 await cliCommand.execWithEnv(`${cmd} auth del ${server.url}`)
177
178 const stdout = await cliCommand.execWithEnv(`${cmd} --help`)
179 expect(stdout).to.contain('no instance selected')
180 })
181
182 it('Should add the admin user', async function () {
183 await cliCommand.execWithEnv(`${cmd} auth add -u ${server.url} -U root -p test${server.internalServerNumber}`)
184 })
185 })
186
187 describe('Manage plugins', function () {
188
189 it('Should install a plugin', async function () {
190 this.timeout(60000)
191
192 await cliCommand.execWithEnv(`${cmd} plugins install --npm-name peertube-plugin-hello-world`)
193 })
194
195 it('Should have registered settings', async function () {
196 await testHelloWorldRegisteredSettings(server)
197 })
198
199 it('Should list installed plugins', async function () {
200 const res = await cliCommand.execWithEnv(`${cmd} plugins list`)
201
202 expect(res).to.contain('peertube-plugin-hello-world')
203 })
204
205 it('Should uninstall the plugin', async function () {
206 const res = await cliCommand.execWithEnv(`${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`)
207
208 expect(res).to.not.contain('peertube-plugin-hello-world')
209 })
210 })
211
212 describe('Manage video redundancies', function () {
213 let anotherServer: PeerTubeServer
214 let video1Server2: number
215 let servers: PeerTubeServer[]
216
217 before(async function () {
218 this.timeout(120000)
219
220 anotherServer = await createSingleServer(2)
221 await setAccessTokensToServers([ anotherServer ])
222
223 await doubleFollow(server, anotherServer)
224
225 servers = [ server, anotherServer ]
226 await waitJobs(servers)
227
228 const { uuid } = await anotherServer.videos.quickUpload({ name: 'super video' })
229 await waitJobs(servers)
230
231 video1Server2 = await server.videos.getId({ uuid })
232 })
233
234 it('Should add a redundancy', async function () {
235 this.timeout(60000)
236
237 const params = `add --video ${video1Server2}`
238 await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
239
240 await waitJobs(servers)
241 })
242
243 it('Should list redundancies', async function () {
244 this.timeout(60000)
245
246 {
247 const params = 'list-my-redundancies'
248 const stdout = await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
249
250 expect(stdout).to.contain('super video')
251 expect(stdout).to.contain(`localhost:${server.port}`)
252 }
253 })
254
255 it('Should remove a redundancy', async function () {
256 this.timeout(60000)
257
258 const params = `remove --video ${video1Server2}`
259 await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
260
261 await waitJobs(servers)
262
263 {
264 const params = 'list-my-redundancies'
265 const stdout = await cliCommand.execWithEnv(`${cmd} redundancy ${params}`)
266
267 expect(stdout).to.not.contain('super video')
268 }
269 })
270
271 after(async function () {
272 this.timeout(10000)
273
274 await cleanupTests([ anotherServer ])
275 })
276 })
277
278 after(async function () {
279 this.timeout(10000)
280
281 await cleanupTests([ server ])
282 })
283 })