]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - shared/extra-utils/server/plugins.ts
Simplify createServer args
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / server / plugins.ts
index 65d37d69f094c5134a509d8cbad3c0ec4049c694..0f5fabd5abab9b3fedcbd644ba86fda26a069a8d 100644 (file)
-import { makeGetRequest, makePostBodyRequest, makePutBodyRequest } from '../requests/requests'
-import { PluginType } from '../../models/plugins/plugin.type'
-import { PeertubePluginIndexList } from '../../models/plugins/peertube-plugin-index-list.model'
-import { readJSON, writeJSON } from 'fs-extra'
-import { ServerInfo } from './servers'
-import { root } from '../miscs/miscs'
-import { join } from 'path'
+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
-function listPlugins (parameters: {
-  url: string,
-  accessToken: string,
-  start?: number,
-  count?: number,
-  sort?: string,
-  pluginType?: PluginType,
-  uninstalled?: boolean,
-  expectedStatus?: number
-}) {
-  const { url, accessToken, start, count, sort, pluginType, uninstalled, expectedStatus = 200 } = parameters
-  const path = '/api/v1/plugins'
+import { expect } from 'chai'
+import { PeerTubeServer } from '../server/server'
 
-  return makeGetRequest({
-    url,
-    path,
-    token: accessToken,
-    query: {
-      start,
-      count,
-      sort,
-      pluginType,
-      uninstalled
-    },
-    statusCodeExpected: expectedStatus
-  })
-}
-
-function listAvailablePlugins (parameters: {
-  url: string,
-  accessToken: string,
-  start?: number,
-  count?: number,
-  sort?: string,
-  pluginType?: PluginType,
-  currentPeerTubeEngine?: string,
-  search?: string
-  expectedStatus?: number
-}) {
-  const { url, accessToken, start, count, sort, pluginType, search, currentPeerTubeEngine, expectedStatus = 200 } = parameters
-  const path = '/api/v1/plugins/available'
-
-  const query: PeertubePluginIndexList = {
-    start,
-    count,
-    sort,
-    pluginType,
-    currentPeerTubeEngine,
-    search
-  }
-
-  return makeGetRequest({
-    url,
-    path,
-    token: accessToken,
-    query,
-    statusCodeExpected: expectedStatus
-  })
-}
-
-function getPlugin (parameters: {
-  url: string,
-  accessToken: string,
-  npmName: string,
-  expectedStatus?: number
-}) {
-  const { url, accessToken, npmName, expectedStatus = 200 } = parameters
-  const path = '/api/v1/plugins/' + npmName
-
-  return makeGetRequest({
-    url,
-    path,
-    token: accessToken,
-    statusCodeExpected: expectedStatus
-  })
-}
-
-function updatePluginSettings (parameters: {
-  url: string,
-  accessToken: string,
-  npmName: string,
-  settings: any,
-  expectedStatus?: number
-}) {
-  const { url, accessToken, npmName, settings, expectedStatus = 204 } = parameters
-  const path = '/api/v1/plugins/' + npmName + '/settings'
-
-  return makePutBodyRequest({
-    url,
-    path,
-    token: accessToken,
-    fields: { settings },
-    statusCodeExpected: expectedStatus
-  })
-}
-
-function getPluginRegisteredSettings (parameters: {
-  url: string,
-  accessToken: string,
-  npmName: string,
-  expectedStatus?: number
-}) {
-  const { url, accessToken, npmName, expectedStatus = 200 } = parameters
-  const path = '/api/v1/plugins/' + npmName + '/registered-settings'
-
-  return makeGetRequest({
-    url,
-    path,
-    token: accessToken,
-    statusCodeExpected: expectedStatus
-  })
-}
-
-function getPublicSettings (parameters: {
-  url: string,
-  npmName: string,
-  expectedStatus?: number
-}) {
-  const { url, npmName, expectedStatus = 200 } = parameters
-  const path = '/api/v1/plugins/' + npmName + '/public-settings'
-
-  return makeGetRequest({
-    url,
-    path,
-    statusCodeExpected: expectedStatus
-  })
-}
-
-function installPlugin (parameters: {
-  url: string,
-  accessToken: string,
-  path?: string,
-  npmName?: string
-  expectedStatus?: number
-}) {
-  const { url, accessToken, npmName, path, expectedStatus = 200 } = parameters
-  const apiPath = '/api/v1/plugins/install'
+async function testHelloWorldRegisteredSettings (server: PeerTubeServer) {
+  const body = await server.plugins.getRegisteredSettings({ npmName: 'peertube-plugin-hello-world' })
 
-  return makePostBodyRequest({
-    url,
-    path: apiPath,
-    token: accessToken,
-    fields: { npmName, path },
-    statusCodeExpected: expectedStatus
-  })
-}
-
-function updatePlugin (parameters: {
-  url: string,
-  accessToken: string,
-  path?: string,
-  npmName?: string
-  expectedStatus?: number
-}) {
-  const { url, accessToken, npmName, path, expectedStatus = 200 } = parameters
-  const apiPath = '/api/v1/plugins/update'
-
-  return makePostBodyRequest({
-    url,
-    path: apiPath,
-    token: accessToken,
-    fields: { npmName, path },
-    statusCodeExpected: expectedStatus
-  })
-}
-
-function uninstallPlugin (parameters: {
-  url: string,
-  accessToken: string,
-  npmName: string
-  expectedStatus?: number
-}) {
-  const { url, accessToken, npmName, expectedStatus = 204 } = parameters
-  const apiPath = '/api/v1/plugins/uninstall'
-
-  return makePostBodyRequest({
-    url,
-    path: apiPath,
-    token: accessToken,
-    fields: { npmName },
-    statusCodeExpected: expectedStatus
-  })
-}
-
-function getPluginsCSS (url: string) {
-  const path = '/plugins/global.css'
-
-  return makeGetRequest({
-    url,
-    path,
-    statusCodeExpected: 200
-  })
-}
-
-function getPackageJSONPath (server: ServerInfo, npmName: string) {
-  return join(root(), 'test' + server.internalServerNumber, 'plugins', 'node_modules', npmName, 'package.json')
-}
-
-function updatePluginPackageJSON (server: ServerInfo, npmName: string, json: any) {
-  const path = getPackageJSONPath(server, npmName)
-
-  return writeJSON(path, json)
-}
-
-function getPluginPackageJSON (server: ServerInfo, npmName: string) {
-  const path = getPackageJSONPath(server, npmName)
-
-  return readJSON(path)
-}
+  const registeredSettings = body.registeredSettings
+  expect(registeredSettings).to.have.length.at.least(1)
 
-function getPluginTestPath (suffix = '') {
-  return join(root(), 'server', 'tests', 'fixtures', 'peertube-plugin-test' + suffix)
+  const adminNameSettings = registeredSettings.find(s => s.name === 'admin-name')
+  expect(adminNameSettings).to.not.be.undefined
 }
 
 export {
-  listPlugins,
-  listAvailablePlugins,
-  installPlugin,
-  getPluginsCSS,
-  updatePlugin,
-  getPlugin,
-  uninstallPlugin,
-  updatePluginSettings,
-  getPluginRegisteredSettings,
-  getPackageJSONPath,
-  updatePluginPackageJSON,
-  getPluginPackageJSON,
-  getPluginTestPath,
-  getPublicSettings
+  testHelloWorldRegisteredSettings
 }