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