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