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