]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
1a12f66d | 2 | |
8704acf4 | 3 | import 'mocha' |
1a12f66d | 4 | import { expect } from 'chai' |
5c0ecc34 | 5 | import { Video, VideoDetails } from '../../../shared' |
8704acf4 | 6 | import { |
1a12f66d | 7 | addVideoChannel, |
5c0ecc34 | 8 | areHttpImportTestsDisabled, |
1a12f66d C |
9 | buildAbsoluteFixturePath, |
10 | cleanupTests, | |
a1587156 C |
11 | createUser, |
12 | doubleFollow, | |
8704acf4 | 13 | execCLI, |
210feb6c | 14 | flushAndRunServer, |
a1587156 C |
15 | getEnvCli, |
16 | getLocalIdByUUID, | |
1205823f | 17 | getVideo, |
1a12f66d | 18 | getVideosList, |
a1587156 | 19 | removeVideo, |
8704acf4 | 20 | ServerInfo, |
a1587156 | 21 | setAccessTokensToServers, |
353f8bc0 | 22 | testHelloWorldRegisteredSettings, |
a1587156 | 23 | uploadVideoAndGetId, |
1205823f C |
24 | userLogin, |
25 | waitJobs | |
94565d52 | 26 | } from '../../../shared/extra-utils' |
1a12f66d | 27 | import { getYoutubeVideoUrl } from '../../../shared/extra-utils/videos/video-imports' |
8704acf4 RK |
28 | |
29 | describe('Test CLI wrapper', function () { | |
30 | let server: ServerInfo | |
1205823f | 31 | let userAccessToken: string |
1a12f66d | 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 | { | |
1205823f C |
46 | const args = { name: 'user_channel', displayName: 'User channel', support: 'super support text' } |
47 | await addVideoChannel(server.url, userAccessToken, args) | |
1a12f66d | 48 | } |
8704acf4 RK |
49 | }) |
50 | ||
9b474844 | 51 | describe('Authentication and instance selection', function () { |
8704acf4 | 52 | |
9b474844 C |
53 | it('Should display no selected instance', async function () { |
54 | this.timeout(60000) | |
8704acf4 | 55 | |
9b474844 C |
56 | const env = getEnvCli(server) |
57 | const stdout = await execCLI(`${env} ${cmd} --help`) | |
1a12f66d | 58 | |
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 | |
9b474844 C |
65 | const env = getEnvCli(server) |
66 | await execCLI(`${env} ${cmd} auth add -u ${server.url} -U user_1 -p super_password`) | |
67 | }) | |
1a12f66d | 68 | |
9b474844 C |
69 | it('Should default to this user', async function () { |
70 | this.timeout(60000) | |
1a12f66d | 71 | |
9b474844 C |
72 | const env = getEnvCli(server) |
73 | const stdout = await execCLI(`${env} ${cmd} --help`) | |
1a12f66d | 74 | |
9b474844 C |
75 | expect(stdout).to.contain(`instance ${server.url} selected`) |
76 | }) | |
1a12f66d | 77 | |
9b474844 C |
78 | it('Should remember the user', async function () { |
79 | this.timeout(60000) | |
1a12f66d | 80 | |
9b474844 C |
81 | const env = getEnvCli(server) |
82 | const stdout = await execCLI(`${env} ${cmd} auth list`) | |
83 | ||
84 | expect(stdout).to.contain(server.url) | |
85 | }) | |
1a12f66d C |
86 | }) |
87 | ||
9b474844 | 88 | describe('Video upload/import', function () { |
1a12f66d | 89 | |
9b474844 C |
90 | it('Should upload a video', async function () { |
91 | this.timeout(60000) | |
1a12f66d | 92 | |
9b474844 | 93 | const env = getEnvCli(server) |
1a12f66d | 94 | |
9b474844 | 95 | const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4') |
1a12f66d | 96 | |
9b474844 | 97 | const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'` |
1a12f66d | 98 | |
9b474844 C |
99 | await execCLI(`${env} ${cmd} upload ${params}`) |
100 | }) | |
1a12f66d | 101 | |
9b474844 C |
102 | it('Should have the video uploaded', async function () { |
103 | const res = await getVideosList(server.url) | |
1a12f66d | 104 | |
9b474844 | 105 | expect(res.body.total).to.equal(1) |
1205823f | 106 | |
9b474844 | 107 | const videos: Video[] = res.body.data |
1205823f | 108 | |
a1587156 | 109 | const video: VideoDetails = (await getVideo(server.url, videos[0].uuid)).body |
1a12f66d | 110 | |
9b474844 C |
111 | expect(video.name).to.equal('test upload') |
112 | expect(video.support).to.equal('support_text') | |
113 | expect(video.channel.name).to.equal('user_channel') | |
114 | }) | |
1a12f66d | 115 | |
9b474844 | 116 | it('Should import a video', async function () { |
5c0ecc34 C |
117 | if (areHttpImportTestsDisabled()) return |
118 | ||
9b474844 | 119 | this.timeout(60000) |
1a12f66d | 120 | |
9b474844 | 121 | const env = getEnvCli(server) |
1a12f66d | 122 | |
9b474844 | 123 | const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel` |
8704acf4 | 124 | |
9b474844 C |
125 | await execCLI(`${env} ${cmd} import ${params}`) |
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 | |
9b474844 | 157 | const env = getEnvCli(server) |
1205823f | 158 | |
9b474844 | 159 | const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel --video-name toto --nsfw --support support` |
1205823f | 160 | |
9b474844 | 161 | await execCLI(`${env} ${cmd} import ${params}`) |
1205823f | 162 | |
9b474844 | 163 | await waitJobs([ server ]) |
1205823f | 164 | |
9b474844 C |
165 | { |
166 | const res = await getVideosList(server.url) | |
167 | expect(res.body.total).to.equal(2) | |
1205823f | 168 | |
9b474844 C |
169 | const videos: Video[] = res.body.data |
170 | const video = videos.find(v => v.name === 'toto') | |
171 | expect(video).to.not.be.undefined | |
172 | ||
173 | const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body | |
174 | expect(videoDetails.channel.name).to.equal('user_channel') | |
175 | expect(videoDetails.support).to.equal('support') | |
176 | expect(videoDetails.nsfw).to.be.true | |
177 | expect(videoDetails.commentsEnabled).to.be.true | |
178 | } | |
179 | }) | |
1a12f66d C |
180 | }) |
181 | ||
9b474844 C |
182 | describe('Admin auth', function () { |
183 | ||
184 | it('Should remove the auth user', async function () { | |
185 | const env = getEnvCli(server) | |
186 | ||
187 | await execCLI(`${env} ${cmd} auth del ${server.url}`) | |
188 | ||
189 | const stdout = await execCLI(`${env} ${cmd} --help`) | |
190 | ||
191 | expect(stdout).to.contain('no instance selected') | |
192 | }) | |
193 | ||
194 | it('Should add the admin user', async function () { | |
195 | const env = getEnvCli(server) | |
196 | await execCLI(`${env} ${cmd} auth add -u ${server.url} -U root -p test${server.internalServerNumber}`) | |
197 | }) | |
198 | }) | |
199 | ||
200 | describe('Manage plugins', function () { | |
201 | ||
202 | it('Should install a plugin', async function () { | |
203 | this.timeout(60000) | |
204 | ||
205 | const env = getEnvCli(server) | |
206 | await execCLI(`${env} ${cmd} plugins install --npm-name peertube-plugin-hello-world`) | |
207 | }) | |
208 | ||
353f8bc0 C |
209 | it('Should have registered settings', async function () { |
210 | await testHelloWorldRegisteredSettings(server) | |
211 | }) | |
212 | ||
9b474844 C |
213 | it('Should list installed plugins', async function () { |
214 | const env = getEnvCli(server) | |
215 | const res = await execCLI(`${env} ${cmd} plugins list`) | |
1a12f66d | 216 | |
9b474844 C |
217 | expect(res).to.contain('peertube-plugin-hello-world') |
218 | }) | |
1a12f66d | 219 | |
9b474844 C |
220 | it('Should uninstall the plugin', async function () { |
221 | const env = getEnvCli(server) | |
222 | const res = await execCLI(`${env} ${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`) | |
1a12f66d | 223 | |
9b474844 C |
224 | expect(res).to.not.contain('peertube-plugin-hello-world') |
225 | }) | |
8704acf4 RK |
226 | }) |
227 | ||
26fcf2ef C |
228 | describe('Manage video redundancies', function () { |
229 | let anotherServer: ServerInfo | |
230 | let video1Server2: number | |
231 | let servers: ServerInfo[] | |
232 | ||
233 | before(async function () { | |
234 | this.timeout(120000) | |
235 | ||
236 | anotherServer = await flushAndRunServer(2) | |
237 | await setAccessTokensToServers([ anotherServer ]) | |
238 | ||
239 | await doubleFollow(server, anotherServer) | |
240 | ||
241 | servers = [ server, anotherServer ] | |
242 | await waitJobs(servers) | |
243 | ||
244 | const uuid = (await uploadVideoAndGetId({ server: anotherServer, videoName: 'super video' })).uuid | |
245 | await waitJobs(servers) | |
246 | ||
247 | video1Server2 = await getLocalIdByUUID(server.url, uuid) | |
248 | }) | |
249 | ||
250 | it('Should add a redundancy', async function () { | |
251 | this.timeout(60000) | |
252 | ||
253 | const env = getEnvCli(server) | |
254 | ||
255 | const params = `add --video ${video1Server2}` | |
256 | ||
257 | await execCLI(`${env} ${cmd} redundancy ${params}`) | |
258 | ||
259 | await waitJobs(servers) | |
260 | }) | |
261 | ||
262 | it('Should list redundancies', async function () { | |
263 | this.timeout(60000) | |
264 | ||
265 | { | |
266 | const env = getEnvCli(server) | |
267 | ||
a1587156 | 268 | const params = 'list-my-redundancies' |
26fcf2ef C |
269 | const stdout = await execCLI(`${env} ${cmd} redundancy ${params}`) |
270 | ||
271 | expect(stdout).to.contain('super video') | |
272 | expect(stdout).to.contain(`localhost:${server.port}`) | |
273 | } | |
274 | }) | |
275 | ||
276 | it('Should remove a redundancy', async function () { | |
277 | this.timeout(60000) | |
278 | ||
279 | const env = getEnvCli(server) | |
280 | ||
281 | const params = `remove --video ${video1Server2}` | |
282 | ||
283 | await execCLI(`${env} ${cmd} redundancy ${params}`) | |
284 | ||
285 | await waitJobs(servers) | |
286 | ||
287 | { | |
288 | const env = getEnvCli(server) | |
a1587156 | 289 | const params = 'list-my-redundancies' |
26fcf2ef C |
290 | const stdout = await execCLI(`${env} ${cmd} redundancy ${params}`) |
291 | ||
292 | expect(stdout).to.not.contain('super video') | |
293 | } | |
294 | }) | |
e669ff58 C |
295 | |
296 | after(async function () { | |
297 | this.timeout(10000) | |
298 | ||
299 | await cleanupTests([ anotherServer ]) | |
300 | }) | |
26fcf2ef C |
301 | }) |
302 | ||
8704acf4 | 303 | after(async function () { |
e5cb43e0 C |
304 | this.timeout(10000) |
305 | ||
7c3b7976 | 306 | await cleanupTests([ server ]) |
8704acf4 RK |
307 | }) |
308 | }) |