]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/server/plugins.ts
Add plugin settings change watcher
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / plugins.ts
index b3d003f451745ca99dee5d9e5983e9fb48a55750..9885be4e84bc3b19f8bb97646e0af59db0422a5b 100644 (file)
@@ -1,4 +1,4 @@
-/* tslint:disable:no-unused-expression */
+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
 import 'mocha'
 import * as chai from 'chai'
@@ -6,27 +6,38 @@ import {
   cleanupTests,
   closeAllSequelize,
   flushAndRunServer,
-  getConfig, getMyUserInformation, getPluginPackageJSON,
+  getConfig,
+  getMyUserInformation,
   getPlugin,
+  getPluginPackageJSON,
   getPluginRegisteredSettings,
   getPluginsCSS,
-  installPlugin, killallServers,
+  getPublicSettings,
+  installPlugin,
+  killallServers,
   listAvailablePlugins,
-  listPlugins, reRunServer,
+  listPlugins,
+  reRunServer,
   ServerInfo,
   setAccessTokensToServers,
-  setPluginVersion, uninstallPlugin,
-  updateCustomSubConfig, updateMyUser, updatePluginPackageJSON, updatePlugin,
+  setPluginVersion,
+  uninstallPlugin,
+  updateCustomSubConfig,
+  updateMyUser,
+  updatePlugin,
+  updatePluginPackageJSON,
   updatePluginSettings,
-  wait
+  wait,
+  waitUntilLog
 } from '../../../../shared/extra-utils'
 import { PluginType } from '../../../../shared/models/plugins/plugin.type'
 import { PeerTubePluginIndex } from '../../../../shared/models/plugins/peertube-plugin-index.model'
 import { ServerConfig } from '../../../../shared/models/server'
-import { RegisteredSettings } from '../../../../shared/models/plugins/register-setting.model'
 import { PeerTubePlugin } from '../../../../shared/models/plugins/peertube-plugin.model'
 import { User } from '../../../../shared/models/users'
 import { PluginPackageJson } from '../../../../shared/models/plugins/plugin-package-json.model'
+import { RegisteredServerSettings } from '../../../../shared/models/plugins/register-server-setting.model'
+import { PublicServerSetting } from '../../../../shared/models/plugins/public-server.setting'
 
 const expect = chai.expect
 
@@ -87,7 +98,7 @@ describe('Test plugins', function () {
       expect(res2.body.total).to.be.at.least(2)
       expect(data2).to.have.lengthOf(2)
 
-      expect(data1[0].npmName).to.not.equal(data2[ 0 ].npmName)
+      expect(data1[0].npmName).to.not.equal(data2[0].npmName)
     }
 
     {
@@ -132,7 +143,7 @@ describe('Test plugins', function () {
   it('Should have the correct global css', async function () {
     const res = await getPluginsCSS(server.url)
 
-    expect(res.text).to.contain('--mainBackgroundColor')
+    expect(res.text).to.contain('background-color: red')
   })
 
   it('Should have the plugin loaded in the configuration', async function () {
@@ -217,14 +228,24 @@ describe('Test plugins', function () {
       npmName: 'peertube-plugin-hello-world'
     })
 
-    const settings = (res.body as RegisteredSettings).settings
+    const registeredSettings = (res.body as RegisteredServerSettings).registeredSettings
 
-    expect(settings).to.have.length.at.least(1)
+    expect(registeredSettings).to.have.length.at.least(1)
 
-    const adminNameSettings = settings.find(s => s.name === 'admin-name')
+    const adminNameSettings = registeredSettings.find(s => s.name === 'admin-name')
     expect(adminNameSettings).to.not.be.undefined
   })
 
+  it('Should get public settings', async function () {
+    const res = await getPublicSettings({ url: server.url, npmName: 'peertube-plugin-hello-world' })
+
+    const publicSettings = (res.body as PublicServerSetting).publicSettings
+
+    expect(Object.keys(publicSettings)).to.have.lengthOf(1)
+    expect(Object.keys(publicSettings)).to.deep.equal([ 'user-name' ])
+    expect(publicSettings['user-name']).to.be.null
+  })
+
   it('Should update the settings', async function () {
     const settings = {
       'admin-name': 'Cid'
@@ -238,6 +259,12 @@ describe('Test plugins', function () {
     })
   })
 
+  it('Should have watched settings changes', async function () {
+    this.timeout(10000)
+
+    await waitUntilLog(server, 'Settings changed!')
+  })
+
   it('Should get a plugin and a theme', async function () {
     {
       const res = await getPlugin({