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