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