From 9b474844e85cce916370693cc24f53339a695570 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 19 Jul 2019 10:37:35 +0200 Subject: Add CLI plugins tests --- server/tests/api/check-params/users.ts | 13 +++- server/tests/api/server/index.ts | 1 + server/tests/api/server/plugins.ts | 130 +++++++++++++++++++++++++++++++++ server/tests/api/users/users.ts | 19 ++++- 4 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 server/tests/api/server/plugins.ts (limited to 'server/tests/api') diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts index 5d62fe2b3..5b788e328 100644 --- a/server/tests/api/check-params/users.ts +++ b/server/tests/api/check-params/users.ts @@ -387,13 +387,24 @@ describe('Test users API validators', function () { } }) + it('Should fail with an invalid theme', async function () { + const fields = { theme: 'invalid' } + await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) + }) + + it('Should fail with an unknown theme', async function () { + const fields = { theme: 'peertube-theme-unknown' } + await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) + }) + it('Should succeed to change password with the correct params', async function () { const fields = { currentPassword: 'my super password', password: 'my super password', nsfwPolicy: 'blur', autoPlayVideo: false, - email: 'super_email@example.com' + email: 'super_email@example.com', + theme: 'default' } await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields, statusCodeExpected: 204 }) diff --git a/server/tests/api/server/index.ts b/server/tests/api/server/index.ts index 94c15e0d0..3daeeb49a 100644 --- a/server/tests/api/server/index.ts +++ b/server/tests/api/server/index.ts @@ -11,3 +11,4 @@ import './reverse-proxy' import './stats' import './tracker' import './no-client' +import './plugins' diff --git a/server/tests/api/server/plugins.ts b/server/tests/api/server/plugins.ts new file mode 100644 index 000000000..9a623c553 --- /dev/null +++ b/server/tests/api/server/plugins.ts @@ -0,0 +1,130 @@ +/* tslint:disable:no-unused-expression */ + +import 'mocha' +import * as chai from 'chai' +import { About } from '../../../../shared/models/server/about.model' +import { CustomConfig } from '../../../../shared/models/server/custom-config.model' +import { + cleanupTests, + deleteCustomConfig, + flushAndRunServer, + getAbout, + getConfig, + getCustomConfig, installPlugin, + killallServers, parallelTests, + registerUser, + reRunServer, ServerInfo, + setAccessTokensToServers, + updateCustomConfig, uploadVideo +} from '../../../../shared/extra-utils' +import { ServerConfig } from '../../../../shared/models' +import { PeerTubePlugin } from '../../../../shared/models/plugins/peertube-plugin.model' + +const expect = chai.expect + +describe('Test plugins', function () { + let server = null + + before(async function () { + this.timeout(30000) + + server = await flushAndRunServer(1) + await setAccessTokensToServers([ server ]) + + { + await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-hello-world' }) + } + + { + await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-plugin-background-color' }) + } + }) + + it('Should list available plugins and themes', async function () { + // List without filter + // List with filter (plugin and theme) + }) + + it('Should search available plugins', async function () { + // Search with filter (plugin and theme) + // Add pagination + // Add sort + // Add peertube engine + }) + + it('Should have an empty global css', async function () { + // get /global.css + }) + + it('Should install a plugin and a theme', async function () { + + }) + + it('Should have the correct global css', async function () { + // get /global.css + }) + + it('Should have the plugin loaded in the configuration', async function () { + // Check registered themes/plugins + }) + + it('Should update the default theme in the configuration', async function () { + // Update config + }) + + it('Should list plugins and themes', async function () { + // List without filter + // List with filter (theme/plugin) + // List with pagination + // List with sort + }) + + it('Should get a plugin and a theme', async function () { + // Get plugin + // Get theme + }) + + it('Should get registered settings', async function () { + // Get plugin + }) + + it('Should update the settings', async function () { + // Update /settings + + // get /plugin + }) + + it('Should update the plugin and the theme', async function () { + // update BDD -> 0.0.1 + // update package.json (theme + plugin) + // list to check versions + // update plugin + theme + // list to check they have been updated + // check package.json are upgraded too + }) + + it('Should uninstall the plugin', async function () { + // uninstall + // list + }) + + it('Should have an empty global css', async function () { + // get /global.css + }) + + it('Should list uninstalled plugins', async function () { + // { uninstalled: true } + }) + + it('Should uninstall the theme', async function () { + // Uninstall + }) + + it('Should have updated the configuration', async function () { + // get /config (default theme + registered themes + registered plugins) + }) + + after(async function () { + await cleanupTests([ server ]) + }) +}) diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 6fc2a070f..3a3fabb4c 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts @@ -18,7 +18,7 @@ import { getUsersList, getUsersListPaginationAndSort, getVideoChannel, - getVideosList, + getVideosList, installPlugin, login, makePutBodyRequest, rateVideo, @@ -57,6 +57,8 @@ describe('Test users', function () { server = await flushAndRunServer(1) await setAccessTokensToServers([ server ]) + + await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: 'peertube-theme-background-red' }) }) describe('OAuth client', function () { @@ -551,6 +553,21 @@ describe('Test users', function () { expect(user.account.displayName).to.equal('new display name') expect(user.account.description).to.equal('my super description updated') }) + + it('Should be able to update my theme', async function () { + for (const theme of [ 'background-red', 'default', 'instance-default' ]) { + await updateMyUser({ + url: server.url, + accessToken: accessTokenUser, + theme + }) + + const res = await getMyUserInformation(server.url, accessTokenUser) + const body: User = res.body + + expect(body.theme).to.equal(theme) + } + }) }) describe('Updating another user', function () { -- cgit v1.2.3