aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-04-10 15:07:54 +0200
committerChocobozzz <me@florianbigard.com>2020-04-10 15:23:25 +0200
commit5e2b2e2775421cd98286d6e2f75cf38aae7a212c (patch)
treed92e32824d83cecbe5e90206738f393b47e55754 /server/tests
parent9afa0901f11c321e071c42ba3c814a3af4843c55 (diff)
downloadPeerTube-5e2b2e2775421cd98286d6e2f75cf38aae7a212c.tar.gz
PeerTube-5e2b2e2775421cd98286d6e2f75cf38aae7a212c.tar.zst
PeerTube-5e2b2e2775421cd98286d6e2f75cf38aae7a212c.zip
Add ability for plugins to add custom routes
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/fixtures/peertube-plugin-test-five/main.js21
-rw-r--r--server/tests/fixtures/peertube-plugin-test-five/package.json20
-rw-r--r--server/tests/plugins/index.ts1
-rw-r--r--server/tests/plugins/plugin-router.ts91
4 files changed, 133 insertions, 0 deletions
diff --git a/server/tests/fixtures/peertube-plugin-test-five/main.js b/server/tests/fixtures/peertube-plugin-test-five/main.js
new file mode 100644
index 000000000..c1435b928
--- /dev/null
+++ b/server/tests/fixtures/peertube-plugin-test-five/main.js
@@ -0,0 +1,21 @@
1async function register ({
2 getRouter
3}) {
4 const router = getRouter()
5 router.get('/ping', (req, res) => res.json({ message: 'pong' }))
6
7 router.post('/form/post/mirror', (req, res) => {
8 res.json(req.body)
9 })
10}
11
12async function unregister () {
13 return
14}
15
16module.exports = {
17 register,
18 unregister
19}
20
21// ###########################################################################
diff --git a/server/tests/fixtures/peertube-plugin-test-five/package.json b/server/tests/fixtures/peertube-plugin-test-five/package.json
new file mode 100644
index 000000000..1f5d65d9d
--- /dev/null
+++ b/server/tests/fixtures/peertube-plugin-test-five/package.json
@@ -0,0 +1,20 @@
1{
2 "name": "peertube-plugin-test-five",
3 "version": "0.0.1",
4 "description": "Plugin test 5",
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 9c9499a79..1414e7e58 100644
--- a/server/tests/plugins/index.ts
+++ b/server/tests/plugins/index.ts
@@ -3,3 +3,4 @@ import './filter-hooks'
3import './translations' 3import './translations'
4import './video-constants' 4import './video-constants'
5import './plugin-helpers' 5import './plugin-helpers'
6import './plugin-router'
diff --git a/server/tests/plugins/plugin-router.ts b/server/tests/plugins/plugin-router.ts
new file mode 100644
index 000000000..cf4130f4b
--- /dev/null
+++ b/server/tests/plugins/plugin-router.ts
@@ -0,0 +1,91 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3import 'mocha'
4import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../shared/extra-utils/server/servers'
5import {
6 getPluginTestPath,
7 installPlugin,
8 makeGetRequest,
9 makePostBodyRequest,
10 setAccessTokensToServers, uninstallPlugin
11} from '../../../shared/extra-utils'
12import { expect } from 'chai'
13
14describe('Test plugin helpers', function () {
15 let server: ServerInfo
16 const basePaths = [
17 '/plugins/test-five/router/',
18 '/plugins/test-five/0.0.1/router/'
19 ]
20
21 before(async function () {
22 this.timeout(30000)
23
24 server = await flushAndRunServer(1)
25 await setAccessTokensToServers([ server ])
26
27 await installPlugin({
28 url: server.url,
29 accessToken: server.accessToken,
30 path: getPluginTestPath('-five')
31 })
32 })
33
34 it('Should answer "pong"', async function () {
35 for (const path of basePaths) {
36 const res = await makeGetRequest({
37 url: server.url,
38 path: path + 'ping',
39 statusCodeExpected: 200
40 })
41
42 expect(res.body.message).to.equal('pong')
43 }
44 })
45
46 it('Should mirror post body', async function () {
47 const body = {
48 hello: 'world',
49 riri: 'fifi',
50 loulou: 'picsou'
51 }
52
53 for (const path of basePaths) {
54 const res = await makePostBodyRequest({
55 url: server.url,
56 path: path + 'form/post/mirror',
57 fields: body,
58 statusCodeExpected: 200
59 })
60
61 expect(res.body).to.deep.equal(body)
62 }
63 })
64
65 it('Should remove the plugin and remove the routes', async function () {
66 await uninstallPlugin({
67 url: server.url,
68 accessToken: server.accessToken,
69 npmName: 'peertube-plugin-test-five'
70 })
71
72 for (const path of basePaths) {
73 await makeGetRequest({
74 url: server.url,
75 path: path + 'ping',
76 statusCodeExpected: 404
77 })
78
79 await makePostBodyRequest({
80 url: server.url,
81 path: path + 'ping',
82 fields: {},
83 statusCodeExpected: 404
84 })
85 }
86 })
87
88 after(async function () {
89 await cleanupTests([ server ])
90 })
91})