aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-07 10:33:49 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:17 +0200
commitae2abfd3aed3e75d39a316b49b914d187faa7475 (patch)
tree4d5060dc310f3d8cdcd5829779522f49b3d10e71 /server/tests/api
parent9c6327f803aaf4200672f1fc40b2f43786daca47 (diff)
downloadPeerTube-ae2abfd3aed3e75d39a316b49b914d187faa7475.tar.gz
PeerTube-ae2abfd3aed3e75d39a316b49b914d187faa7475.tar.zst
PeerTube-ae2abfd3aed3e75d39a316b49b914d187faa7475.zip
Introduce plugins command
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/check-params/plugins.ts5
-rw-r--r--server/tests/api/notifications/admin-notifications.ts31
-rw-r--r--server/tests/api/server/plugins.ts188
-rw-r--r--server/tests/api/users/users.ts3
4 files changed, 64 insertions, 163 deletions
diff --git a/server/tests/api/check-params/plugins.ts b/server/tests/api/check-params/plugins.ts
index a833fe6ff..d372221d0 100644
--- a/server/tests/api/check-params/plugins.ts
+++ b/server/tests/api/check-params/plugins.ts
@@ -10,7 +10,6 @@ import {
10 createUser, 10 createUser,
11 flushAndRunServer, 11 flushAndRunServer,
12 immutableAssign, 12 immutableAssign,
13 installPlugin,
14 makeGetRequest, 13 makeGetRequest,
15 makePostBodyRequest, 14 makePostBodyRequest,
16 makePutBodyRequest, 15 makePutBodyRequest,
@@ -50,13 +49,13 @@ describe('Test server plugins API validators', function () {
50 userAccessToken = await userLogin(server, user) 49 userAccessToken = await userLogin(server, user)
51 50
52 { 51 {
53 const res = await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: npmPlugin }) 52 const res = await server.pluginsCommand.install({ npmName: npmPlugin })
54 const plugin = res.body as PeerTubePlugin 53 const plugin = res.body as PeerTubePlugin
55 npmVersion = plugin.version 54 npmVersion = plugin.version
56 } 55 }
57 56
58 { 57 {
59 const res = await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: themePlugin }) 58 const res = await server.pluginsCommand.install({ npmName: themePlugin })
60 const plugin = res.body as PeerTubePlugin 59 const plugin = res.body as PeerTubePlugin
61 themeVersion = plugin.version 60 themeVersion = plugin.version
62 } 61 }
diff --git a/server/tests/api/notifications/admin-notifications.ts b/server/tests/api/notifications/admin-notifications.ts
index 91681c9d6..da9767b74 100644
--- a/server/tests/api/notifications/admin-notifications.ts
+++ b/server/tests/api/notifications/admin-notifications.ts
@@ -2,18 +2,20 @@
2 2
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { MockJoinPeerTubeVersions } from '@shared/extra-utils'
6import { PluginType } from '@shared/models'
7import { cleanupTests, installPlugin, setPluginLatestVersion, setPluginVersion, wait } from '../../../../shared/extra-utils'
8import { ServerInfo } from '../../../../shared/extra-utils/index'
9import { MockSmtpServer } from '../../../../shared/extra-utils/mock-servers/mock-email'
10import { 5import {
11 CheckerBaseParams, 6 CheckerBaseParams,
12 checkNewPeerTubeVersion, 7 checkNewPeerTubeVersion,
13 checkNewPluginVersion, 8 checkNewPluginVersion,
14 prepareNotificationsTest 9 cleanupTests,
15} from '../../../../shared/extra-utils/users/user-notifications' 10 MockJoinPeerTubeVersions,
16import { UserNotification, UserNotificationType } from '../../../../shared/models/users' 11 MockSmtpServer,
12 prepareNotificationsTest,
13 ServerInfo,
14 setPluginLatestVersion,
15 setPluginVersion,
16 wait
17} from '@shared/extra-utils'
18import { PluginType, UserNotification, UserNotificationType } from '@shared/models'
17 19
18describe('Test admin notifications', function () { 20describe('Test admin notifications', function () {
19 let server: ServerInfo 21 let server: ServerInfo
@@ -58,17 +60,8 @@ describe('Test admin notifications', function () {
58 token: server.accessToken 60 token: server.accessToken
59 } 61 }
60 62
61 await installPlugin({ 63 await server.pluginsCommand.install({ npmName: 'peertube-plugin-hello-world' })
62 url: server.url, 64 await server.pluginsCommand.install({ npmName: 'peertube-theme-background-red' })
63 accessToken: server.accessToken,
64 npmName: 'peertube-plugin-hello-world'
65 })
66
67 await installPlugin({
68 url: server.url,
69 accessToken: server.accessToken,
70 npmName: 'peertube-theme-background-red'
71 })
72 }) 65 })
73 66
74 describe('Latest PeerTube version notification', function () { 67 describe('Latest PeerTube version notification', function () {
diff --git a/server/tests/api/server/plugins.ts b/server/tests/api/server/plugins.ts
index 6b61c7c33..1536997d5 100644
--- a/server/tests/api/server/plugins.ts
+++ b/server/tests/api/server/plugins.ts
@@ -9,34 +9,25 @@ import {
9 flushAndRunServer, 9 flushAndRunServer,
10 getConfig, 10 getConfig,
11 getMyUserInformation, 11 getMyUserInformation,
12 getPlugin,
13 getPluginPackageJSON,
14 getPluginTestPath,
15 getPublicSettings,
16 installPlugin,
17 killallServers, 12 killallServers,
18 listAvailablePlugins, 13 PluginsCommand,
19 listPlugins,
20 reRunServer, 14 reRunServer,
21 ServerInfo, 15 ServerInfo,
22 setAccessTokensToServers, 16 setAccessTokensToServers,
23 setPluginVersion, 17 setPluginVersion,
24 testHelloWorldRegisteredSettings, 18 testHelloWorldRegisteredSettings,
25 uninstallPlugin,
26 updateCustomSubConfig, 19 updateCustomSubConfig,
27 updateMyUser, 20 updateMyUser,
28 updatePlugin,
29 updatePluginPackageJSON,
30 updatePluginSettings,
31 wait, 21 wait,
32 waitUntilLog 22 waitUntilLog
33} from '@shared/extra-utils' 23} from '@shared/extra-utils'
34import { PeerTubePlugin, PeerTubePluginIndex, PluginPackageJson, PluginType, PublicServerSetting, ServerConfig, User } from '@shared/models' 24import { PluginType, ServerConfig, User } from '@shared/models'
35 25
36const expect = chai.expect 26const expect = chai.expect
37 27
38describe('Test plugins', function () { 28describe('Test plugins', function () {
39 let server: ServerInfo = null 29 let server: ServerInfo = null
30 let command: PluginsCommand
40 31
41 before(async function () { 32 before(async function () {
42 this.timeout(30000) 33 this.timeout(30000)
@@ -54,60 +45,51 @@ describe('Test plugins', function () {
54 this.timeout(30000) 45 this.timeout(30000)
55 46
56 { 47 {
57 const res = await listAvailablePlugins({ 48 const body = await command.listAvailable({
58 url: server.url,
59 accessToken: server.accessToken,
60 count: 1, 49 count: 1,
61 start: 0, 50 start: 0,
62 pluginType: PluginType.THEME, 51 pluginType: PluginType.THEME,
63 search: 'background-red' 52 search: 'background-red'
64 }) 53 })
65 54
66 expect(res.body.total).to.be.at.least(1) 55 expect(body.total).to.be.at.least(1)
67 expect(res.body.data).to.have.lengthOf(1) 56 expect(body.data).to.have.lengthOf(1)
68 } 57 }
69 58
70 { 59 {
71 const res1 = await listAvailablePlugins({ 60 const body1 = await command.listAvailable({
72 url: server.url,
73 accessToken: server.accessToken,
74 count: 2, 61 count: 2,
75 start: 0, 62 start: 0,
76 sort: 'npmName' 63 sort: 'npmName'
77 }) 64 })
78 const data1: PeerTubePluginIndex[] = res1.body.data 65 expect(body1.total).to.be.at.least(2)
79 66
80 expect(res1.body.total).to.be.at.least(2) 67 const data1 = body1.data
81 expect(data1).to.have.lengthOf(2) 68 expect(data1).to.have.lengthOf(2)
82 69
83 const res2 = await listAvailablePlugins({ 70 const body2 = await command.listAvailable({
84 url: server.url,
85 accessToken: server.accessToken,
86 count: 2, 71 count: 2,
87 start: 0, 72 start: 0,
88 sort: '-npmName' 73 sort: '-npmName'
89 }) 74 })
90 const data2: PeerTubePluginIndex[] = res2.body.data 75 expect(body2.total).to.be.at.least(2)
91 76
92 expect(res2.body.total).to.be.at.least(2) 77 const data2 = body2.data
93 expect(data2).to.have.lengthOf(2) 78 expect(data2).to.have.lengthOf(2)
94 79
95 expect(data1[0].npmName).to.not.equal(data2[0].npmName) 80 expect(data1[0].npmName).to.not.equal(data2[0].npmName)
96 } 81 }
97 82
98 { 83 {
99 const res = await listAvailablePlugins({ 84 const body = await command.listAvailable({
100 url: server.url,
101 accessToken: server.accessToken,
102 count: 10, 85 count: 10,
103 start: 0, 86 start: 0,
104 pluginType: PluginType.THEME, 87 pluginType: PluginType.THEME,
105 search: 'background-red', 88 search: 'background-red',
106 currentPeerTubeEngine: '1.0.0' 89 currentPeerTubeEngine: '1.0.0'
107 }) 90 })
108 const data: PeerTubePluginIndex[] = res.body.data
109 91
110 const p = data.find(p => p.npmName === 'peertube-theme-background-red') 92 const p = body.data.find(p => p.npmName === 'peertube-theme-background-red')
111 expect(p).to.be.undefined 93 expect(p).to.be.undefined
112 } 94 }
113 }) 95 })
@@ -115,17 +97,8 @@ describe('Test plugins', function () {
115 it('Should install a plugin and a theme', async function () { 97 it('Should install a plugin and a theme', async function () {
116 this.timeout(30000) 98 this.timeout(30000)
117 99
118 await installPlugin({ 100 await command.install({ npmName: 'peertube-plugin-hello-world' })
119 url: server.url, 101 await command.install({ npmName: 'peertube-theme-background-red' })
120 accessToken: server.accessToken,
121 npmName: 'peertube-plugin-hello-world'
122 })
123
124 await installPlugin({
125 url: server.url,
126 accessToken: server.accessToken,
127 npmName: 'peertube-theme-background-red'
128 })
129 }) 102 })
130 103
131 it('Should have the plugin loaded in the configuration', async function () { 104 it('Should have the plugin loaded in the configuration', async function () {
@@ -161,45 +134,38 @@ describe('Test plugins', function () {
161 134
162 it('Should list plugins and themes', async function () { 135 it('Should list plugins and themes', async function () {
163 { 136 {
164 const res = await listPlugins({ 137 const body = await command.list({
165 url: server.url,
166 accessToken: server.accessToken,
167 count: 1, 138 count: 1,
168 start: 0, 139 start: 0,
169 pluginType: PluginType.THEME 140 pluginType: PluginType.THEME
170 }) 141 })
171 const data: PeerTubePlugin[] = res.body.data 142 expect(body.total).to.be.at.least(1)
172 143
173 expect(res.body.total).to.be.at.least(1) 144 const data = body.data
174 expect(data).to.have.lengthOf(1) 145 expect(data).to.have.lengthOf(1)
175 expect(data[0].name).to.equal('background-red') 146 expect(data[0].name).to.equal('background-red')
176 } 147 }
177 148
178 { 149 {
179 const res = await listPlugins({ 150 const body = await command.list({
180 url: server.url,
181 accessToken: server.accessToken,
182 count: 2, 151 count: 2,
183 start: 0, 152 start: 0,
184 sort: 'name' 153 sort: 'name'
185 }) 154 })
186 const data: PeerTubePlugin[] = res.body.data
187 155
156 const data = body
188 expect(data[0].name).to.equal('background-red') 157 expect(data[0].name).to.equal('background-red')
189 expect(data[1].name).to.equal('hello-world') 158 expect(data[1].name).to.equal('hello-world')
190 } 159 }
191 160
192 { 161 {
193 const res = await listPlugins({ 162 const body = await command.list({
194 url: server.url,
195 accessToken: server.accessToken,
196 count: 2, 163 count: 2,
197 start: 1, 164 start: 1,
198 sort: 'name' 165 sort: 'name'
199 }) 166 })
200 const data: PeerTubePlugin[] = res.body.data
201 167
202 expect(data[0].name).to.equal('hello-world') 168 expect(body.data[0].name).to.equal('hello-world')
203 } 169 }
204 }) 170 })
205 171
@@ -208,9 +174,8 @@ describe('Test plugins', function () {
208 }) 174 })
209 175
210 it('Should get public settings', async function () { 176 it('Should get public settings', async function () {
211 const res = await getPublicSettings({ url: server.url, npmName: 'peertube-plugin-hello-world' }) 177 const body = await command.getPublicSettings({ npmName: 'peertube-plugin-hello-world' })
212 178 const publicSettings = body.publicSettings
213 const publicSettings = (res.body as PublicServerSetting).publicSettings
214 179
215 expect(Object.keys(publicSettings)).to.have.lengthOf(1) 180 expect(Object.keys(publicSettings)).to.have.lengthOf(1)
216 expect(Object.keys(publicSettings)).to.deep.equal([ 'user-name' ]) 181 expect(Object.keys(publicSettings)).to.deep.equal([ 'user-name' ])
@@ -222,9 +187,7 @@ describe('Test plugins', function () {
222 'admin-name': 'Cid' 187 'admin-name': 'Cid'
223 } 188 }
224 189
225 await updatePluginSettings({ 190 await command.updateSettings({
226 url: server.url,
227 accessToken: server.accessToken,
228 npmName: 'peertube-plugin-hello-world', 191 npmName: 'peertube-plugin-hello-world',
229 settings 192 settings
230 }) 193 })
@@ -238,13 +201,7 @@ describe('Test plugins', function () {
238 201
239 it('Should get a plugin and a theme', async function () { 202 it('Should get a plugin and a theme', async function () {
240 { 203 {
241 const res = await getPlugin({ 204 const plugin = await command.get({ npmName: 'peertube-plugin-hello-world' })
242 url: server.url,
243 accessToken: server.accessToken,
244 npmName: 'peertube-plugin-hello-world'
245 })
246
247 const plugin: PeerTubePlugin = res.body
248 205
249 expect(plugin.type).to.equal(PluginType.PLUGIN) 206 expect(plugin.type).to.equal(PluginType.PLUGIN)
250 expect(plugin.name).to.equal('hello-world') 207 expect(plugin.name).to.equal('hello-world')
@@ -262,13 +219,7 @@ describe('Test plugins', function () {
262 } 219 }
263 220
264 { 221 {
265 const res = await getPlugin({ 222 const plugin = await command.get({ npmName: 'peertube-theme-background-red' })
266 url: server.url,
267 accessToken: server.accessToken,
268 npmName: 'peertube-theme-background-red'
269 })
270
271 const plugin: PeerTubePlugin = res.body
272 223
273 expect(plugin.type).to.equal(PluginType.THEME) 224 expect(plugin.type).to.equal(PluginType.THEME)
274 expect(plugin.name).to.equal('background-red') 225 expect(plugin.name).to.equal('background-red')
@@ -295,92 +246,59 @@ describe('Test plugins', function () {
295 await setPluginVersion(server.internalServerNumber, 'hello-world', '0.0.1') 246 await setPluginVersion(server.internalServerNumber, 'hello-world', '0.0.1')
296 247
297 // Fake update package.json 248 // Fake update package.json
298 const packageJSON: PluginPackageJson = await getPluginPackageJSON(server, 'peertube-plugin-hello-world') 249 const packageJSON = await command.getPackageJSON('peertube-plugin-hello-world')
299 const oldVersion = packageJSON.version 250 const oldVersion = packageJSON.version
300 251
301 packageJSON.version = '0.0.1' 252 packageJSON.version = '0.0.1'
302 await updatePluginPackageJSON(server, 'peertube-plugin-hello-world', packageJSON) 253 await command.updatePackageJSON('peertube-plugin-hello-world', packageJSON)
303 254
304 // Restart the server to take into account this change 255 // Restart the server to take into account this change
305 killallServers([ server ]) 256 killallServers([ server ])
306 await reRunServer(server) 257 await reRunServer(server)
307 258
308 { 259 {
309 const res = await listPlugins({ 260 const body = await command.list({ pluginType: PluginType.PLUGIN })
310 url: server.url,
311 accessToken: server.accessToken,
312 pluginType: PluginType.PLUGIN
313 })
314
315 const plugin: PeerTubePlugin = res.body.data[0]
316 261
262 const plugin = body.data[0]
317 expect(plugin.version).to.equal('0.0.1') 263 expect(plugin.version).to.equal('0.0.1')
318 expect(plugin.latestVersion).to.exist 264 expect(plugin.latestVersion).to.exist
319 expect(plugin.latestVersion).to.not.equal('0.0.1') 265 expect(plugin.latestVersion).to.not.equal('0.0.1')
320 } 266 }
321 267
322 { 268 {
323 await updatePlugin({ 269 await command.update({ npmName: 'peertube-plugin-hello-world' })
324 url: server.url,
325 accessToken: server.accessToken,
326 npmName: 'peertube-plugin-hello-world'
327 })
328
329 const res = await listPlugins({
330 url: server.url,
331 accessToken: server.accessToken,
332 pluginType: PluginType.PLUGIN
333 })
334 270
335 const plugin: PeerTubePlugin = res.body.data[0] 271 const body = await command.list({ pluginType: PluginType.PLUGIN })
336 272
273 const plugin = body.data[0]
337 expect(plugin.version).to.equal(oldVersion) 274 expect(plugin.version).to.equal(oldVersion)
338 275
339 const updatedPackageJSON: PluginPackageJson = await getPluginPackageJSON(server, 'peertube-plugin-hello-world') 276 const updatedPackageJSON = await command.getPackageJSON('peertube-plugin-hello-world')
340 expect(updatedPackageJSON.version).to.equal(oldVersion) 277 expect(updatedPackageJSON.version).to.equal(oldVersion)
341 } 278 }
342 }) 279 })
343 280
344 it('Should uninstall the plugin', async function () { 281 it('Should uninstall the plugin', async function () {
345 await uninstallPlugin({ 282 await command.uninstall({ npmName: 'peertube-plugin-hello-world' })
346 url: server.url,
347 accessToken: server.accessToken,
348 npmName: 'peertube-plugin-hello-world'
349 })
350
351 const res = await listPlugins({
352 url: server.url,
353 accessToken: server.accessToken,
354 pluginType: PluginType.PLUGIN
355 })
356 283
357 expect(res.body.total).to.equal(0) 284 const body = await command.list({ pluginType: PluginType.PLUGIN })
358 expect(res.body.data).to.have.lengthOf(0) 285 expect(body.total).to.equal(0)
286 expect(body.data).to.have.lengthOf(0)
359 }) 287 })
360 288
361 it('Should list uninstalled plugins', async function () { 289 it('Should list uninstalled plugins', async function () {
362 const res = await listPlugins({ 290 const body = await command.list({ pluginType: PluginType.PLUGIN, uninstalled: true })
363 url: server.url, 291 expect(body.total).to.equal(1)
364 accessToken: server.accessToken, 292 expect(body.data).to.have.lengthOf(1)
365 pluginType: PluginType.PLUGIN,
366 uninstalled: true
367 })
368 293
369 expect(res.body.total).to.equal(1) 294 const plugin = body.data[0]
370 expect(res.body.data).to.have.lengthOf(1)
371
372 const plugin: PeerTubePlugin = res.body.data[0]
373 expect(plugin.name).to.equal('hello-world') 295 expect(plugin.name).to.equal('hello-world')
374 expect(plugin.enabled).to.be.false 296 expect(plugin.enabled).to.be.false
375 expect(plugin.uninstalled).to.be.true 297 expect(plugin.uninstalled).to.be.true
376 }) 298 })
377 299
378 it('Should uninstall the theme', async function () { 300 it('Should uninstall the theme', async function () {
379 await uninstallPlugin({ 301 await command.uninstall({ npmName: 'peertube-theme-background-red' })
380 url: server.url,
381 accessToken: server.accessToken,
382 npmName: 'peertube-theme-background-red'
383 })
384 }) 302 })
385 303
386 it('Should have updated the configuration', async function () { 304 it('Should have updated the configuration', async function () {
@@ -406,21 +324,13 @@ describe('Test plugins', function () {
406 this.timeout(60000) 324 this.timeout(60000)
407 325
408 async function check () { 326 async function check () {
409 const res = await listPlugins({ 327 const body = await command.list({ pluginType: PluginType.PLUGIN })
410 url: server.url, 328 const plugins = body.data
411 accessToken: server.accessToken,
412 pluginType: PluginType.PLUGIN
413 })
414
415 const plugins: PeerTubePlugin[] = res.body.data
416
417 expect(plugins.find(p => p.name === 'test-broken')).to.not.exist 329 expect(plugins.find(p => p.name === 'test-broken')).to.not.exist
418 } 330 }
419 331
420 await installPlugin({ 332 await command.install({
421 url: server.url, 333 path: PluginsCommand.getPluginTestPath('-broken'),
422 accessToken: server.accessToken,
423 path: getPluginTestPath('-broken'),
424 expectedStatus: HttpStatusCode.BAD_REQUEST_400 334 expectedStatus: HttpStatusCode.BAD_REQUEST_400
425 }) 335 })
426 336
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts
index 92927ea97..ba4183e08 100644
--- a/server/tests/api/users/users.ts
+++ b/server/tests/api/users/users.ts
@@ -23,7 +23,6 @@ import {
23 getUsersListPaginationAndSort, 23 getUsersListPaginationAndSort,
24 getVideoChannel, 24 getVideoChannel,
25 getVideosList, 25 getVideosList,
26 installPlugin,
27 killallServers, 26 killallServers,
28 login, 27 login,
29 logout, 28 logout,
@@ -75,7 +74,7 @@ describe('Test users', function () {
75 74
76 await setAccessTokensToServers([ server ]) 75 await setAccessTokensToServers([ server ])
77 76
78 await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-theme-background-red' }) 77 await server.pluginsCommand.install({ npmName: 'peertube-theme-background-red' })
79 }) 78 })
80 79
81 describe('OAuth client', function () { 80 describe('OAuth client', function () {