diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-21 15:51:30 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-21 15:51:30 +0200 |
commit | a24bd1ed41b43790bab6ba789580bb4e85f07d85 (patch) | |
tree | a54b0f6c921ba83a6e909cd0ced325b2d4b8863c /server/tests/cli/peertube.ts | |
parent | 5f26f13b3c16ac5ae0a3b0a7142d84a9528cf565 (diff) | |
parent | c63830f15403ac4e750829f27d8bbbdc9a59282c (diff) | |
download | PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.gz PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.zst PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.zip |
Merge branch 'next' into develop
Diffstat (limited to 'server/tests/cli/peertube.ts')
-rw-r--r-- | server/tests/cli/peertube.ts | 163 |
1 files changed, 63 insertions, 100 deletions
diff --git a/server/tests/cli/peertube.ts b/server/tests/cli/peertube.ts index fcf7e2e2e..f2a984962 100644 --- a/server/tests/cli/peertube.ts +++ b/server/tests/cli/peertube.ts | |||
@@ -2,97 +2,91 @@ | |||
2 | 2 | ||
3 | import 'mocha' | 3 | import 'mocha' |
4 | import { expect } from 'chai' | 4 | import { expect } from 'chai' |
5 | import { Video, VideoDetails } from '../../../shared' | ||
6 | import { | 5 | import { |
7 | addVideoChannel, | ||
8 | areHttpImportTestsDisabled, | 6 | areHttpImportTestsDisabled, |
9 | buildAbsoluteFixturePath, | 7 | buildAbsoluteFixturePath, |
10 | cleanupTests, | 8 | cleanupTests, |
11 | createUser, | 9 | CLICommand, |
10 | createSingleServer, | ||
12 | doubleFollow, | 11 | doubleFollow, |
13 | execCLI, | 12 | FIXTURE_URLS, |
14 | flushAndRunServer, | 13 | PeerTubeServer, |
15 | getEnvCli, | ||
16 | getLocalIdByUUID, | ||
17 | getVideo, | ||
18 | getVideosList, | ||
19 | removeVideo, | ||
20 | ServerInfo, | ||
21 | setAccessTokensToServers, | 14 | setAccessTokensToServers, |
22 | testHelloWorldRegisteredSettings, | 15 | testHelloWorldRegisteredSettings, |
23 | uploadVideoAndGetId, | ||
24 | userLogin, | ||
25 | waitJobs | 16 | waitJobs |
26 | } from '../../../shared/extra-utils' | 17 | } from '../../../shared/extra-utils' |
27 | import { getYoutubeVideoUrl } from '../../../shared/extra-utils/videos/video-imports' | ||
28 | 18 | ||
29 | describe('Test CLI wrapper', function () { | 19 | describe('Test CLI wrapper', function () { |
30 | let server: ServerInfo | 20 | let server: PeerTubeServer |
31 | let userAccessToken: string | 21 | let userAccessToken: string |
32 | 22 | ||
23 | let cliCommand: CLICommand | ||
24 | |||
33 | const cmd = 'node ./dist/server/tools/peertube.js' | 25 | const cmd = 'node ./dist/server/tools/peertube.js' |
34 | 26 | ||
35 | before(async function () { | 27 | before(async function () { |
36 | this.timeout(30000) | 28 | this.timeout(30000) |
37 | 29 | ||
38 | server = await flushAndRunServer(1) | 30 | server = await createSingleServer(1) |
39 | await setAccessTokensToServers([ server ]) | 31 | await setAccessTokensToServers([ server ]) |
40 | 32 | ||
41 | await createUser({ url: server.url, accessToken: server.accessToken, username: 'user_1', password: 'super_password' }) | 33 | await server.users.create({ username: 'user_1', password: 'super_password' }) |
42 | 34 | ||
43 | userAccessToken = await userLogin(server, { username: 'user_1', password: 'super_password' }) | 35 | userAccessToken = await server.login.getAccessToken({ username: 'user_1', password: 'super_password' }) |
44 | 36 | ||
45 | { | 37 | { |
46 | const args = { name: 'user_channel', displayName: 'User channel', support: 'super support text' } | 38 | const attributes = { name: 'user_channel', displayName: 'User channel', support: 'super support text' } |
47 | await addVideoChannel(server.url, userAccessToken, args) | 39 | await server.channels.create({ token: userAccessToken, attributes }) |
48 | } | 40 | } |
41 | |||
42 | cliCommand = server.cli | ||
49 | }) | 43 | }) |
50 | 44 | ||
51 | describe('Authentication and instance selection', function () { | 45 | describe('Authentication and instance selection', function () { |
52 | 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 | |||
53 | it('Should display no selected instance', async function () { | 55 | it('Should display no selected instance', async function () { |
54 | this.timeout(60000) | 56 | this.timeout(60000) |
55 | 57 | ||
56 | const env = getEnvCli(server) | 58 | const stdout = await cliCommand.execWithEnv(`${cmd} --help`) |
57 | const stdout = await execCLI(`${env} ${cmd} --help`) | ||
58 | |||
59 | expect(stdout).to.contain('no instance selected') | 59 | expect(stdout).to.contain('no instance selected') |
60 | }) | 60 | }) |
61 | 61 | ||
62 | it('Should add a user', async function () { | 62 | it('Should add a user', async function () { |
63 | this.timeout(60000) | 63 | this.timeout(60000) |
64 | 64 | ||
65 | const env = getEnvCli(server) | 65 | await cliCommand.execWithEnv(`${cmd} auth add -u ${server.url} -U user_1 -p super_password`) |
66 | await execCLI(`${env} ${cmd} auth add -u ${server.url} -U user_1 -p super_password`) | ||
67 | }) | 66 | }) |
68 | 67 | ||
69 | it('Should not fail to add a user if there is a slash at the end of the instance URL', async function () { | 68 | it('Should not fail to add a user if there is a slash at the end of the instance URL', async function () { |
70 | this.timeout(60000) | 69 | this.timeout(60000) |
71 | 70 | ||
72 | const env = getEnvCli(server) | 71 | let fullServerURL = server.url + '/' |
73 | let fullServerURL | 72 | |
74 | fullServerURL = server.url + '/' | 73 | await cliCommand.execWithEnv(`${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`) |
75 | await execCLI(`${env} ${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`) | ||
76 | 74 | ||
77 | fullServerURL = server.url + '/asdfasdf' | 75 | fullServerURL = server.url + '/asdfasdf' |
78 | await execCLI(`${env} ${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`) | 76 | await cliCommand.execWithEnv(`${cmd} auth add -u ${fullServerURL} -U user_1 -p super_password`) |
79 | }) | 77 | }) |
80 | 78 | ||
81 | it('Should default to this user', async function () { | 79 | it('Should default to this user', async function () { |
82 | this.timeout(60000) | 80 | this.timeout(60000) |
83 | 81 | ||
84 | const env = getEnvCli(server) | 82 | const stdout = await cliCommand.execWithEnv(`${cmd} --help`) |
85 | const stdout = await execCLI(`${env} ${cmd} --help`) | ||
86 | |||
87 | expect(stdout).to.contain(`instance ${server.url} selected`) | 83 | expect(stdout).to.contain(`instance ${server.url} selected`) |
88 | }) | 84 | }) |
89 | 85 | ||
90 | it('Should remember the user', async function () { | 86 | it('Should remember the user', async function () { |
91 | this.timeout(60000) | 87 | this.timeout(60000) |
92 | 88 | ||
93 | const env = getEnvCli(server) | 89 | const stdout = await cliCommand.execWithEnv(`${cmd} auth list`) |
94 | const stdout = await execCLI(`${env} ${cmd} auth list`) | ||
95 | |||
96 | expect(stdout).to.contain(server.url) | 90 | expect(stdout).to.contain(server.url) |
97 | }) | 91 | }) |
98 | }) | 92 | }) |
@@ -102,24 +96,17 @@ describe('Test CLI wrapper', function () { | |||
102 | it('Should upload a video', async function () { | 96 | it('Should upload a video', async function () { |
103 | this.timeout(60000) | 97 | this.timeout(60000) |
104 | 98 | ||
105 | const env = getEnvCli(server) | ||
106 | |||
107 | const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4') | 99 | const fixture = buildAbsoluteFixturePath('60fps_720p_small.mp4') |
108 | |||
109 | const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'` | 100 | const params = `-f ${fixture} --video-name 'test upload' --channel-name user_channel --support 'support_text'` |
110 | 101 | ||
111 | await execCLI(`${env} ${cmd} upload ${params}`) | 102 | await cliCommand.execWithEnv(`${cmd} upload ${params}`) |
112 | }) | 103 | }) |
113 | 104 | ||
114 | it('Should have the video uploaded', async function () { | 105 | it('Should have the video uploaded', async function () { |
115 | const res = await getVideosList(server.url) | 106 | const { total, data } = await server.videos.list() |
116 | 107 | expect(total).to.equal(1) | |
117 | expect(res.body.total).to.equal(1) | ||
118 | |||
119 | const videos: Video[] = res.body.data | ||
120 | |||
121 | const video: VideoDetails = (await getVideo(server.url, videos[0].uuid)).body | ||
122 | 108 | ||
109 | const video = await server.videos.get({ id: data[0].uuid }) | ||
123 | expect(video.name).to.equal('test upload') | 110 | expect(video.name).to.equal('test upload') |
124 | expect(video.support).to.equal('support_text') | 111 | expect(video.support).to.equal('support_text') |
125 | expect(video.channel.name).to.equal('user_channel') | 112 | expect(video.channel.name).to.equal('user_channel') |
@@ -130,11 +117,8 @@ describe('Test CLI wrapper', function () { | |||
130 | 117 | ||
131 | this.timeout(60000) | 118 | this.timeout(60000) |
132 | 119 | ||
133 | const env = getEnvCli(server) | 120 | const params = `--target-url ${FIXTURE_URLS.youtube} --channel-name user_channel` |
134 | 121 | await cliCommand.execWithEnv(`${cmd} import ${params}`) | |
135 | const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel` | ||
136 | |||
137 | await execCLI(`${env} ${cmd} import ${params}`) | ||
138 | }) | 122 | }) |
139 | 123 | ||
140 | it('Should have imported the video', async function () { | 124 | it('Should have imported the video', async function () { |
@@ -144,21 +128,19 @@ describe('Test CLI wrapper', function () { | |||
144 | 128 | ||
145 | await waitJobs([ server ]) | 129 | await waitJobs([ server ]) |
146 | 130 | ||
147 | const res = await getVideosList(server.url) | 131 | const { total, data } = await server.videos.list() |
148 | 132 | expect(total).to.equal(2) | |
149 | expect(res.body.total).to.equal(2) | ||
150 | 133 | ||
151 | const videos: Video[] = res.body.data | 134 | const video = data.find(v => v.name === 'small video - youtube') |
152 | const video = videos.find(v => v.name === 'small video - youtube') | ||
153 | expect(video).to.not.be.undefined | 135 | expect(video).to.not.be.undefined |
154 | 136 | ||
155 | const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body | 137 | const videoDetails = await server.videos.get({ id: video.id }) |
156 | expect(videoDetails.channel.name).to.equal('user_channel') | 138 | expect(videoDetails.channel.name).to.equal('user_channel') |
157 | expect(videoDetails.support).to.equal('super support text') | 139 | expect(videoDetails.support).to.equal('super support text') |
158 | expect(videoDetails.nsfw).to.be.false | 140 | expect(videoDetails.nsfw).to.be.false |
159 | 141 | ||
160 | // So we can reimport it | 142 | // So we can reimport it |
161 | await removeVideo(server.url, userAccessToken, video.id) | 143 | await server.videos.remove({ token: userAccessToken, id: video.id }) |
162 | }) | 144 | }) |
163 | 145 | ||
164 | it('Should import and override some imported attributes', async function () { | 146 | it('Should import and override some imported attributes', async function () { |
@@ -166,23 +148,20 @@ describe('Test CLI wrapper', function () { | |||
166 | 148 | ||
167 | this.timeout(60000) | 149 | this.timeout(60000) |
168 | 150 | ||
169 | const env = getEnvCli(server) | 151 | const params = `--target-url ${FIXTURE_URLS.youtube} ` + |
170 | 152 | `--channel-name user_channel --video-name toto --nsfw --support support` | |
171 | const params = `--target-url ${getYoutubeVideoUrl()} --channel-name user_channel --video-name toto --nsfw --support support` | 153 | await cliCommand.execWithEnv(`${cmd} import ${params}`) |
172 | |||
173 | await execCLI(`${env} ${cmd} import ${params}`) | ||
174 | 154 | ||
175 | await waitJobs([ server ]) | 155 | await waitJobs([ server ]) |
176 | 156 | ||
177 | { | 157 | { |
178 | const res = await getVideosList(server.url) | 158 | const { total, data } = await server.videos.list() |
179 | expect(res.body.total).to.equal(2) | 159 | expect(total).to.equal(2) |
180 | 160 | ||
181 | const videos: Video[] = res.body.data | 161 | const video = data.find(v => v.name === 'toto') |
182 | const video = videos.find(v => v.name === 'toto') | ||
183 | expect(video).to.not.be.undefined | 162 | expect(video).to.not.be.undefined |
184 | 163 | ||
185 | const videoDetails: VideoDetails = (await getVideo(server.url, video.id)).body | 164 | const videoDetails = await server.videos.get({ id: video.id }) |
186 | expect(videoDetails.channel.name).to.equal('user_channel') | 165 | expect(videoDetails.channel.name).to.equal('user_channel') |
187 | expect(videoDetails.support).to.equal('support') | 166 | expect(videoDetails.support).to.equal('support') |
188 | expect(videoDetails.nsfw).to.be.true | 167 | expect(videoDetails.nsfw).to.be.true |
@@ -194,18 +173,14 @@ describe('Test CLI wrapper', function () { | |||
194 | describe('Admin auth', function () { | 173 | describe('Admin auth', function () { |
195 | 174 | ||
196 | it('Should remove the auth user', async function () { | 175 | it('Should remove the auth user', async function () { |
197 | const env = getEnvCli(server) | 176 | await cliCommand.execWithEnv(`${cmd} auth del ${server.url}`) |
198 | |||
199 | await execCLI(`${env} ${cmd} auth del ${server.url}`) | ||
200 | |||
201 | const stdout = await execCLI(`${env} ${cmd} --help`) | ||
202 | 177 | ||
178 | const stdout = await cliCommand.execWithEnv(`${cmd} --help`) | ||
203 | expect(stdout).to.contain('no instance selected') | 179 | expect(stdout).to.contain('no instance selected') |
204 | }) | 180 | }) |
205 | 181 | ||
206 | it('Should add the admin user', async function () { | 182 | it('Should add the admin user', async function () { |
207 | const env = getEnvCli(server) | 183 | await cliCommand.execWithEnv(`${cmd} auth add -u ${server.url} -U root -p test${server.internalServerNumber}`) |
208 | await execCLI(`${env} ${cmd} auth add -u ${server.url} -U root -p test${server.internalServerNumber}`) | ||
209 | }) | 184 | }) |
210 | }) | 185 | }) |
211 | 186 | ||
@@ -214,8 +189,7 @@ describe('Test CLI wrapper', function () { | |||
214 | it('Should install a plugin', async function () { | 189 | it('Should install a plugin', async function () { |
215 | this.timeout(60000) | 190 | this.timeout(60000) |
216 | 191 | ||
217 | const env = getEnvCli(server) | 192 | await cliCommand.execWithEnv(`${cmd} plugins install --npm-name peertube-plugin-hello-world`) |
218 | await execCLI(`${env} ${cmd} plugins install --npm-name peertube-plugin-hello-world`) | ||
219 | }) | 193 | }) |
220 | 194 | ||
221 | it('Should have registered settings', async function () { | 195 | it('Should have registered settings', async function () { |
@@ -223,29 +197,27 @@ describe('Test CLI wrapper', function () { | |||
223 | }) | 197 | }) |
224 | 198 | ||
225 | it('Should list installed plugins', async function () { | 199 | it('Should list installed plugins', async function () { |
226 | const env = getEnvCli(server) | 200 | const res = await cliCommand.execWithEnv(`${cmd} plugins list`) |
227 | const res = await execCLI(`${env} ${cmd} plugins list`) | ||
228 | 201 | ||
229 | expect(res).to.contain('peertube-plugin-hello-world') | 202 | expect(res).to.contain('peertube-plugin-hello-world') |
230 | }) | 203 | }) |
231 | 204 | ||
232 | it('Should uninstall the plugin', async function () { | 205 | it('Should uninstall the plugin', async function () { |
233 | const env = getEnvCli(server) | 206 | const res = await cliCommand.execWithEnv(`${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`) |
234 | const res = await execCLI(`${env} ${cmd} plugins uninstall --npm-name peertube-plugin-hello-world`) | ||
235 | 207 | ||
236 | expect(res).to.not.contain('peertube-plugin-hello-world') | 208 | expect(res).to.not.contain('peertube-plugin-hello-world') |
237 | }) | 209 | }) |
238 | }) | 210 | }) |
239 | 211 | ||
240 | describe('Manage video redundancies', function () { | 212 | describe('Manage video redundancies', function () { |
241 | let anotherServer: ServerInfo | 213 | let anotherServer: PeerTubeServer |
242 | let video1Server2: number | 214 | let video1Server2: number |
243 | let servers: ServerInfo[] | 215 | let servers: PeerTubeServer[] |
244 | 216 | ||
245 | before(async function () { | 217 | before(async function () { |
246 | this.timeout(120000) | 218 | this.timeout(120000) |
247 | 219 | ||
248 | anotherServer = await flushAndRunServer(2) | 220 | anotherServer = await createSingleServer(2) |
249 | await setAccessTokensToServers([ anotherServer ]) | 221 | await setAccessTokensToServers([ anotherServer ]) |
250 | 222 | ||
251 | await doubleFollow(server, anotherServer) | 223 | await doubleFollow(server, anotherServer) |
@@ -253,20 +225,17 @@ describe('Test CLI wrapper', function () { | |||
253 | servers = [ server, anotherServer ] | 225 | servers = [ server, anotherServer ] |
254 | await waitJobs(servers) | 226 | await waitJobs(servers) |
255 | 227 | ||
256 | const uuid = (await uploadVideoAndGetId({ server: anotherServer, videoName: 'super video' })).uuid | 228 | const { uuid } = await anotherServer.videos.quickUpload({ name: 'super video' }) |
257 | await waitJobs(servers) | 229 | await waitJobs(servers) |
258 | 230 | ||
259 | video1Server2 = await getLocalIdByUUID(server.url, uuid) | 231 | video1Server2 = await server.videos.getId({ uuid }) |
260 | }) | 232 | }) |
261 | 233 | ||
262 | it('Should add a redundancy', async function () { | 234 | it('Should add a redundancy', async function () { |
263 | this.timeout(60000) | 235 | this.timeout(60000) |
264 | 236 | ||
265 | const env = getEnvCli(server) | ||
266 | |||
267 | const params = `add --video ${video1Server2}` | 237 | const params = `add --video ${video1Server2}` |
268 | 238 | await cliCommand.execWithEnv(`${cmd} redundancy ${params}`) | |
269 | await execCLI(`${env} ${cmd} redundancy ${params}`) | ||
270 | 239 | ||
271 | await waitJobs(servers) | 240 | await waitJobs(servers) |
272 | }) | 241 | }) |
@@ -275,10 +244,8 @@ describe('Test CLI wrapper', function () { | |||
275 | this.timeout(60000) | 244 | this.timeout(60000) |
276 | 245 | ||
277 | { | 246 | { |
278 | const env = getEnvCli(server) | ||
279 | |||
280 | const params = 'list-my-redundancies' | 247 | const params = 'list-my-redundancies' |
281 | const stdout = await execCLI(`${env} ${cmd} redundancy ${params}`) | 248 | const stdout = await cliCommand.execWithEnv(`${cmd} redundancy ${params}`) |
282 | 249 | ||
283 | expect(stdout).to.contain('super video') | 250 | expect(stdout).to.contain('super video') |
284 | expect(stdout).to.contain(`localhost:${server.port}`) | 251 | expect(stdout).to.contain(`localhost:${server.port}`) |
@@ -288,18 +255,14 @@ describe('Test CLI wrapper', function () { | |||
288 | it('Should remove a redundancy', async function () { | 255 | it('Should remove a redundancy', async function () { |
289 | this.timeout(60000) | 256 | this.timeout(60000) |
290 | 257 | ||
291 | const env = getEnvCli(server) | ||
292 | |||
293 | const params = `remove --video ${video1Server2}` | 258 | const params = `remove --video ${video1Server2}` |
294 | 259 | await cliCommand.execWithEnv(`${cmd} redundancy ${params}`) | |
295 | await execCLI(`${env} ${cmd} redundancy ${params}`) | ||
296 | 260 | ||
297 | await waitJobs(servers) | 261 | await waitJobs(servers) |
298 | 262 | ||
299 | { | 263 | { |
300 | const env = getEnvCli(server) | ||
301 | const params = 'list-my-redundancies' | 264 | const params = 'list-my-redundancies' |
302 | const stdout = await execCLI(`${env} ${cmd} redundancy ${params}`) | 265 | const stdout = await cliCommand.execWithEnv(`${cmd} redundancy ${params}`) |
303 | 266 | ||
304 | expect(stdout).to.not.contain('super video') | 267 | expect(stdout).to.not.contain('super video') |
305 | } | 268 | } |