From 1b05d82d861f42c27766e9f24d8d55e68b0cf098 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 9 Apr 2020 11:00:30 +0200 Subject: Add SQL query support in plugins --- .../fixtures/peertube-plugin-test-four/main.js | 27 +++++++++++++++ .../peertube-plugin-test-four/package.json | 20 ++++++++++++ server/tests/plugins/index.ts | 1 + server/tests/plugins/plugin-helpers.ts | 38 ++++++++++++++++++++++ 4 files changed, 86 insertions(+) create mode 100644 server/tests/fixtures/peertube-plugin-test-four/main.js create mode 100644 server/tests/fixtures/peertube-plugin-test-four/package.json create mode 100644 server/tests/plugins/plugin-helpers.ts (limited to 'server/tests') diff --git a/server/tests/fixtures/peertube-plugin-test-four/main.js b/server/tests/fixtures/peertube-plugin-test-four/main.js new file mode 100644 index 000000000..9abb73646 --- /dev/null +++ b/server/tests/fixtures/peertube-plugin-test-four/main.js @@ -0,0 +1,27 @@ +async function register ({ + peertubeHelpers +}) { + peertubeHelpers.logger.info('Hello world from plugin four') + + const username = 'root' + const results = await peertubeHelpers.database.query( + 'SELECT "email" from "user" WHERE "username" = $username', + { + type: 'SELECT', + bind: { username } + } + ) + + peertubeHelpers.logger.info('root email is ' + results[0]['email']) +} + +async function unregister () { + return +} + +module.exports = { + register, + unregister +} + +// ########################################################################### diff --git a/server/tests/fixtures/peertube-plugin-test-four/package.json b/server/tests/fixtures/peertube-plugin-test-four/package.json new file mode 100644 index 000000000..dda3c7f37 --- /dev/null +++ b/server/tests/fixtures/peertube-plugin-test-four/package.json @@ -0,0 +1,20 @@ +{ + "name": "peertube-plugin-test-four", + "version": "0.0.1", + "description": "Plugin test 4", + "engine": { + "peertube": ">=1.3.0" + }, + "keywords": [ + "peertube", + "plugin" + ], + "homepage": "https://github.com/Chocobozzz/PeerTube", + "author": "Chocobozzz", + "bugs": "https://github.com/Chocobozzz/PeerTube/issues", + "library": "./main.js", + "staticDirs": {}, + "css": [], + "clientScripts": [], + "translations": {} +} diff --git a/server/tests/plugins/index.ts b/server/tests/plugins/index.ts index f41708055..9c9499a79 100644 --- a/server/tests/plugins/index.ts +++ b/server/tests/plugins/index.ts @@ -2,3 +2,4 @@ import './action-hooks' import './filter-hooks' import './translations' import './video-constants' +import './plugin-helpers' diff --git a/server/tests/plugins/plugin-helpers.ts b/server/tests/plugins/plugin-helpers.ts new file mode 100644 index 000000000..05928273f --- /dev/null +++ b/server/tests/plugins/plugin-helpers.ts @@ -0,0 +1,38 @@ +/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ + +import * as chai from 'chai' +import 'mocha' +import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers' +import { getPluginTestPath, installPlugin, setAccessTokensToServers } from '../../../shared/extra-utils' + +const expect = chai.expect + +describe('Test plugin helpers', function () { + let server: ServerInfo + + before(async function () { + this.timeout(30000) + + server = await flushAndRunServer(1) + await setAccessTokensToServers([ server ]) + + await installPlugin({ + url: server.url, + accessToken: server.accessToken, + path: getPluginTestPath('-four') + }) + }) + + it('Should have logged things', async function () { + await waitUntilLog(server, 'localhost:' + server.port + ' peertube-plugin-test-four', 1, false) + await waitUntilLog(server, 'Hello world from plugin four', 1) + }) + + it('Should have made a query', async function () { + await waitUntilLog(server, `root email is admin${server.internalServerNumber}@example.com`, 1) + }) + + after(async function () { + await cleanupTests([ server ]) + }) +}) -- cgit v1.2.3