aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared
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 /shared
parent9b474844e85cce916370693cc24f53339a695570 (diff)
downloadPeerTube-09071200c73f5358e1d0bfb61a274e4f2c4ec52b.tar.gz
PeerTube-09071200c73f5358e1d0bfb61a274e4f2c4ec52b.tar.zst
PeerTube-09071200c73f5358e1d0bfb61a274e4f2c4ec52b.zip
Add plugin API tests
Diffstat (limited to 'shared')
-rw-r--r--shared/extra-utils/miscs/sql.ts10
-rw-r--r--shared/extra-utils/server/plugins.ts90
-rw-r--r--shared/models/plugins/register-setting.model.ts4
3 files changed, 95 insertions, 9 deletions
diff --git a/shared/extra-utils/miscs/sql.ts b/shared/extra-utils/miscs/sql.ts
index 34477cb78..1961a8762 100644
--- a/shared/extra-utils/miscs/sql.ts
+++ b/shared/extra-utils/miscs/sql.ts
@@ -1,5 +1,6 @@
1import { QueryTypes, Sequelize } from 'sequelize' 1import { QueryTypes, Sequelize } from 'sequelize'
2import { ServerInfo } from '../server/servers' 2import { ServerInfo } from '../server/servers'
3import { PluginType } from '../../models/plugins/plugin.type'
3 4
4let sequelizes: { [ id: number ]: Sequelize } = {} 5let sequelizes: { [ id: number ]: Sequelize } = {}
5 6
@@ -72,10 +73,19 @@ async function closeAllSequelize (servers: ServerInfo[]) {
72 } 73 }
73} 74}
74 75
76function setPluginVersion (internalServerNumber: number, pluginName: string, newVersion: string) {
77 const seq = getSequelize(internalServerNumber)
78
79 const options = { type: QueryTypes.UPDATE }
80
81 return seq.query(`UPDATE "plugin" SET "version" = '${newVersion}' WHERE "name" = '${pluginName}'`, options)
82}
83
75export { 84export {
76 setVideoField, 85 setVideoField,
77 setPlaylistField, 86 setPlaylistField,
78 setActorField, 87 setActorField,
79 countVideoViewsOf, 88 countVideoViewsOf,
89 setPluginVersion,
80 closeAllSequelize 90 closeAllSequelize
81} 91}
diff --git a/shared/extra-utils/server/plugins.ts b/shared/extra-utils/server/plugins.ts
index 1da313ab7..7a5c5344b 100644
--- a/shared/extra-utils/server/plugins.ts
+++ b/shared/extra-utils/server/plugins.ts
@@ -1,5 +1,10 @@
1import { makeGetRequest, makePostBodyRequest } from '../requests/requests' 1import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests'
2import { PluginType } from '../../models/plugins/plugin.type' 2import { PluginType } from '../../models/plugins/plugin.type'
3import { PeertubePluginIndexList } from '../../models/plugins/peertube-plugin-index-list.model'
4import { readJSON, writeJSON } from 'fs-extra'
5import { ServerInfo } from './servers'
6import { root } from '../miscs/miscs'
7import { join } from 'path'
3 8
4function listPlugins (parameters: { 9function listPlugins (parameters: {
5 url: string, 10 url: string,
@@ -7,10 +12,11 @@ function listPlugins (parameters: {
7 start?: number, 12 start?: number,
8 count?: number, 13 count?: number,
9 sort?: string, 14 sort?: string,
10 type?: PluginType, 15 pluginType?: PluginType,
16 uninstalled?: boolean,
11 expectedStatus?: number 17 expectedStatus?: number
12}) { 18}) {
13 const { url, accessToken, start, count, sort, type, expectedStatus = 200 } = parameters 19 const { url, accessToken, start, count, sort, pluginType, uninstalled, expectedStatus = 200 } = parameters
14 const path = '/api/v1/plugins' 20 const path = '/api/v1/plugins'
15 21
16 return makeGetRequest({ 22 return makeGetRequest({
@@ -21,12 +27,45 @@ function listPlugins (parameters: {
21 start, 27 start,
22 count, 28 count,
23 sort, 29 sort,
24 type 30 pluginType,
31 uninstalled
25 }, 32 },
26 statusCodeExpected: expectedStatus 33 statusCodeExpected: expectedStatus
27 }) 34 })
28} 35}
29 36
37function listAvailablePlugins (parameters: {
38 url: string,
39 accessToken: string,
40 start?: number,
41 count?: number,
42 sort?: string,
43 pluginType?: PluginType,
44 currentPeerTubeEngine?: string,
45 search?: string
46 expectedStatus?: number
47}) {
48 const { url, accessToken, start, count, sort, pluginType, search, currentPeerTubeEngine, expectedStatus = 200 } = parameters
49 const path = '/api/v1/plugins/available'
50
51 const query: PeertubePluginIndexList = {
52 start,
53 count,
54 sort,
55 pluginType,
56 currentPeerTubeEngine,
57 search
58 }
59
60 return makeGetRequest({
61 url,
62 path,
63 token: accessToken,
64 query,
65 statusCodeExpected: expectedStatus
66 })
67}
68
30function getPlugin (parameters: { 69function getPlugin (parameters: {
31 url: string, 70 url: string,
32 accessToken: string, 71 accessToken: string,
@@ -44,19 +83,21 @@ function getPlugin (parameters: {
44 }) 83 })
45} 84}
46 85
47function getPluginSettings (parameters: { 86function updatePluginSettings (parameters: {
48 url: string, 87 url: string,
49 accessToken: string, 88 accessToken: string,
50 npmName: string, 89 npmName: string,
90 settings: any,
51 expectedStatus?: number 91 expectedStatus?: number
52}) { 92}) {
53 const { url, accessToken, npmName, expectedStatus = 200 } = parameters 93 const { url, accessToken, npmName, settings, expectedStatus = 204 } = parameters
54 const path = '/api/v1/plugins/' + npmName + '/settings' 94 const path = '/api/v1/plugins/' + npmName + '/settings'
55 95
56 return makeGetRequest({ 96 return makePutBodyRequest({
57 url, 97 url,
58 path, 98 path,
59 token: accessToken, 99 token: accessToken,
100 fields: { settings },
60 statusCodeExpected: expectedStatus 101 statusCodeExpected: expectedStatus
61 }) 102 })
62} 103}
@@ -134,12 +175,43 @@ function uninstallPlugin (parameters: {
134 }) 175 })
135} 176}
136 177
178function getPluginsCSS (url: string) {
179 const path = '/plugins/global.css'
180
181 return makeGetRequest({
182 url,
183 path,
184 statusCodeExpected: 200
185 })
186}
187
188function getPackageJSONPath (server: ServerInfo, npmName: string) {
189 return join(root(), 'test' + server.internalServerNumber, 'plugins', 'node_modules', npmName, 'package.json')
190}
191
192function updatePluginPackageJSON (server: ServerInfo, npmName: string, json: any) {
193 const path = getPackageJSONPath(server, npmName)
194
195 return writeJSON(path, json)
196}
197
198function getPluginPackageJSON (server: ServerInfo, npmName: string) {
199 const path = getPackageJSONPath(server, npmName)
200
201 return readJSON(path)
202}
203
137export { 204export {
138 listPlugins, 205 listPlugins,
206 listAvailablePlugins,
139 installPlugin, 207 installPlugin,
208 getPluginsCSS,
140 updatePlugin, 209 updatePlugin,
141 getPlugin, 210 getPlugin,
142 uninstallPlugin, 211 uninstallPlugin,
143 getPluginSettings, 212 updatePluginSettings,
144 getPluginRegisteredSettings 213 getPluginRegisteredSettings,
214 getPackageJSONPath,
215 updatePluginPackageJSON,
216 getPluginPackageJSON
145} 217}
diff --git a/shared/models/plugins/register-setting.model.ts b/shared/models/plugins/register-setting.model.ts
index e7af75dca..429ac3aad 100644
--- a/shared/models/plugins/register-setting.model.ts
+++ b/shared/models/plugins/register-setting.model.ts
@@ -4,3 +4,7 @@ export interface RegisterSettingOptions {
4 type: 'input' 4 type: 'input'
5 default?: string 5 default?: string
6} 6}
7
8export interface RegisteredSettings {
9 settings: RegisterSettingOptions[]
10}