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