]>
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' | |
c55e3d72 C |
5 | import { testHelloWorldRegisteredSettings } from '@server/tests/shared' |
6 | import { wait } from '@shared/core-utils' | |
7 | import { HttpStatusCode, PluginType } from '@shared/models' | |
9b474844 C |
8 | import { |
9 | cleanupTests, | |
254d3579 | 10 | createSingleServer, |
a1587156 | 11 | killallServers, |
254d3579 | 12 | PeerTubeServer, |
4c7e60bc | 13 | PluginsCommand, |
c55e3d72 | 14 | setAccessTokensToServers |
bf54587a | 15 | } from '@shared/server-commands' |
9b474844 C |
16 | |
17 | const expect = chai.expect | |
18 | ||
19 | describe('Test plugins', function () { | |
254d3579 | 20 | let server: PeerTubeServer = null |
ae2abfd3 | 21 | let command: PluginsCommand |
9b474844 C |
22 | |
23 | before(async function () { | |
24 | this.timeout(30000) | |
25 | ||
09071200 C |
26 | const configOverride = { |
27 | plugins: { | |
28 | index: { check_latest_versions_interval: '5 seconds' } | |
29 | } | |
30 | } | |
254d3579 | 31 | server = await createSingleServer(1, configOverride) |
9b474844 | 32 | await setAccessTokensToServers([ server ]) |
a5461888 | 33 | |
89d241a7 | 34 | command = server.plugins |
09071200 C |
35 | }) |
36 | ||
37 | it('Should list and search available plugins and themes', async function () { | |
38 | this.timeout(30000) | |
9b474844 C |
39 | |
40 | { | |
ae2abfd3 | 41 | const body = await command.listAvailable({ |
09071200 C |
42 | count: 1, |
43 | start: 0, | |
44 | pluginType: PluginType.THEME, | |
45 | search: 'background-red' | |
46 | }) | |
47 | ||
ae2abfd3 C |
48 | expect(body.total).to.be.at.least(1) |
49 | expect(body.data).to.have.lengthOf(1) | |
9b474844 C |
50 | } |
51 | ||
52 | { | |
ae2abfd3 | 53 | const body1 = await command.listAvailable({ |
09071200 C |
54 | count: 2, |
55 | start: 0, | |
56 | sort: 'npmName' | |
57 | }) | |
ae2abfd3 | 58 | expect(body1.total).to.be.at.least(2) |
09071200 | 59 | |
ae2abfd3 | 60 | const data1 = body1.data |
09071200 C |
61 | expect(data1).to.have.lengthOf(2) |
62 | ||
ae2abfd3 | 63 | const body2 = await command.listAvailable({ |
09071200 C |
64 | count: 2, |
65 | start: 0, | |
66 | sort: '-npmName' | |
67 | }) | |
ae2abfd3 | 68 | expect(body2.total).to.be.at.least(2) |
09071200 | 69 | |
ae2abfd3 | 70 | const data2 = body2.data |
09071200 C |
71 | expect(data2).to.have.lengthOf(2) |
72 | ||
a1587156 | 73 | expect(data1[0].npmName).to.not.equal(data2[0].npmName) |
9b474844 | 74 | } |
9b474844 | 75 | |
09071200 | 76 | { |
ae2abfd3 | 77 | const body = await command.listAvailable({ |
09071200 C |
78 | count: 10, |
79 | start: 0, | |
80 | pluginType: PluginType.THEME, | |
81 | search: 'background-red', | |
82 | currentPeerTubeEngine: '1.0.0' | |
83 | }) | |
9b474844 | 84 | |
ae2abfd3 | 85 | const p = body.data.find(p => p.npmName === 'peertube-theme-background-red') |
09071200 C |
86 | expect(p).to.be.undefined |
87 | } | |
9b474844 C |
88 | }) |
89 | ||
9b474844 | 90 | it('Should install a plugin and a theme', async function () { |
09071200 C |
91 | this.timeout(30000) |
92 | ||
ae2abfd3 C |
93 | await command.install({ npmName: 'peertube-plugin-hello-world' }) |
94 | await command.install({ npmName: 'peertube-theme-background-red' }) | |
9b474844 C |
95 | }) |
96 | ||
9b474844 | 97 | it('Should have the plugin loaded in the configuration', async function () { |
89d241a7 | 98 | const config = await server.config.getConfig() |
09071200 C |
99 | |
100 | const theme = config.theme.registered.find(r => r.name === 'background-red') | |
101 | expect(theme).to.not.be.undefined | |
fb3c9e2b | 102 | expect(theme.npmName).to.equal('peertube-theme-background-red') |
09071200 C |
103 | |
104 | const plugin = config.plugin.registered.find(r => r.name === 'hello-world') | |
105 | expect(plugin).to.not.be.undefined | |
fb3c9e2b | 106 | expect(plugin.npmName).to.equal('peertube-plugin-hello-world') |
9b474844 C |
107 | }) |
108 | ||
109 | it('Should update the default theme in the configuration', async function () { | |
89d241a7 | 110 | await server.config.updateCustomSubConfig({ |
65e6e260 C |
111 | newConfig: { |
112 | theme: { default: 'background-red' } | |
113 | } | |
114 | }) | |
09071200 | 115 | |
89d241a7 | 116 | const config = await server.config.getConfig() |
09071200 | 117 | expect(config.theme.default).to.equal('background-red') |
9b474844 C |
118 | }) |
119 | ||
09071200 | 120 | it('Should update my default theme', async function () { |
89d241a7 | 121 | await server.users.updateMe({ theme: 'background-red' }) |
09071200 | 122 | |
89d241a7 | 123 | const user = await server.users.getMyInfo() |
7926c5f9 | 124 | expect(user.theme).to.equal('background-red') |
9b474844 C |
125 | }) |
126 | ||
09071200 C |
127 | it('Should list plugins and themes', async function () { |
128 | { | |
ae2abfd3 | 129 | const body = await command.list({ |
09071200 C |
130 | count: 1, |
131 | start: 0, | |
132 | pluginType: PluginType.THEME | |
133 | }) | |
ae2abfd3 | 134 | expect(body.total).to.be.at.least(1) |
09071200 | 135 | |
ae2abfd3 | 136 | const data = body.data |
09071200 C |
137 | expect(data).to.have.lengthOf(1) |
138 | expect(data[0].name).to.equal('background-red') | |
139 | } | |
140 | ||
141 | { | |
dd0ebb71 | 142 | const { data } = await command.list({ |
09071200 C |
143 | count: 2, |
144 | start: 0, | |
145 | sort: 'name' | |
146 | }) | |
09071200 C |
147 | |
148 | expect(data[0].name).to.equal('background-red') | |
149 | expect(data[1].name).to.equal('hello-world') | |
150 | } | |
151 | ||
152 | { | |
ae2abfd3 | 153 | const body = await command.list({ |
09071200 C |
154 | count: 2, |
155 | start: 1, | |
156 | sort: 'name' | |
157 | }) | |
09071200 | 158 | |
ae2abfd3 | 159 | expect(body.data[0].name).to.equal('hello-world') |
09071200 | 160 | } |
9b474844 C |
161 | }) |
162 | ||
163 | it('Should get registered settings', async function () { | |
353f8bc0 | 164 | await testHelloWorldRegisteredSettings(server) |
9b474844 C |
165 | }) |
166 | ||
ba211e73 | 167 | it('Should get public settings', async function () { |
ae2abfd3 C |
168 | const body = await command.getPublicSettings({ npmName: 'peertube-plugin-hello-world' }) |
169 | const publicSettings = body.publicSettings | |
ba211e73 C |
170 | |
171 | expect(Object.keys(publicSettings)).to.have.lengthOf(1) | |
172 | expect(Object.keys(publicSettings)).to.deep.equal([ 'user-name' ]) | |
173 | expect(publicSettings['user-name']).to.be.null | |
174 | }) | |
175 | ||
9b474844 | 176 | it('Should update the settings', async function () { |
09071200 C |
177 | const settings = { |
178 | 'admin-name': 'Cid' | |
179 | } | |
180 | ||
ae2abfd3 | 181 | await command.updateSettings({ |
09071200 C |
182 | npmName: 'peertube-plugin-hello-world', |
183 | settings | |
184 | }) | |
185 | }) | |
186 | ||
a5896799 C |
187 | it('Should have watched settings changes', async function () { |
188 | this.timeout(10000) | |
189 | ||
89d241a7 | 190 | await server.servers.waitUntilLog('Settings changed!') |
a5896799 C |
191 | }) |
192 | ||
09071200 C |
193 | it('Should get a plugin and a theme', async function () { |
194 | { | |
ae2abfd3 | 195 | const plugin = await command.get({ npmName: 'peertube-plugin-hello-world' }) |
09071200 C |
196 | |
197 | expect(plugin.type).to.equal(PluginType.PLUGIN) | |
198 | expect(plugin.name).to.equal('hello-world') | |
199 | expect(plugin.description).to.exist | |
200 | expect(plugin.homepage).to.exist | |
201 | expect(plugin.uninstalled).to.be.false | |
202 | expect(plugin.enabled).to.be.true | |
203 | expect(plugin.description).to.exist | |
204 | expect(plugin.version).to.exist | |
205 | expect(plugin.peertubeEngine).to.exist | |
206 | expect(plugin.createdAt).to.exist | |
207 | ||
208 | expect(plugin.settings).to.not.be.undefined | |
209 | expect(plugin.settings['admin-name']).to.equal('Cid') | |
210 | } | |
211 | ||
212 | { | |
ae2abfd3 | 213 | const plugin = await command.get({ npmName: 'peertube-theme-background-red' }) |
9b474844 | 214 | |
09071200 C |
215 | expect(plugin.type).to.equal(PluginType.THEME) |
216 | expect(plugin.name).to.equal('background-red') | |
217 | expect(plugin.description).to.exist | |
218 | expect(plugin.homepage).to.exist | |
219 | expect(plugin.uninstalled).to.be.false | |
220 | expect(plugin.enabled).to.be.true | |
221 | expect(plugin.description).to.exist | |
222 | expect(plugin.version).to.exist | |
223 | expect(plugin.peertubeEngine).to.exist | |
224 | expect(plugin.createdAt).to.exist | |
225 | ||
226 | expect(plugin.settings).to.be.null | |
227 | } | |
9b474844 C |
228 | }) |
229 | ||
230 | it('Should update the plugin and the theme', async function () { | |
31a91119 | 231 | this.timeout(90000) |
09071200 C |
232 | |
233 | // Wait the scheduler that get the latest plugins versions | |
234 | await wait(6000) | |
235 | ||
236 | // Fake update our plugin version | |
89d241a7 | 237 | await server.sql.setPluginVersion('hello-world', '0.0.1') |
09071200 C |
238 | |
239 | // Fake update package.json | |
ae2abfd3 | 240 | const packageJSON = await command.getPackageJSON('peertube-plugin-hello-world') |
09071200 C |
241 | const oldVersion = packageJSON.version |
242 | ||
243 | packageJSON.version = '0.0.1' | |
ae2abfd3 | 244 | await command.updatePackageJSON('peertube-plugin-hello-world', packageJSON) |
09071200 C |
245 | |
246 | // Restart the server to take into account this change | |
9293139f | 247 | await killallServers([ server ]) |
254d3579 | 248 | await server.run() |
09071200 C |
249 | |
250 | { | |
ae2abfd3 | 251 | const body = await command.list({ pluginType: PluginType.PLUGIN }) |
09071200 | 252 | |
ae2abfd3 | 253 | const plugin = body.data[0] |
09071200 C |
254 | expect(plugin.version).to.equal('0.0.1') |
255 | expect(plugin.latestVersion).to.exist | |
256 | expect(plugin.latestVersion).to.not.equal('0.0.1') | |
257 | } | |
258 | ||
259 | { | |
ae2abfd3 | 260 | await command.update({ npmName: 'peertube-plugin-hello-world' }) |
09071200 | 261 | |
ae2abfd3 | 262 | const body = await command.list({ pluginType: PluginType.PLUGIN }) |
09071200 | 263 | |
ae2abfd3 | 264 | const plugin = body.data[0] |
09071200 C |
265 | expect(plugin.version).to.equal(oldVersion) |
266 | ||
ae2abfd3 | 267 | const updatedPackageJSON = await command.getPackageJSON('peertube-plugin-hello-world') |
09071200 C |
268 | expect(updatedPackageJSON.version).to.equal(oldVersion) |
269 | } | |
9b474844 C |
270 | }) |
271 | ||
272 | it('Should uninstall the plugin', async function () { | |
ae2abfd3 | 273 | await command.uninstall({ npmName: 'peertube-plugin-hello-world' }) |
09071200 | 274 | |
ae2abfd3 C |
275 | const body = await command.list({ pluginType: PluginType.PLUGIN }) |
276 | expect(body.total).to.equal(0) | |
277 | expect(body.data).to.have.lengthOf(0) | |
9b474844 C |
278 | }) |
279 | ||
9b474844 | 280 | it('Should list uninstalled plugins', async function () { |
ae2abfd3 C |
281 | const body = await command.list({ pluginType: PluginType.PLUGIN, uninstalled: true }) |
282 | expect(body.total).to.equal(1) | |
283 | expect(body.data).to.have.lengthOf(1) | |
09071200 | 284 | |
ae2abfd3 | 285 | const plugin = body.data[0] |
09071200 C |
286 | expect(plugin.name).to.equal('hello-world') |
287 | expect(plugin.enabled).to.be.false | |
288 | expect(plugin.uninstalled).to.be.true | |
9b474844 C |
289 | }) |
290 | ||
291 | it('Should uninstall the theme', async function () { | |
ae2abfd3 | 292 | await command.uninstall({ npmName: 'peertube-theme-background-red' }) |
9b474844 C |
293 | }) |
294 | ||
295 | it('Should have updated the configuration', async function () { | |
89d241a7 | 296 | const config = await server.config.getConfig() |
09071200 C |
297 | |
298 | expect(config.theme.default).to.equal('default') | |
299 | ||
300 | const theme = config.theme.registered.find(r => r.name === 'background-red') | |
301 | expect(theme).to.be.undefined | |
302 | ||
303 | const plugin = config.plugin.registered.find(r => r.name === 'hello-world') | |
304 | expect(plugin).to.be.undefined | |
305 | }) | |
306 | ||
307 | it('Should have updated the user theme', async function () { | |
89d241a7 | 308 | const user = await server.users.getMyInfo() |
7926c5f9 | 309 | expect(user.theme).to.equal('instance-default') |
9b474844 C |
310 | }) |
311 | ||
9c2e051c C |
312 | it('Should not install a broken plugin', async function () { |
313 | this.timeout(60000) | |
314 | ||
315 | async function check () { | |
ae2abfd3 C |
316 | const body = await command.list({ pluginType: PluginType.PLUGIN }) |
317 | const plugins = body.data | |
9c2e051c C |
318 | expect(plugins.find(p => p.name === 'test-broken')).to.not.exist |
319 | } | |
320 | ||
ae2abfd3 C |
321 | await command.install({ |
322 | path: PluginsCommand.getPluginTestPath('-broken'), | |
9c2e051c C |
323 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
324 | }) | |
325 | ||
326 | await check() | |
327 | ||
9293139f | 328 | await killallServers([ server ]) |
254d3579 | 329 | await server.run() |
9c2e051c C |
330 | |
331 | await check() | |
332 | }) | |
333 | ||
9b474844 C |
334 | after(async function () { |
335 | await cleanupTests([ server ]) | |
336 | }) | |
337 | }) |