]>
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 | 10 | getMyUserInformation, |
a1587156 | 11 | killallServers, |
ae2abfd3 | 12 | PluginsCommand, |
a1587156 | 13 | reRunServer, |
09071200 | 14 | ServerInfo, |
9b474844 | 15 | setAccessTokensToServers, |
a1587156 | 16 | setPluginVersion, |
353f8bc0 | 17 | testHelloWorldRegisteredSettings, |
a1587156 | 18 | updateMyUser, |
a5896799 | 19 | wait, |
1f5221fb | 20 | waitUntilLog |
428ccb8b | 21 | } from '@shared/extra-utils' |
65e6e260 | 22 | import { PluginType, User } from '@shared/models' |
9b474844 C |
23 | |
24 | const expect = chai.expect | |
25 | ||
26 | describe('Test plugins', function () { | |
09071200 | 27 | let server: ServerInfo = null |
ae2abfd3 | 28 | let command: PluginsCommand |
9b474844 C |
29 | |
30 | before(async function () { | |
31 | this.timeout(30000) | |
32 | ||
09071200 C |
33 | const configOverride = { |
34 | plugins: { | |
35 | index: { check_latest_versions_interval: '5 seconds' } | |
36 | } | |
37 | } | |
38 | server = await flushAndRunServer(1, configOverride) | |
9b474844 | 39 | await setAccessTokensToServers([ server ]) |
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 | { | |
ae2abfd3 | 149 | const body = await command.list({ |
09071200 C |
150 | count: 2, |
151 | start: 0, | |
152 | sort: 'name' | |
153 | }) | |
09071200 | 154 | |
ae2abfd3 | 155 | const data = body |
09071200 C |
156 | expect(data[0].name).to.equal('background-red') |
157 | expect(data[1].name).to.equal('hello-world') | |
158 | } | |
159 | ||
160 | { | |
ae2abfd3 | 161 | const body = await command.list({ |
09071200 C |
162 | count: 2, |
163 | start: 1, | |
164 | sort: 'name' | |
165 | }) | |
09071200 | 166 | |
ae2abfd3 | 167 | expect(body.data[0].name).to.equal('hello-world') |
09071200 | 168 | } |
9b474844 C |
169 | }) |
170 | ||
171 | it('Should get registered settings', async function () { | |
353f8bc0 | 172 | await testHelloWorldRegisteredSettings(server) |
9b474844 C |
173 | }) |
174 | ||
ba211e73 | 175 | it('Should get public settings', async function () { |
ae2abfd3 C |
176 | const body = await command.getPublicSettings({ npmName: 'peertube-plugin-hello-world' }) |
177 | const publicSettings = body.publicSettings | |
ba211e73 C |
178 | |
179 | expect(Object.keys(publicSettings)).to.have.lengthOf(1) | |
180 | expect(Object.keys(publicSettings)).to.deep.equal([ 'user-name' ]) | |
181 | expect(publicSettings['user-name']).to.be.null | |
182 | }) | |
183 | ||
9b474844 | 184 | it('Should update the settings', async function () { |
09071200 C |
185 | const settings = { |
186 | 'admin-name': 'Cid' | |
187 | } | |
188 | ||
ae2abfd3 | 189 | await command.updateSettings({ |
09071200 C |
190 | npmName: 'peertube-plugin-hello-world', |
191 | settings | |
192 | }) | |
193 | }) | |
194 | ||
a5896799 C |
195 | it('Should have watched settings changes', async function () { |
196 | this.timeout(10000) | |
197 | ||
198 | await waitUntilLog(server, 'Settings changed!') | |
199 | }) | |
200 | ||
09071200 C |
201 | it('Should get a plugin and a theme', async function () { |
202 | { | |
ae2abfd3 | 203 | const plugin = await command.get({ npmName: 'peertube-plugin-hello-world' }) |
09071200 C |
204 | |
205 | expect(plugin.type).to.equal(PluginType.PLUGIN) | |
206 | expect(plugin.name).to.equal('hello-world') | |
207 | expect(plugin.description).to.exist | |
208 | expect(plugin.homepage).to.exist | |
209 | expect(plugin.uninstalled).to.be.false | |
210 | expect(plugin.enabled).to.be.true | |
211 | expect(plugin.description).to.exist | |
212 | expect(plugin.version).to.exist | |
213 | expect(plugin.peertubeEngine).to.exist | |
214 | expect(plugin.createdAt).to.exist | |
215 | ||
216 | expect(plugin.settings).to.not.be.undefined | |
217 | expect(plugin.settings['admin-name']).to.equal('Cid') | |
218 | } | |
219 | ||
220 | { | |
ae2abfd3 | 221 | const plugin = await command.get({ npmName: 'peertube-theme-background-red' }) |
9b474844 | 222 | |
09071200 C |
223 | expect(plugin.type).to.equal(PluginType.THEME) |
224 | expect(plugin.name).to.equal('background-red') | |
225 | expect(plugin.description).to.exist | |
226 | expect(plugin.homepage).to.exist | |
227 | expect(plugin.uninstalled).to.be.false | |
228 | expect(plugin.enabled).to.be.true | |
229 | expect(plugin.description).to.exist | |
230 | expect(plugin.version).to.exist | |
231 | expect(plugin.peertubeEngine).to.exist | |
232 | expect(plugin.createdAt).to.exist | |
233 | ||
234 | expect(plugin.settings).to.be.null | |
235 | } | |
9b474844 C |
236 | }) |
237 | ||
238 | it('Should update the plugin and the theme', async function () { | |
31a91119 | 239 | this.timeout(90000) |
09071200 C |
240 | |
241 | // Wait the scheduler that get the latest plugins versions | |
242 | await wait(6000) | |
243 | ||
244 | // Fake update our plugin version | |
245 | await setPluginVersion(server.internalServerNumber, 'hello-world', '0.0.1') | |
246 | ||
247 | // Fake update package.json | |
ae2abfd3 | 248 | const packageJSON = await command.getPackageJSON('peertube-plugin-hello-world') |
09071200 C |
249 | const oldVersion = packageJSON.version |
250 | ||
251 | packageJSON.version = '0.0.1' | |
ae2abfd3 | 252 | await command.updatePackageJSON('peertube-plugin-hello-world', packageJSON) |
09071200 C |
253 | |
254 | // Restart the server to take into account this change | |
255 | killallServers([ server ]) | |
256 | await reRunServer(server) | |
257 | ||
258 | { | |
ae2abfd3 | 259 | const body = await command.list({ pluginType: PluginType.PLUGIN }) |
09071200 | 260 | |
ae2abfd3 | 261 | const plugin = body.data[0] |
09071200 C |
262 | expect(plugin.version).to.equal('0.0.1') |
263 | expect(plugin.latestVersion).to.exist | |
264 | expect(plugin.latestVersion).to.not.equal('0.0.1') | |
265 | } | |
266 | ||
267 | { | |
ae2abfd3 | 268 | await command.update({ npmName: 'peertube-plugin-hello-world' }) |
09071200 | 269 | |
ae2abfd3 | 270 | const body = await command.list({ pluginType: PluginType.PLUGIN }) |
09071200 | 271 | |
ae2abfd3 | 272 | const plugin = body.data[0] |
09071200 C |
273 | expect(plugin.version).to.equal(oldVersion) |
274 | ||
ae2abfd3 | 275 | const updatedPackageJSON = await command.getPackageJSON('peertube-plugin-hello-world') |
09071200 C |
276 | expect(updatedPackageJSON.version).to.equal(oldVersion) |
277 | } | |
9b474844 C |
278 | }) |
279 | ||
280 | it('Should uninstall the plugin', async function () { | |
ae2abfd3 | 281 | await command.uninstall({ npmName: 'peertube-plugin-hello-world' }) |
09071200 | 282 | |
ae2abfd3 C |
283 | const body = await command.list({ pluginType: PluginType.PLUGIN }) |
284 | expect(body.total).to.equal(0) | |
285 | expect(body.data).to.have.lengthOf(0) | |
9b474844 C |
286 | }) |
287 | ||
9b474844 | 288 | it('Should list uninstalled plugins', async function () { |
ae2abfd3 C |
289 | const body = await command.list({ pluginType: PluginType.PLUGIN, uninstalled: true }) |
290 | expect(body.total).to.equal(1) | |
291 | expect(body.data).to.have.lengthOf(1) | |
09071200 | 292 | |
ae2abfd3 | 293 | const plugin = body.data[0] |
09071200 C |
294 | expect(plugin.name).to.equal('hello-world') |
295 | expect(plugin.enabled).to.be.false | |
296 | expect(plugin.uninstalled).to.be.true | |
9b474844 C |
297 | }) |
298 | ||
299 | it('Should uninstall the theme', async function () { | |
ae2abfd3 | 300 | await command.uninstall({ npmName: 'peertube-theme-background-red' }) |
9b474844 C |
301 | }) |
302 | ||
303 | it('Should have updated the configuration', async function () { | |
65e6e260 | 304 | const config = await server.configCommand.getConfig() |
09071200 C |
305 | |
306 | expect(config.theme.default).to.equal('default') | |
307 | ||
308 | const theme = config.theme.registered.find(r => r.name === 'background-red') | |
309 | expect(theme).to.be.undefined | |
310 | ||
311 | const plugin = config.plugin.registered.find(r => r.name === 'hello-world') | |
312 | expect(plugin).to.be.undefined | |
313 | }) | |
314 | ||
315 | it('Should have updated the user theme', async function () { | |
316 | const res = await getMyUserInformation(server.url, server.accessToken) | |
317 | expect((res.body as User).theme).to.equal('instance-default') | |
9b474844 C |
318 | }) |
319 | ||
9c2e051c C |
320 | it('Should not install a broken plugin', async function () { |
321 | this.timeout(60000) | |
322 | ||
323 | async function check () { | |
ae2abfd3 C |
324 | const body = await command.list({ pluginType: PluginType.PLUGIN }) |
325 | const plugins = body.data | |
9c2e051c C |
326 | expect(plugins.find(p => p.name === 'test-broken')).to.not.exist |
327 | } | |
328 | ||
ae2abfd3 C |
329 | await command.install({ |
330 | path: PluginsCommand.getPluginTestPath('-broken'), | |
9c2e051c C |
331 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 |
332 | }) | |
333 | ||
334 | await check() | |
335 | ||
336 | killallServers([ server ]) | |
337 | await reRunServer(server) | |
338 | ||
339 | await check() | |
340 | }) | |
341 | ||
9b474844 | 342 | after(async function () { |
09071200 | 343 | await closeAllSequelize([ server ]) |
9b474844 C |
344 | await cleanupTests([ server ]) |
345 | }) | |
346 | }) |