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