aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/fixtures
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-07-19 17:30:41 +0200
committerChocobozzz <chocobozzz@cpy.re>2019-07-24 10:58:16 +0200
commit89cd12756035a146bbcc4db78cd3cd64f2f3d88d (patch)
tree896cd9fca1e0baa969b1f7a5b398ec1602761661 /server/tests/fixtures
parent09071200c73f5358e1d0bfb61a274e4f2c4ec52b (diff)
downloadPeerTube-89cd12756035a146bbcc4db78cd3cd64f2f3d88d.tar.gz
PeerTube-89cd12756035a146bbcc4db78cd3cd64f2f3d88d.tar.zst
PeerTube-89cd12756035a146bbcc4db78cd3cd64f2f3d88d.zip
Add hook filters tests
Diffstat (limited to 'server/tests/fixtures')
-rw-r--r--server/tests/fixtures/peertube-plugin-test-two/main.js21
-rw-r--r--server/tests/fixtures/peertube-plugin-test-two/package.json19
-rw-r--r--server/tests/fixtures/peertube-plugin-test/main.js62
3 files changed, 84 insertions, 18 deletions
diff --git a/server/tests/fixtures/peertube-plugin-test-two/main.js b/server/tests/fixtures/peertube-plugin-test-two/main.js
new file mode 100644
index 000000000..71c11b2ba
--- /dev/null
+++ b/server/tests/fixtures/peertube-plugin-test-two/main.js
@@ -0,0 +1,21 @@
1async function register ({ registerHook, registerSetting, settingsManager, storageManager, peertubeHelpers }) {
2 registerHook({
3 target: 'filter:api.videos.list.params',
4 handler: obj => addToCount(obj)
5 })
6}
7
8async function unregister () {
9 return
10}
11
12module.exports = {
13 register,
14 unregister
15}
16
17// ############################################################################
18
19function addToCount (obj) {
20 return Object.assign({}, obj, { count: obj.count + 1 })
21}
diff --git a/server/tests/fixtures/peertube-plugin-test-two/package.json b/server/tests/fixtures/peertube-plugin-test-two/package.json
new file mode 100644
index 000000000..52ebb5ac1
--- /dev/null
+++ b/server/tests/fixtures/peertube-plugin-test-two/package.json
@@ -0,0 +1,19 @@
1{
2 "name": "peertube-plugin-test-two",
3 "version": "0.0.1",
4 "description": "Plugin test 2",
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}
diff --git a/server/tests/fixtures/peertube-plugin-test/main.js b/server/tests/fixtures/peertube-plugin-test/main.js
index fae0ef948..c5317ab41 100644
--- a/server/tests/fixtures/peertube-plugin-test/main.js
+++ b/server/tests/fixtures/peertube-plugin-test/main.js
@@ -1,23 +1,52 @@
1async function register ({ registerHook, registerSetting, settingsManager, storageManager }) { 1async function register ({ registerHook, registerSetting, settingsManager, storageManager, peertubeHelpers }) {
2 const defaultAdmin = 'PeerTube admin' 2 const actionHooks = [
3 'action:application.listening',
4
5 'action:api.video.updated',
6 'action:api.video.deleted',
7 'action:api.video.uploaded',
8 'action:api.video.viewed',
9
10 'action:api.video-thread.created',
11 'action:api.video-comment-reply.created',
12 'action:api.video-comment.deleted'
13 ]
14
15 for (const h of actionHooks) {
16 registerHook({
17 target: h,
18 handler: () => peertubeHelpers.logger.debug('Run hook %s.', h)
19 })
20 }
3 21
4 registerHook({ 22 registerHook({
5 target: 'action:application.listening', 23 target: 'filter:api.videos.list.params',
6 handler: () => displayHelloWorld(settingsManager, defaultAdmin) 24 handler: obj => addToCount(obj)
7 }) 25 })
8 26
9 registerSetting({ 27 registerHook({
10 name: 'admin-name', 28 target: 'filter:api.videos.list.result',
11 label: 'Admin name', 29 handler: obj => ({ data: obj.data, total: obj.total + 1 })
12 type: 'input',
13 default: defaultAdmin
14 }) 30 })
15 31
16 const value = await storageManager.getData('toto') 32 registerHook({
17 console.log(value) 33 target: 'filter:api.video.get.result',
18 console.log(value.coucou) 34 handler: video => {
35 video.name += ' <3'
19 36
20 await storageManager.storeData('toto', { coucou: 'hello' + new Date() }) 37 return video
38 }
39 })
40
41 registerHook({
42 target: 'filter:api.video.upload.accept.result',
43 handler: ({ accepted }, { videoBody }) => {
44 if (accepted !== false) return { accepted: true }
45 if (videoBody.name.indexOf('bad word') !== -1) return { accepted: false, errorMessage: 'bad word '}
46
47 return { accepted: true }
48 }
49 })
21} 50}
22 51
23async function unregister () { 52async function unregister () {
@@ -31,9 +60,6 @@ module.exports = {
31 60
32// ############################################################################ 61// ############################################################################
33 62
34async function displayHelloWorld (settingsManager, defaultAdmin) { 63function addToCount (obj) {
35 let value = await settingsManager.getSetting('admin-name') 64 return Object.assign({}, obj, { count: obj.count + 1 })
36 if (!value) value = defaultAdmin
37
38 console.log('hello world ' + value)
39} 65}