]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/server/plugins.ts
Merge branch 'master' into release/3.3.0
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / plugins.ts
index b3d003f451745ca99dee5d9e5983e9fb48a55750..6b61c7c33705384733584872d4fe6d7d7daa62f0 100644 (file)
@@ -1,32 +1,37 @@
-/* tslint:disable:no-unused-expression */
+/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
 import 'mocha'
 import * as chai from 'chai'
+import { HttpStatusCode } from '@shared/core-utils'
 import {
   cleanupTests,
   closeAllSequelize,
   flushAndRunServer,
-  getConfig, getMyUserInformation, getPluginPackageJSON,
+  getConfig,
+  getMyUserInformation,
   getPlugin,
-  getPluginRegisteredSettings,
-  getPluginsCSS,
-  installPlugin, killallServers,
+  getPluginPackageJSON,
+  getPluginTestPath,
+  getPublicSettings,
+  installPlugin,
+  killallServers,
   listAvailablePlugins,
-  listPlugins, reRunServer,
+  listPlugins,
+  reRunServer,
   ServerInfo,
   setAccessTokensToServers,
-  setPluginVersion, uninstallPlugin,
-  updateCustomSubConfig, updateMyUser, updatePluginPackageJSON, updatePlugin,
+  setPluginVersion,
+  testHelloWorldRegisteredSettings,
+  uninstallPlugin,
+  updateCustomSubConfig,
+  updateMyUser,
+  updatePlugin,
+  updatePluginPackageJSON,
   updatePluginSettings,
-  wait
-} 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'
+  wait,
+  waitUntilLog
+} from '@shared/extra-utils'
+import { PeerTubePlugin, PeerTubePluginIndex, PluginPackageJson, PluginType, PublicServerSetting, ServerConfig, User } from '@shared/models'
 
 const expect = chai.expect
 
@@ -87,7 +92,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)
     }
 
     {
@@ -107,12 +112,6 @@ describe('Test plugins', function () {
     }
   })
 
-  it('Should have an empty global css', async function () {
-    const res = await getPluginsCSS(server.url)
-
-    expect(res.text).to.be.empty
-  })
-
   it('Should install a plugin and a theme', async function () {
     this.timeout(30000)
 
@@ -129,12 +128,6 @@ 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')
-  })
-
   it('Should have the plugin loaded in the configuration', async function () {
     const res = await getConfig(server.url)
     const config: ServerConfig = res.body
@@ -211,18 +204,17 @@ describe('Test plugins', function () {
   })
 
   it('Should get registered settings', async function () {
-    const res = await getPluginRegisteredSettings({
-      url: server.url,
-      accessToken: server.accessToken,
-      npmName: 'peertube-plugin-hello-world'
-    })
+    await testHelloWorldRegisteredSettings(server)
+  })
 
-    const settings = (res.body as RegisteredSettings).settings
+  it('Should get public settings', async function () {
+    const res = await getPublicSettings({ url: server.url, npmName: 'peertube-plugin-hello-world' })
 
-    expect(settings).to.have.length.at.least(1)
+    const publicSettings = (res.body as PublicServerSetting).publicSettings
 
-    const adminNameSettings = settings.find(s => s.name === 'admin-name')
-    expect(adminNameSettings).to.not.be.undefined
+    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 () {
@@ -238,6 +230,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({
@@ -288,7 +286,7 @@ describe('Test plugins', function () {
   })
 
   it('Should update the plugin and the theme', async function () {
-    this.timeout(30000)
+    this.timeout(90000)
 
     // Wait the scheduler that get the latest plugins versions
     await wait(6000)
@@ -360,12 +358,6 @@ describe('Test plugins', function () {
     expect(res.body.data).to.have.lengthOf(0)
   })
 
-  it('Should have an empty global css', async function () {
-    const res = await getPluginsCSS(server.url)
-
-    expect(res.text).to.be.empty
-  })
-
   it('Should list uninstalled plugins', async function () {
     const res = await listPlugins({
       url: server.url,
@@ -410,6 +402,36 @@ describe('Test plugins', function () {
     expect((res.body as User).theme).to.equal('instance-default')
   })
 
+  it('Should not install a broken plugin', async function () {
+    this.timeout(60000)
+
+    async function check () {
+      const res = await listPlugins({
+        url: server.url,
+        accessToken: server.accessToken,
+        pluginType: PluginType.PLUGIN
+      })
+
+      const plugins: PeerTubePlugin[] = res.body.data
+
+      expect(plugins.find(p => p.name === 'test-broken')).to.not.exist
+    }
+
+    await installPlugin({
+      url: server.url,
+      accessToken: server.accessToken,
+      path: getPluginTestPath('-broken'),
+      expectedStatus: HttpStatusCode.BAD_REQUEST_400
+    })
+
+    await check()
+
+    killallServers([ server ])
+    await reRunServer(server)
+
+    await check()
+  })
+
   after(async function () {
     await closeAllSequelize([ server ])
     await cleanupTests([ server ])