aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-19 14:36:04 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-07-24 10:58:16 +0200
commit09071200c73f5358e1d0bfb61a274e4f2c4ec52b (patch)
tree602749b149df1675518846dd223105196b19a557 /server/tests/api
parent9b474844e85cce916370693cc24f53339a695570 (diff)
downloadPeerTube-09071200c73f5358e1d0bfb61a274e4f2c4ec52b.tar.gz
PeerTube-09071200c73f5358e1d0bfb61a274e4f2c4ec52b.tar.zst
PeerTube-09071200c73f5358e1d0bfb61a274e4f2c4ec52b.zip
Add plugin API tests
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/check-params/plugins.ts14
-rw-r--r--server/tests/api/server/plugins.ts389
2 files changed, 351 insertions, 52 deletions
diff --git a/server/tests/api/check-params/plugins.ts b/server/tests/api/check-params/plugins.ts
index dd03766c9..83ce6f451 100644
--- a/server/tests/api/check-params/plugins.ts
+++ b/server/tests/api/check-params/plugins.ts
@@ -152,7 +152,8 @@ describe('Test server plugins API validators', function () {
152 const path = '/api/v1/plugins/available' 152 const path = '/api/v1/plugins/available'
153 const baseQuery = { 153 const baseQuery = {
154 search: 'super search', 154 search: 'super search',
155 pluginType: PluginType.PLUGIN 155 pluginType: PluginType.PLUGIN,
156 currentPeerTubeEngine: '1.2.3'
156 } 157 }
157 158
158 it('Should fail with an invalid token', async function () { 159 it('Should fail with an invalid token', async function () {
@@ -198,6 +199,17 @@ describe('Test server plugins API validators', function () {
198 }) 199 })
199 }) 200 })
200 201
202 it('Should fail with an invalid current peertube engine', async function () {
203 const query = immutableAssign(baseQuery, { currentPeerTubeEngine: '1.0' })
204
205 await makeGetRequest({
206 url: server.url,
207 path,
208 token: server.accessToken,
209 query
210 })
211 })
212
201 it('Should success with the correct parameters', async function () { 213 it('Should success with the correct parameters', async function () {
202 await makeGetRequest({ 214 await makeGetRequest({
203 url: server.url, 215 url: server.url,
diff --git a/server/tests/api/server/plugins.ts b/server/tests/api/server/plugins.ts
index 9a623c553..b3d003f45 100644
--- a/server/tests/api/server/plugins.ts
+++ b/server/tests/api/server/plugins.ts
@@ -2,129 +2,416 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { About } from '../../../../shared/models/server/about.model'
6import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
7import { 5import {
8 cleanupTests, 6 cleanupTests,
9 deleteCustomConfig, 7 closeAllSequelize,
10 flushAndRunServer, 8 flushAndRunServer,
11 getAbout, 9 getConfig, getMyUserInformation, getPluginPackageJSON,
12 getConfig, 10 getPlugin,
13 getCustomConfig, installPlugin, 11 getPluginRegisteredSettings,
14 killallServers, parallelTests, 12 getPluginsCSS,
15 registerUser, 13 installPlugin, killallServers,
16 reRunServer, ServerInfo, 14 listAvailablePlugins,
15 listPlugins, reRunServer,
16 ServerInfo,
17 setAccessTokensToServers, 17 setAccessTokensToServers,
18 updateCustomConfig, uploadVideo 18 setPluginVersion, uninstallPlugin,
19 updateCustomSubConfig, updateMyUser, updatePluginPackageJSON, updatePlugin,
20 updatePluginSettings,
21 wait
19} from '../../../../shared/extra-utils' 22} from '../../../../shared/extra-utils'
20import { ServerConfig } from '../../../../shared/models' 23import { PluginType } from '../../../../shared/models/plugins/plugin.type'
24import { PeerTubePluginIndex } from '../../../../shared/models/plugins/peertube-plugin-index.model'
25import { ServerConfig } from '../../../../shared/models/server'
26import { RegisteredSettings } from '../../../../shared/models/plugins/register-setting.model'
21import { PeerTubePlugin } from '../../../../shared/models/plugins/peertube-plugin.model' 27import { PeerTubePlugin } from '../../../../shared/models/plugins/peertube-plugin.model'
28import { User } from '../../../../shared/models/users'
29import { PluginPackageJson } from '../../../../shared/models/plugins/plugin-package-json.model'
22 30
23const expect = chai.expect 31const expect = chai.expect
24 32
25describe('Test plugins', function () { 33describe('Test plugins', function () {
26 let server = null 34 let server: ServerInfo = null
27 35
28 before(async function () { 36 before(async function () {
29 this.timeout(30000) 37 this.timeout(30000)
30 38
31 server = await flushAndRunServer(1) 39 const configOverride = {
40 plugins: {
41 index: { check_latest_versions_interval: '5 seconds' }
42 }
43 }
44 server = await flushAndRunServer(1, configOverride)
32 await setAccessTokensToServers([ server ]) 45 await setAccessTokensToServers([ server ])
46 })
47
48 it('Should list and search available plugins and themes', async function () {
49 this.timeout(30000)
33 50
34 { 51 {
35 await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-hello-world' }) 52 const res = await listAvailablePlugins({
53 url: server.url,
54 accessToken: server.accessToken,
55 count: 1,
56 start: 0,
57 pluginType: PluginType.THEME,
58 search: 'background-red'
59 })
60
61 expect(res.body.total).to.be.at.least(1)
62 expect(res.body.data).to.have.lengthOf(1)
36 } 63 }
37 64
38 { 65 {
39 await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-background-color' }) 66 const res1 = await listAvailablePlugins({
67 url: server.url,
68 accessToken: server.accessToken,
69 count: 2,
70 start: 0,
71 sort: 'npmName'
72 })
73 const data1: PeerTubePluginIndex[] = res1.body.data
74
75 expect(res1.body.total).to.be.at.least(2)
76 expect(data1).to.have.lengthOf(2)
77
78 const res2 = await listAvailablePlugins({
79 url: server.url,
80 accessToken: server.accessToken,
81 count: 2,
82 start: 0,
83 sort: '-npmName'
84 })
85 const data2: PeerTubePluginIndex[] = res2.body.data
86
87 expect(res2.body.total).to.be.at.least(2)
88 expect(data2).to.have.lengthOf(2)
89
90 expect(data1[0].npmName).to.not.equal(data2[ 0 ].npmName)
40 } 91 }
41 })
42 92
43 it('Should list available plugins and themes', async function () { 93 {
44 // List without filter 94 const res = await listAvailablePlugins({
45 // List with filter (plugin and theme) 95 url: server.url,
46 }) 96 accessToken: server.accessToken,
97 count: 10,
98 start: 0,
99 pluginType: PluginType.THEME,
100 search: 'background-red',
101 currentPeerTubeEngine: '1.0.0'
102 })
103 const data: PeerTubePluginIndex[] = res.body.data
47 104
48 it('Should search available plugins', async function () { 105 const p = data.find(p => p.npmName === 'peertube-theme-background-red')
49 // Search with filter (plugin and theme) 106 expect(p).to.be.undefined
50 // Add pagination 107 }
51 // Add sort
52 // Add peertube engine
53 }) 108 })
54 109
55 it('Should have an empty global css', async function () { 110 it('Should have an empty global css', async function () {
56 // get /global.css 111 const res = await getPluginsCSS(server.url)
112
113 expect(res.text).to.be.empty
57 }) 114 })
58 115
59 it('Should install a plugin and a theme', async function () { 116 it('Should install a plugin and a theme', async function () {
117 this.timeout(30000)
118
119 await installPlugin({
120 url: server.url,
121 accessToken: server.accessToken,
122 npmName: 'peertube-plugin-hello-world'
123 })
60 124
125 await installPlugin({
126 url: server.url,
127 accessToken: server.accessToken,
128 npmName: 'peertube-theme-background-red'
129 })
61 }) 130 })
62 131
63 it('Should have the correct global css', async function () { 132 it('Should have the correct global css', async function () {
64 // get /global.css 133 const res = await getPluginsCSS(server.url)
134
135 expect(res.text).to.contain('--mainBackgroundColor')
65 }) 136 })
66 137
67 it('Should have the plugin loaded in the configuration', async function () { 138 it('Should have the plugin loaded in the configuration', async function () {
68 // Check registered themes/plugins 139 const res = await getConfig(server.url)
140 const config: ServerConfig = res.body
141
142 const theme = config.theme.registered.find(r => r.name === 'background-red')
143 expect(theme).to.not.be.undefined
144
145 const plugin = config.plugin.registered.find(r => r.name === 'hello-world')
146 expect(plugin).to.not.be.undefined
69 }) 147 })
70 148
71 it('Should update the default theme in the configuration', async function () { 149 it('Should update the default theme in the configuration', async function () {
72 // Update config 150 await updateCustomSubConfig(server.url, server.accessToken, { theme: { default: 'background-red' } })
151
152 const res = await getConfig(server.url)
153 const config: ServerConfig = res.body
154
155 expect(config.theme.default).to.equal('background-red')
73 }) 156 })
74 157
75 it('Should list plugins and themes', async function () { 158 it('Should update my default theme', async function () {
76 // List without filter 159 await updateMyUser({
77 // List with filter (theme/plugin) 160 url: server.url,
78 // List with pagination 161 accessToken: server.accessToken,
79 // List with sort 162 theme: 'background-red'
163 })
164
165 const res = await getMyUserInformation(server.url, server.accessToken)
166 expect((res.body as User).theme).to.equal('background-red')
80 }) 167 })
81 168
82 it('Should get a plugin and a theme', async function () { 169 it('Should list plugins and themes', async function () {
83 // Get plugin 170 {
84 // Get theme 171 const res = await listPlugins({
172 url: server.url,
173 accessToken: server.accessToken,
174 count: 1,
175 start: 0,
176 pluginType: PluginType.THEME
177 })
178 const data: PeerTubePlugin[] = res.body.data
179
180 expect(res.body.total).to.be.at.least(1)
181 expect(data).to.have.lengthOf(1)
182 expect(data[0].name).to.equal('background-red')
183 }
184
185 {
186 const res = await listPlugins({
187 url: server.url,
188 accessToken: server.accessToken,
189 count: 2,
190 start: 0,
191 sort: 'name'
192 })
193 const data: PeerTubePlugin[] = res.body.data
194
195 expect(data[0].name).to.equal('background-red')
196 expect(data[1].name).to.equal('hello-world')
197 }
198
199 {
200 const res = await listPlugins({
201 url: server.url,
202 accessToken: server.accessToken,
203 count: 2,
204 start: 1,
205 sort: 'name'
206 })
207 const data: PeerTubePlugin[] = res.body.data
208
209 expect(data[0].name).to.equal('hello-world')
210 }
85 }) 211 })
86 212
87 it('Should get registered settings', async function () { 213 it('Should get registered settings', async function () {
88 // Get plugin 214 const res = await getPluginRegisteredSettings({
215 url: server.url,
216 accessToken: server.accessToken,
217 npmName: 'peertube-plugin-hello-world'
218 })
219
220 const settings = (res.body as RegisteredSettings).settings
221
222 expect(settings).to.have.length.at.least(1)
223
224 const adminNameSettings = settings.find(s => s.name === 'admin-name')
225 expect(adminNameSettings).to.not.be.undefined
89 }) 226 })
90 227
91 it('Should update the settings', async function () { 228 it('Should update the settings', async function () {
92 // Update /settings 229 const settings = {
230 'admin-name': 'Cid'
231 }
232
233 await updatePluginSettings({
234 url: server.url,
235 accessToken: server.accessToken,
236 npmName: 'peertube-plugin-hello-world',
237 settings
238 })
239 })
240
241 it('Should get a plugin and a theme', async function () {
242 {
243 const res = await getPlugin({
244 url: server.url,
245 accessToken: server.accessToken,
246 npmName: 'peertube-plugin-hello-world'
247 })
248
249 const plugin: PeerTubePlugin = res.body
250
251 expect(plugin.type).to.equal(PluginType.PLUGIN)
252 expect(plugin.name).to.equal('hello-world')
253 expect(plugin.description).to.exist
254 expect(plugin.homepage).to.exist
255 expect(plugin.uninstalled).to.be.false
256 expect(plugin.enabled).to.be.true
257 expect(plugin.description).to.exist
258 expect(plugin.version).to.exist
259 expect(plugin.peertubeEngine).to.exist
260 expect(plugin.createdAt).to.exist
261
262 expect(plugin.settings).to.not.be.undefined
263 expect(plugin.settings['admin-name']).to.equal('Cid')
264 }
265
266 {
267 const res = await getPlugin({
268 url: server.url,
269 accessToken: server.accessToken,
270 npmName: 'peertube-theme-background-red'
271 })
272
273 const plugin: PeerTubePlugin = res.body
93 274
94 // get /plugin 275 expect(plugin.type).to.equal(PluginType.THEME)
276 expect(plugin.name).to.equal('background-red')
277 expect(plugin.description).to.exist
278 expect(plugin.homepage).to.exist
279 expect(plugin.uninstalled).to.be.false
280 expect(plugin.enabled).to.be.true
281 expect(plugin.description).to.exist
282 expect(plugin.version).to.exist
283 expect(plugin.peertubeEngine).to.exist
284 expect(plugin.createdAt).to.exist
285
286 expect(plugin.settings).to.be.null
287 }
95 }) 288 })
96 289
97 it('Should update the plugin and the theme', async function () { 290 it('Should update the plugin and the theme', async function () {
98 // update BDD -> 0.0.1 291 this.timeout(30000)
99 // update package.json (theme + plugin) 292
100 // list to check versions 293 // Wait the scheduler that get the latest plugins versions
101 // update plugin + theme 294 await wait(6000)
102 // list to check they have been updated 295
103 // check package.json are upgraded too 296 // Fake update our plugin version
297 await setPluginVersion(server.internalServerNumber, 'hello-world', '0.0.1')
298
299 // Fake update package.json
300 const packageJSON: PluginPackageJson = await getPluginPackageJSON(server, 'peertube-plugin-hello-world')
301 const oldVersion = packageJSON.version
302
303 packageJSON.version = '0.0.1'
304 await updatePluginPackageJSON(server, 'peertube-plugin-hello-world', packageJSON)
305
306 // Restart the server to take into account this change
307 killallServers([ server ])
308 await reRunServer(server)
309
310 {
311 const res = await listPlugins({
312 url: server.url,
313 accessToken: server.accessToken,
314 pluginType: PluginType.PLUGIN
315 })
316
317 const plugin: PeerTubePlugin = res.body.data[0]
318
319 expect(plugin.version).to.equal('0.0.1')
320 expect(plugin.latestVersion).to.exist
321 expect(plugin.latestVersion).to.not.equal('0.0.1')
322 }
323
324 {
325 await updatePlugin({
326 url: server.url,
327 accessToken: server.accessToken,
328 npmName: 'peertube-plugin-hello-world'
329 })
330
331 const res = await listPlugins({
332 url: server.url,
333 accessToken: server.accessToken,
334 pluginType: PluginType.PLUGIN
335 })
336
337 const plugin: PeerTubePlugin = res.body.data[0]
338
339 expect(plugin.version).to.equal(oldVersion)
340
341 const updatedPackageJSON: PluginPackageJson = await getPluginPackageJSON(server, 'peertube-plugin-hello-world')
342 expect(updatedPackageJSON.version).to.equal(oldVersion)
343 }
104 }) 344 })
105 345
106 it('Should uninstall the plugin', async function () { 346 it('Should uninstall the plugin', async function () {
107 // uninstall 347 await uninstallPlugin({
108 // list 348 url: server.url,
349 accessToken: server.accessToken,
350 npmName: 'peertube-plugin-hello-world'
351 })
352
353 const res = await listPlugins({
354 url: server.url,
355 accessToken: server.accessToken,
356 pluginType: PluginType.PLUGIN
357 })
358
359 expect(res.body.total).to.equal(0)
360 expect(res.body.data).to.have.lengthOf(0)
109 }) 361 })
110 362
111 it('Should have an empty global css', async function () { 363 it('Should have an empty global css', async function () {
112 // get /global.css 364 const res = await getPluginsCSS(server.url)
365
366 expect(res.text).to.be.empty
113 }) 367 })
114 368
115 it('Should list uninstalled plugins', async function () { 369 it('Should list uninstalled plugins', async function () {
116 // { uninstalled: true } 370 const res = await listPlugins({
371 url: server.url,
372 accessToken: server.accessToken,
373 pluginType: PluginType.PLUGIN,
374 uninstalled: true
375 })
376
377 expect(res.body.total).to.equal(1)
378 expect(res.body.data).to.have.lengthOf(1)
379
380 const plugin: PeerTubePlugin = res.body.data[0]
381 expect(plugin.name).to.equal('hello-world')
382 expect(plugin.enabled).to.be.false
383 expect(plugin.uninstalled).to.be.true
117 }) 384 })
118 385
119 it('Should uninstall the theme', async function () { 386 it('Should uninstall the theme', async function () {
120 // Uninstall 387 await uninstallPlugin({
388 url: server.url,
389 accessToken: server.accessToken,
390 npmName: 'peertube-theme-background-red'
391 })
121 }) 392 })
122 393
123 it('Should have updated the configuration', async function () { 394 it('Should have updated the configuration', async function () {
124 // get /config (default theme + registered themes + registered plugins) 395 // get /config (default theme + registered themes + registered plugins)
396 const res = await getConfig(server.url)
397 const config: ServerConfig = res.body
398
399 expect(config.theme.default).to.equal('default')
400
401 const theme = config.theme.registered.find(r => r.name === 'background-red')
402 expect(theme).to.be.undefined
403
404 const plugin = config.plugin.registered.find(r => r.name === 'hello-world')
405 expect(plugin).to.be.undefined
406 })
407
408 it('Should have updated the user theme', async function () {
409 const res = await getMyUserInformation(server.url, server.accessToken)
410 expect((res.body as User).theme).to.equal('instance-default')
125 }) 411 })
126 412
127 after(async function () { 413 after(async function () {
414 await closeAllSequelize([ server ])
128 await cleanupTests([ server ]) 415 await cleanupTests([ server ])
129 }) 416 })
130}) 417})