]>
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' | |
9c2e051c | 5 | import { HttpStatusCode } from '@shared/core-utils' |
9b474844 C |
6 | import { |
7 | cleanupTests, | |
9b474844 | 8 | flushAndRunServer, |
a1587156 | 9 | killallServers, |
ae2abfd3 | 10 | PluginsCommand, |
a1587156 | 11 | reRunServer, |
09071200 | 12 | ServerInfo, |
9b474844 | 13 | setAccessTokensToServers, |
353f8bc0 | 14 | testHelloWorldRegisteredSettings, |
6c5065a0 | 15 | wait |
428ccb8b | 16 | } from '@shared/extra-utils' |
7926c5f9 | 17 | import { PluginType } from '@shared/models' |
9b474844 C |
18 | |
19 | const expect = chai.expect | |
20 | ||
21 | describe('Test plugins', function () { | |
09071200 | 22 | let server: ServerInfo = null |
ae2abfd3 | 23 | let command: PluginsCommand |
9b474844 C |
24 | |
25 | before(async function () { | |
26 | this.timeout(30000) | |
27 | ||
09071200 C |
28 | const configOverride = { |
29 | plugins: { | |
30 | index: { check_latest_versions_interval: '5 seconds' } | |
31 | } | |
32 | } | |
33 | server = await flushAndRunServer(1, configOverride) | |
9b474844 | 34 | await setAccessTokensToServers([ server ]) |
a5461888 C |
35 | |
36 | command = server.pluginsCommand | |
09071200 C |
37 | }) |
38 | ||
39 | it('Should list and search available plugins and themes', async function () { | |
40 | this.timeout(30000) | |
9b474844 C |
41 | |
42 | { | |
ae2abfd3 | 43 | const body = await command.listAvailable({ |
09071200 C |
44 | count: 1, |
45 | start: 0, | |
46 | pluginType: PluginType.THEME, | |
47 | search: 'background-red' | |
48 | }) | |
49 | ||
ae2abfd3 C |
50 | expect(body.total).to.be.at.least(1) |
51 | expect(body.data).to.have.lengthOf(1) | |
9b474844 C |
52 | } |
53 | ||
54 | { | |
ae2abfd3 | 55 | const body1 = await command.listAvailable({ |
09071200 C |
56 | count: 2, |
57 | start: 0, | |
58 | sort: 'npmName' | |
59 | }) | |
ae2abfd3 | 60 | expect(body1.total).to.be.at.least(2) |
09071200 | 61 | |
ae2abfd3 | 62 | const data1 = body1.data |
09071200 C |
63 | expect(data1).to.have.lengthOf(2) |
64 | ||
ae2abfd3 | 65 | const body2 = await command.listAvailable({ |
09071200 C |
66 | count: 2, |
67 | start: 0, | |
68 | sort: '-npmName' | |
69 | }) | |
ae2abfd3 | 70 | expect(body2.total).to.be.at.least(2) |
09071200 | 71 | |
ae2abfd3 | 72 | const data2 = body2.data |
09071200 C |
73 | expect(data2).to.have.lengthOf(2) |
74 | ||
a1587156 | 75 | expect(data1[0].npmName).to.not.equal(data2[0].npmName) |
9b474844 | 76 | } |
9b474844 | 77 | |
09071200 | 78 | { |
ae2abfd3 | 79 | const body = await command.listAvailable({ |
09071200 C |
80 | count: 10, |
81 | start: 0, | |
82 | pluginType: PluginType.THEME, | |
83 | search: 'background-red', | |
84 | currentPeerTubeEngine: '1.0.0' | |
85 | }) | |
9b474844 | 86 | |
ae2abfd3 | 87 | const p = body.data.find(p => p.npmName === 'peertube-theme-background-red') |
09071200 C |
88 | expect(p).to.be.undefined |
89 | } | |
9b474844 C |
90 | }) |
91 | ||
9b474844 | 92 | it('Should install a plugin and a theme', async function () { |
09071200 C |
93 | this.timeout(30000) |
94 | ||
ae2abfd3 C |
95 | await command.install({ npmName: 'peertube-plugin-hello-world' }) |
96 | await command.install({ npmName: 'peertube-theme-background-red' }) | |
9b474844 C |
97 | }) |
98 | ||
9b474844 | 99 | it('Should have the plugin loaded in the configuration', async function () { |
65e6e260 | 100 | const config = await server.configCommand.getConfig() |
09071200 C |
101 | |
102 | const theme = config.theme.registered.find(r => r.name === 'background-red') | |
103 | expect(theme).to.not.be.undefined | |
104 | ||
105 | const plugin = config.plugin.registered.find(r => r.name === 'hello-world') | |
106 | expect(plugin).to.not.be.undefined | |
9b474844 C |
107 | }) |
108 | ||
109 | it('Should update the default theme in the configuration', async function () { | |
65e6e260 C |
110 | await server.configCommand.updateCustomSubConfig({ |
111 | newConfig: { | |
112 | theme: { default: 'background-red' } | |
113 | } | |
114 | }) | |
09071200 | 115 | |
65e6e260 | 116 | const config = await server.configCommand.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 () { |
7926c5f9 | 121 | await server.usersCommand.updateMe({ theme: 'background-red' }) |
09071200 | 122 | |
7926c5f9 C |
123 | const user = await server.usersCommand.getMyInfo() |
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 | ||
6c5065a0 | 190 | await server.serversCommand.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 | |
9293139f | 237 | await server.sqlCommand.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 ]) |
09071200 C |
248 | await reRunServer(server) |
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 () { | |
65e6e260 | 296 | const config = await server.configCommand.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 () { | |
7926c5f9 C |
308 | const user = await server.usersCommand.getMyInfo() |
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 ]) |
9c2e051c C |
329 | await reRunServer(server) |
330 | ||
331 | await check() | |
332 | }) | |
333 | ||
9b474844 C |
334 | after(async function () { |
335 | await cleanupTests([ server ]) | |
336 | }) | |
337 | }) |