aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/fixtures/peertube-plugin-test/main.js
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/peertube-plugin-test/main.js
parent09071200c73f5358e1d0bfb61a274e4f2c4ec52b (diff)
downloadPeerTube-89cd12756035a146bbcc4db78cd3cd64f2f3d88d.tar.gz
PeerTube-89cd12756035a146bbcc4db78cd3cd64f2f3d88d.tar.zst
PeerTube-89cd12756035a146bbcc4db78cd3cd64f2f3d88d.zip
Add hook filters tests
Diffstat (limited to 'server/tests/fixtures/peertube-plugin-test/main.js')
-rw-r--r--server/tests/fixtures/peertube-plugin-test/main.js62
1 files changed, 44 insertions, 18 deletions
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}