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