diff options
author | Chocobozzz <me@florianbigard.com> | 2020-04-09 11:00:30 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-04-09 11:00:30 +0200 |
commit | 1b05d82d861f42c27766e9f24d8d55e68b0cf098 (patch) | |
tree | bbf14abc606dd3f8f0c13625afbdf3b17fea3a23 /server/tests | |
parent | bc0d801bb7a0cc503c1637f4a07bb51d68d85608 (diff) | |
download | PeerTube-1b05d82d861f42c27766e9f24d8d55e68b0cf098.tar.gz PeerTube-1b05d82d861f42c27766e9f24d8d55e68b0cf098.tar.zst PeerTube-1b05d82d861f42c27766e9f24d8d55e68b0cf098.zip |
Add SQL query support in plugins
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/fixtures/peertube-plugin-test-four/main.js | 27 | ||||
-rw-r--r-- | server/tests/fixtures/peertube-plugin-test-four/package.json | 20 | ||||
-rw-r--r-- | server/tests/plugins/index.ts | 1 | ||||
-rw-r--r-- | server/tests/plugins/plugin-helpers.ts | 38 |
4 files changed, 86 insertions, 0 deletions
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 @@ | |||
1 | async function register ({ | ||
2 | peertubeHelpers | ||
3 | }) { | ||
4 | peertubeHelpers.logger.info('Hello world from plugin four') | ||
5 | |||
6 | const username = 'root' | ||
7 | const results = await peertubeHelpers.database.query( | ||
8 | 'SELECT "email" from "user" WHERE "username" = $username', | ||
9 | { | ||
10 | type: 'SELECT', | ||
11 | bind: { username } | ||
12 | } | ||
13 | ) | ||
14 | |||
15 | peertubeHelpers.logger.info('root email is ' + results[0]['email']) | ||
16 | } | ||
17 | |||
18 | async function unregister () { | ||
19 | return | ||
20 | } | ||
21 | |||
22 | module.exports = { | ||
23 | register, | ||
24 | unregister | ||
25 | } | ||
26 | |||
27 | // ########################################################################### | ||
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 @@ | |||
1 | { | ||
2 | "name": "peertube-plugin-test-four", | ||
3 | "version": "0.0.1", | ||
4 | "description": "Plugin test 4", | ||
5 | "engine": { | ||
6 | "peertube": ">=1.3.0" | ||
7 | }, | ||
8 | "keywords": [ | ||
9 | "peertube", | ||
10 | "plugin" | ||
11 | ], | ||
12 | "homepage": "https://github.com/Chocobozzz/PeerTube", | ||
13 | "author": "Chocobozzz", | ||
14 | "bugs": "https://github.com/Chocobozzz/PeerTube/issues", | ||
15 | "library": "./main.js", | ||
16 | "staticDirs": {}, | ||
17 | "css": [], | ||
18 | "clientScripts": [], | ||
19 | "translations": {} | ||
20 | } | ||
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' | |||
2 | import './filter-hooks' | 2 | import './filter-hooks' |
3 | import './translations' | 3 | import './translations' |
4 | import './video-constants' | 4 | import './video-constants' |
5 | 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 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import * as chai from 'chai' | ||
4 | import 'mocha' | ||
5 | import { cleanupTests, flushAndRunServer, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers' | ||
6 | import { getPluginTestPath, installPlugin, setAccessTokensToServers } from '../../../shared/extra-utils' | ||
7 | |||
8 | const expect = chai.expect | ||
9 | |||
10 | describe('Test plugin helpers', function () { | ||
11 | let server: ServerInfo | ||
12 | |||
13 | before(async function () { | ||
14 | this.timeout(30000) | ||
15 | |||
16 | server = await flushAndRunServer(1) | ||
17 | await setAccessTokensToServers([ server ]) | ||
18 | |||
19 | await installPlugin({ | ||
20 | url: server.url, | ||
21 | accessToken: server.accessToken, | ||
22 | path: getPluginTestPath('-four') | ||
23 | }) | ||
24 | }) | ||
25 | |||
26 | it('Should have logged things', async function () { | ||
27 | await waitUntilLog(server, 'localhost:' + server.port + ' peertube-plugin-test-four', 1, false) | ||
28 | await waitUntilLog(server, 'Hello world from plugin four', 1) | ||
29 | }) | ||
30 | |||
31 | it('Should have made a query', async function () { | ||
32 | await waitUntilLog(server, `root email is admin${server.internalServerNumber}@example.com`, 1) | ||
33 | }) | ||
34 | |||
35 | after(async function () { | ||
36 | await cleanupTests([ server ]) | ||
37 | }) | ||
38 | }) | ||