]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
9b474844 C |
2 | |
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
9b474844 C |
5 | import { |
6 | cleanupTests, | |
09071200 | 7 | closeAllSequelize, |
9b474844 | 8 | flushAndRunServer, |
a1587156 C |
9 | getConfig, |
10 | getMyUserInformation, | |
09071200 | 11 | getPlugin, |
a1587156 | 12 | getPluginPackageJSON, |
09071200 C |
13 | getPluginRegisteredSettings, |
14 | getPluginsCSS, | |
a1587156 C |
15 | getPublicSettings, |
16 | installPlugin, | |
17 | killallServers, | |
09071200 | 18 | listAvailablePlugins, |
a1587156 C |
19 | listPlugins, |
20 | reRunServer, | |
09071200 | 21 | ServerInfo, |
9b474844 | 22 | setAccessTokensToServers, |
a1587156 C |
23 | setPluginVersion, |
24 | uninstallPlugin, | |
25 | updateCustomSubConfig, | |
26 | updateMyUser, | |
27 | updatePlugin, | |
28 | updatePluginPackageJSON, | |
09071200 | 29 | updatePluginSettings, |
a5896799 C |
30 | wait, |
31 | waitUntilLog | |
9b474844 | 32 | } from '../../../../shared/extra-utils' |
09071200 C |
33 | import { PluginType } from '../../../../shared/models/plugins/plugin.type' |
34 | import { PeerTubePluginIndex } from '../../../../shared/models/plugins/peertube-plugin-index.model' | |
35 | import { ServerConfig } from '../../../../shared/models/server' | |
9b474844 | 36 | import { PeerTubePlugin } from '../../../../shared/models/plugins/peertube-plugin.model' |
09071200 C |
37 | import { User } from '../../../../shared/models/users' |
38 | import { PluginPackageJson } from '../../../../shared/models/plugins/plugin-package-json.model' | |
9ae88819 | 39 | import { RegisteredServerSettings } from '../../../../shared/models/plugins/register-server-setting.model' |
ba211e73 | 40 | import { PublicServerSetting } from '../../../../shared/models/plugins/public-server.setting' |
9b474844 C |
41 | |
42 | const expect = chai.expect | |
43 | ||
44 | describe('Test plugins', function () { | |
09071200 | 45 | let server: ServerInfo = null |
9b474844 C |
46 | |
47 | before(async function () { | |
48 | this.timeout(30000) | |
49 | ||
09071200 C |
50 | const configOverride = { |
51 | plugins: { | |
52 | index: { check_latest_versions_interval: '5 seconds' } | |
53 | } | |
54 | } | |
55 | server = await flushAndRunServer(1, configOverride) | |
9b474844 | 56 | await setAccessTokensToServers([ server ]) |
09071200 C |
57 | }) |
58 | ||
59 | it('Should list and search available plugins and themes', async function () { | |
60 | this.timeout(30000) | |
9b474844 C |
61 | |
62 | { | |
09071200 C |
63 | const res = await listAvailablePlugins({ |
64 | url: server.url, | |
65 | accessToken: server.accessToken, | |
66 | count: 1, | |
67 | start: 0, | |
68 | pluginType: PluginType.THEME, | |
69 | search: 'background-red' | |
70 | }) | |
71 | ||
72 | expect(res.body.total).to.be.at.least(1) | |
73 | expect(res.body.data).to.have.lengthOf(1) | |
9b474844 C |
74 | } |
75 | ||
76 | { | |
09071200 C |
77 | const res1 = await listAvailablePlugins({ |
78 | url: server.url, | |
79 | accessToken: server.accessToken, | |
80 | count: 2, | |
81 | start: 0, | |
82 | sort: 'npmName' | |
83 | }) | |
84 | const data1: PeerTubePluginIndex[] = res1.body.data | |
85 | ||
86 | expect(res1.body.total).to.be.at.least(2) | |
87 | expect(data1).to.have.lengthOf(2) | |
88 | ||
89 | const res2 = await listAvailablePlugins({ | |
90 | url: server.url, | |
91 | accessToken: server.accessToken, | |
92 | count: 2, | |
93 | start: 0, | |
94 | sort: '-npmName' | |
95 | }) | |
96 | const data2: PeerTubePluginIndex[] = res2.body.data | |
97 | ||
98 | expect(res2.body.total).to.be.at.least(2) | |
99 | expect(data2).to.have.lengthOf(2) | |
100 | ||
a1587156 | 101 | expect(data1[0].npmName).to.not.equal(data2[0].npmName) |
9b474844 | 102 | } |
9b474844 | 103 | |
09071200 C |
104 | { |
105 | const res = await listAvailablePlugins({ | |
106 | url: server.url, | |
107 | accessToken: server.accessToken, | |
108 | count: 10, | |
109 | start: 0, | |
110 | pluginType: PluginType.THEME, | |
111 | search: 'background-red', | |
112 | currentPeerTubeEngine: '1.0.0' | |
113 | }) | |
114 | const data: PeerTubePluginIndex[] = res.body.data | |
9b474844 | 115 | |
09071200 C |
116 | const p = data.find(p => p.npmName === 'peertube-theme-background-red') |
117 | expect(p).to.be.undefined | |
118 | } | |
9b474844 C |
119 | }) |
120 | ||
121 | it('Should have an empty global css', async function () { | |
09071200 C |
122 | const res = await getPluginsCSS(server.url) |
123 | ||
124 | expect(res.text).to.be.empty | |
9b474844 C |
125 | }) |
126 | ||
127 | it('Should install a plugin and a theme', async function () { | |
09071200 C |
128 | this.timeout(30000) |
129 | ||
130 | await installPlugin({ | |
131 | url: server.url, | |
132 | accessToken: server.accessToken, | |
133 | npmName: 'peertube-plugin-hello-world' | |
134 | }) | |
9b474844 | 135 | |
09071200 C |
136 | await installPlugin({ |
137 | url: server.url, | |
138 | accessToken: server.accessToken, | |
139 | npmName: 'peertube-theme-background-red' | |
140 | }) | |
9b474844 C |
141 | }) |
142 | ||
143 | it('Should have the correct global css', async function () { | |
09071200 C |
144 | const res = await getPluginsCSS(server.url) |
145 | ||
a5896799 | 146 | expect(res.text).to.contain('background-color: red') |
9b474844 C |
147 | }) |
148 | ||
149 | it('Should have the plugin loaded in the configuration', async function () { | |
09071200 C |
150 | const res = await getConfig(server.url) |
151 | const config: ServerConfig = res.body | |
152 | ||
153 | const theme = config.theme.registered.find(r => r.name === 'background-red') | |
154 | expect(theme).to.not.be.undefined | |
155 | ||
156 | const plugin = config.plugin.registered.find(r => r.name === 'hello-world') | |
157 | expect(plugin).to.not.be.undefined | |
9b474844 C |
158 | }) |
159 | ||
160 | it('Should update the default theme in the configuration', async function () { | |
09071200 C |
161 | await updateCustomSubConfig(server.url, server.accessToken, { theme: { default: 'background-red' } }) |
162 | ||
163 | const res = await getConfig(server.url) | |
164 | const config: ServerConfig = res.body | |
165 | ||
166 | expect(config.theme.default).to.equal('background-red') | |
9b474844 C |
167 | }) |
168 | ||
09071200 C |
169 | it('Should update my default theme', async function () { |
170 | await updateMyUser({ | |
171 | url: server.url, | |
172 | accessToken: server.accessToken, | |
173 | theme: 'background-red' | |
174 | }) | |
175 | ||
176 | const res = await getMyUserInformation(server.url, server.accessToken) | |
177 | expect((res.body as User).theme).to.equal('background-red') | |
9b474844 C |
178 | }) |
179 | ||
09071200 C |
180 | it('Should list plugins and themes', async function () { |
181 | { | |
182 | const res = await listPlugins({ | |
183 | url: server.url, | |
184 | accessToken: server.accessToken, | |
185 | count: 1, | |
186 | start: 0, | |
187 | pluginType: PluginType.THEME | |
188 | }) | |
189 | const data: PeerTubePlugin[] = res.body.data | |
190 | ||
191 | expect(res.body.total).to.be.at.least(1) | |
192 | expect(data).to.have.lengthOf(1) | |
193 | expect(data[0].name).to.equal('background-red') | |
194 | } | |
195 | ||
196 | { | |
197 | const res = await listPlugins({ | |
198 | url: server.url, | |
199 | accessToken: server.accessToken, | |
200 | count: 2, | |
201 | start: 0, | |
202 | sort: 'name' | |
203 | }) | |
204 | const data: PeerTubePlugin[] = res.body.data | |
205 | ||
206 | expect(data[0].name).to.equal('background-red') | |
207 | expect(data[1].name).to.equal('hello-world') | |
208 | } | |
209 | ||
210 | { | |
211 | const res = await listPlugins({ | |
212 | url: server.url, | |
213 | accessToken: server.accessToken, | |
214 | count: 2, | |
215 | start: 1, | |
216 | sort: 'name' | |
217 | }) | |
218 | const data: PeerTubePlugin[] = res.body.data | |
219 | ||
220 | expect(data[0].name).to.equal('hello-world') | |
221 | } | |
9b474844 C |
222 | }) |
223 | ||
224 | it('Should get registered settings', async function () { | |
09071200 C |
225 | const res = await getPluginRegisteredSettings({ |
226 | url: server.url, | |
227 | accessToken: server.accessToken, | |
228 | npmName: 'peertube-plugin-hello-world' | |
229 | }) | |
230 | ||
ba211e73 | 231 | const registeredSettings = (res.body as RegisteredServerSettings).registeredSettings |
09071200 | 232 | |
ba211e73 | 233 | expect(registeredSettings).to.have.length.at.least(1) |
09071200 | 234 | |
ba211e73 | 235 | const adminNameSettings = registeredSettings.find(s => s.name === 'admin-name') |
09071200 | 236 | expect(adminNameSettings).to.not.be.undefined |
9b474844 C |
237 | }) |
238 | ||
ba211e73 C |
239 | it('Should get public settings', async function () { |
240 | const res = await getPublicSettings({ url: server.url, npmName: 'peertube-plugin-hello-world' }) | |
241 | ||
242 | const publicSettings = (res.body as PublicServerSetting).publicSettings | |
243 | ||
244 | expect(Object.keys(publicSettings)).to.have.lengthOf(1) | |
245 | expect(Object.keys(publicSettings)).to.deep.equal([ 'user-name' ]) | |
246 | expect(publicSettings['user-name']).to.be.null | |
247 | }) | |
248 | ||
9b474844 | 249 | it('Should update the settings', async function () { |
09071200 C |
250 | const settings = { |
251 | 'admin-name': 'Cid' | |
252 | } | |
253 | ||
254 | await updatePluginSettings({ | |
255 | url: server.url, | |
256 | accessToken: server.accessToken, | |
257 | npmName: 'peertube-plugin-hello-world', | |
258 | settings | |
259 | }) | |
260 | }) | |
261 | ||
a5896799 C |
262 | it('Should have watched settings changes', async function () { |
263 | this.timeout(10000) | |
264 | ||
265 | await waitUntilLog(server, 'Settings changed!') | |
266 | }) | |
267 | ||
09071200 C |
268 | it('Should get a plugin and a theme', async function () { |
269 | { | |
270 | const res = await getPlugin({ | |
271 | url: server.url, | |
272 | accessToken: server.accessToken, | |
273 | npmName: 'peertube-plugin-hello-world' | |
274 | }) | |
275 | ||
276 | const plugin: PeerTubePlugin = res.body | |
277 | ||
278 | expect(plugin.type).to.equal(PluginType.PLUGIN) | |
279 | expect(plugin.name).to.equal('hello-world') | |
280 | expect(plugin.description).to.exist | |
281 | expect(plugin.homepage).to.exist | |
282 | expect(plugin.uninstalled).to.be.false | |
283 | expect(plugin.enabled).to.be.true | |
284 | expect(plugin.description).to.exist | |
285 | expect(plugin.version).to.exist | |
286 | expect(plugin.peertubeEngine).to.exist | |
287 | expect(plugin.createdAt).to.exist | |
288 | ||
289 | expect(plugin.settings).to.not.be.undefined | |
290 | expect(plugin.settings['admin-name']).to.equal('Cid') | |
291 | } | |
292 | ||
293 | { | |
294 | const res = await getPlugin({ | |
295 | url: server.url, | |
296 | accessToken: server.accessToken, | |
297 | npmName: 'peertube-theme-background-red' | |
298 | }) | |
299 | ||
300 | const plugin: PeerTubePlugin = res.body | |
9b474844 | 301 | |
09071200 C |
302 | expect(plugin.type).to.equal(PluginType.THEME) |
303 | expect(plugin.name).to.equal('background-red') | |
304 | expect(plugin.description).to.exist | |
305 | expect(plugin.homepage).to.exist | |
306 | expect(plugin.uninstalled).to.be.false | |
307 | expect(plugin.enabled).to.be.true | |
308 | expect(plugin.description).to.exist | |
309 | expect(plugin.version).to.exist | |
310 | expect(plugin.peertubeEngine).to.exist | |
311 | expect(plugin.createdAt).to.exist | |
312 | ||
313 | expect(plugin.settings).to.be.null | |
314 | } | |
9b474844 C |
315 | }) |
316 | ||
317 | it('Should update the plugin and the theme', async function () { | |
09071200 C |
318 | this.timeout(30000) |
319 | ||
320 | // Wait the scheduler that get the latest plugins versions | |
321 | await wait(6000) | |
322 | ||
323 | // Fake update our plugin version | |
324 | await setPluginVersion(server.internalServerNumber, 'hello-world', '0.0.1') | |
325 | ||
326 | // Fake update package.json | |
327 | const packageJSON: PluginPackageJson = await getPluginPackageJSON(server, 'peertube-plugin-hello-world') | |
328 | const oldVersion = packageJSON.version | |
329 | ||
330 | packageJSON.version = '0.0.1' | |
331 | await updatePluginPackageJSON(server, 'peertube-plugin-hello-world', packageJSON) | |
332 | ||
333 | // Restart the server to take into account this change | |
334 | killallServers([ server ]) | |
335 | await reRunServer(server) | |
336 | ||
337 | { | |
338 | const res = await listPlugins({ | |
339 | url: server.url, | |
340 | accessToken: server.accessToken, | |
341 | pluginType: PluginType.PLUGIN | |
342 | }) | |
343 | ||
344 | const plugin: PeerTubePlugin = res.body.data[0] | |
345 | ||
346 | expect(plugin.version).to.equal('0.0.1') | |
347 | expect(plugin.latestVersion).to.exist | |
348 | expect(plugin.latestVersion).to.not.equal('0.0.1') | |
349 | } | |
350 | ||
351 | { | |
352 | await updatePlugin({ | |
353 | url: server.url, | |
354 | accessToken: server.accessToken, | |
355 | npmName: 'peertube-plugin-hello-world' | |
356 | }) | |
357 | ||
358 | const res = await listPlugins({ | |
359 | url: server.url, | |
360 | accessToken: server.accessToken, | |
361 | pluginType: PluginType.PLUGIN | |
362 | }) | |
363 | ||
364 | const plugin: PeerTubePlugin = res.body.data[0] | |
365 | ||
366 | expect(plugin.version).to.equal(oldVersion) | |
367 | ||
368 | const updatedPackageJSON: PluginPackageJson = await getPluginPackageJSON(server, 'peertube-plugin-hello-world') | |
369 | expect(updatedPackageJSON.version).to.equal(oldVersion) | |
370 | } | |
9b474844 C |
371 | }) |
372 | ||
373 | it('Should uninstall the plugin', async function () { | |
09071200 C |
374 | await uninstallPlugin({ |
375 | url: server.url, | |
376 | accessToken: server.accessToken, | |
377 | npmName: 'peertube-plugin-hello-world' | |
378 | }) | |
379 | ||
380 | const res = await listPlugins({ | |
381 | url: server.url, | |
382 | accessToken: server.accessToken, | |
383 | pluginType: PluginType.PLUGIN | |
384 | }) | |
385 | ||
386 | expect(res.body.total).to.equal(0) | |
387 | expect(res.body.data).to.have.lengthOf(0) | |
9b474844 C |
388 | }) |
389 | ||
390 | it('Should have an empty global css', async function () { | |
09071200 C |
391 | const res = await getPluginsCSS(server.url) |
392 | ||
393 | expect(res.text).to.be.empty | |
9b474844 C |
394 | }) |
395 | ||
396 | it('Should list uninstalled plugins', async function () { | |
09071200 C |
397 | const res = await listPlugins({ |
398 | url: server.url, | |
399 | accessToken: server.accessToken, | |
400 | pluginType: PluginType.PLUGIN, | |
401 | uninstalled: true | |
402 | }) | |
403 | ||
404 | expect(res.body.total).to.equal(1) | |
405 | expect(res.body.data).to.have.lengthOf(1) | |
406 | ||
407 | const plugin: PeerTubePlugin = res.body.data[0] | |
408 | expect(plugin.name).to.equal('hello-world') | |
409 | expect(plugin.enabled).to.be.false | |
410 | expect(plugin.uninstalled).to.be.true | |
9b474844 C |
411 | }) |
412 | ||
413 | it('Should uninstall the theme', async function () { | |
09071200 C |
414 | await uninstallPlugin({ |
415 | url: server.url, | |
416 | accessToken: server.accessToken, | |
417 | npmName: 'peertube-theme-background-red' | |
418 | }) | |
9b474844 C |
419 | }) |
420 | ||
421 | it('Should have updated the configuration', async function () { | |
422 | // get /config (default theme + registered themes + registered plugins) | |
09071200 C |
423 | const res = await getConfig(server.url) |
424 | const config: ServerConfig = res.body | |
425 | ||
426 | expect(config.theme.default).to.equal('default') | |
427 | ||
428 | const theme = config.theme.registered.find(r => r.name === 'background-red') | |
429 | expect(theme).to.be.undefined | |
430 | ||
431 | const plugin = config.plugin.registered.find(r => r.name === 'hello-world') | |
432 | expect(plugin).to.be.undefined | |
433 | }) | |
434 | ||
435 | it('Should have updated the user theme', async function () { | |
436 | const res = await getMyUserInformation(server.url, server.accessToken) | |
437 | expect((res.body as User).theme).to.equal('instance-default') | |
9b474844 C |
438 | }) |
439 | ||
440 | after(async function () { | |
09071200 | 441 | await closeAllSequelize([ server ]) |
9b474844 C |
442 | await cleanupTests([ server ]) |
443 | }) | |
444 | }) |