X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fserver%2Fplugins.ts;h=76d3e248162958da9c356624b7502f3187bfa55d;hb=7b51ede977c299a74728171d8c124bcc4cbba6ea;hp=e22ecfad957e9b7aff59946152982410303157b9;hpb=a54618880c394ad7571f3f3222dc96ec2dd10d9a;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/server/plugins.ts b/server/tests/api/server/plugins.ts index e22ecfad9..76d3e2481 100644 --- a/server/tests/api/server/plugins.ts +++ b/server/tests/api/server/plugins.ts @@ -2,29 +2,22 @@ import 'mocha' import * as chai from 'chai' -import { HttpStatusCode } from '@shared/core-utils' +import { testHelloWorldRegisteredSettings } from '@server/tests/shared' +import { wait } from '@shared/core-utils' +import { HttpStatusCode, PluginType } from '@shared/models' import { cleanupTests, - closeAllSequelize, - flushAndRunServer, - getMyUserInformation, + createSingleServer, killallServers, + PeerTubeServer, PluginsCommand, - reRunServer, - ServerInfo, - setAccessTokensToServers, - setPluginVersion, - testHelloWorldRegisteredSettings, - updateMyUser, - wait, - waitUntilLog -} from '@shared/extra-utils' -import { PluginType, User } from '@shared/models' + setAccessTokensToServers +} from '@shared/server-commands' const expect = chai.expect describe('Test plugins', function () { - let server: ServerInfo = null + let server: PeerTubeServer = null let command: PluginsCommand before(async function () { @@ -35,10 +28,10 @@ describe('Test plugins', function () { index: { check_latest_versions_interval: '5 seconds' } } } - server = await flushAndRunServer(1, configOverride) + server = await createSingleServer(1, configOverride) await setAccessTokensToServers([ server ]) - command = server.pluginsCommand + command = server.plugins }) it('Should list and search available plugins and themes', async function () { @@ -102,35 +95,33 @@ describe('Test plugins', function () { }) it('Should have the plugin loaded in the configuration', async function () { - const config = await server.configCommand.getConfig() + const config = await server.config.getConfig() const theme = config.theme.registered.find(r => r.name === 'background-red') expect(theme).to.not.be.undefined + expect(theme.npmName).to.equal('peertube-theme-background-red') const plugin = config.plugin.registered.find(r => r.name === 'hello-world') expect(plugin).to.not.be.undefined + expect(plugin.npmName).to.equal('peertube-plugin-hello-world') }) it('Should update the default theme in the configuration', async function () { - await server.configCommand.updateCustomSubConfig({ + await server.config.updateCustomSubConfig({ newConfig: { theme: { default: 'background-red' } } }) - const config = await server.configCommand.getConfig() + const config = await server.config.getConfig() expect(config.theme.default).to.equal('background-red') }) it('Should update my default theme', async function () { - await updateMyUser({ - url: server.url, - accessToken: server.accessToken, - theme: 'background-red' - }) + await server.users.updateMe({ theme: 'background-red' }) - const res = await getMyUserInformation(server.url, server.accessToken) - expect((res.body as User).theme).to.equal('background-red') + const user = await server.users.getMyInfo() + expect(user.theme).to.equal('background-red') }) it('Should list plugins and themes', async function () { @@ -148,13 +139,12 @@ describe('Test plugins', function () { } { - const body = await command.list({ + const { data } = await command.list({ count: 2, start: 0, sort: 'name' }) - const data = body expect(data[0].name).to.equal('background-red') expect(data[1].name).to.equal('hello-world') } @@ -197,7 +187,7 @@ describe('Test plugins', function () { it('Should have watched settings changes', async function () { this.timeout(10000) - await waitUntilLog(server, 'Settings changed!') + await server.servers.waitUntilLog('Settings changed!') }) it('Should get a plugin and a theme', async function () { @@ -244,7 +234,7 @@ describe('Test plugins', function () { await wait(6000) // Fake update our plugin version - await setPluginVersion(server.internalServerNumber, 'hello-world', '0.0.1') + await server.sql.setPluginVersion('hello-world', '0.0.1') // Fake update package.json const packageJSON = await command.getPackageJSON('peertube-plugin-hello-world') @@ -254,8 +244,8 @@ describe('Test plugins', function () { await command.updatePackageJSON('peertube-plugin-hello-world', packageJSON) // Restart the server to take into account this change - killallServers([ server ]) - await reRunServer(server) + await killallServers([ server ]) + await server.run() { const body = await command.list({ pluginType: PluginType.PLUGIN }) @@ -303,7 +293,7 @@ describe('Test plugins', function () { }) it('Should have updated the configuration', async function () { - const config = await server.configCommand.getConfig() + const config = await server.config.getConfig() expect(config.theme.default).to.equal('default') @@ -315,8 +305,8 @@ describe('Test plugins', function () { }) it('Should have updated the user theme', async function () { - const res = await getMyUserInformation(server.url, server.accessToken) - expect((res.body as User).theme).to.equal('instance-default') + const user = await server.users.getMyInfo() + expect(user.theme).to.equal('instance-default') }) it('Should not install a broken plugin', async function () { @@ -335,14 +325,13 @@ describe('Test plugins', function () { await check() - killallServers([ server ]) - await reRunServer(server) + await killallServers([ server ]) + await server.run() await check() }) after(async function () { - await closeAllSequelize([ server ]) await cleanupTests([ server ]) }) })