diff options
author | Chocobozzz <me@florianbigard.com> | 2022-08-03 11:17:57 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-08-03 11:24:42 +0200 |
commit | 0260dc8aca952f9412a8620e433b9e16e675696e (patch) | |
tree | 6f3e6dde7242a4f61aff99fd4c35b4e7f5076314 /server/tests | |
parent | 9ca0f688e9e8558233f1a538b96a43da44e35353 (diff) | |
download | PeerTube-0260dc8aca952f9412a8620e433b9e16e675696e.tar.gz PeerTube-0260dc8aca952f9412a8620e433b9e16e675696e.tar.zst PeerTube-0260dc8aca952f9412a8620e433b9e16e675696e.zip |
Add channel server hooks
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/fixtures/peertube-plugin-test/main.js | 27 | ||||
-rw-r--r-- | server/tests/plugins/action-hooks.ts | 33 | ||||
-rw-r--r-- | server/tests/plugins/filter-hooks.ts | 24 |
3 files changed, 83 insertions, 1 deletions
diff --git a/server/tests/fixtures/peertube-plugin-test/main.js b/server/tests/fixtures/peertube-plugin-test/main.js index c395ac7aa..8d7584eba 100644 --- a/server/tests/fixtures/peertube-plugin-test/main.js +++ b/server/tests/fixtures/peertube-plugin-test/main.js | |||
@@ -7,6 +7,10 @@ async function register ({ registerHook, registerSetting, settingsManager, stora | |||
7 | 'action:api.video.uploaded', | 7 | 'action:api.video.uploaded', |
8 | 'action:api.video.viewed', | 8 | 'action:api.video.viewed', |
9 | 9 | ||
10 | 'action:api.video-channel.created', | ||
11 | 'action:api.video-channel.updated', | ||
12 | 'action:api.video-channel.deleted', | ||
13 | |||
10 | 'action:api.live-video.created', | 14 | 'action:api.live-video.created', |
11 | 15 | ||
12 | 'action:api.video-thread.created', | 16 | 'action:api.video-thread.created', |
@@ -93,6 +97,29 @@ async function register ({ registerHook, registerSetting, settingsManager, stora | |||
93 | } | 97 | } |
94 | }) | 98 | }) |
95 | 99 | ||
100 | // --------------------------------------------------------------------------- | ||
101 | |||
102 | registerHook({ | ||
103 | target: 'filter:api.video-channels.list.params', | ||
104 | handler: obj => addToCount(obj, 1) | ||
105 | }) | ||
106 | |||
107 | registerHook({ | ||
108 | target: 'filter:api.video-channels.list.result', | ||
109 | handler: obj => addToTotal(obj, 1) | ||
110 | }) | ||
111 | |||
112 | registerHook({ | ||
113 | target: 'filter:api.video-channel.get.result', | ||
114 | handler: channel => { | ||
115 | channel.name += ' <3' | ||
116 | |||
117 | return channel | ||
118 | } | ||
119 | }) | ||
120 | |||
121 | // --------------------------------------------------------------------------- | ||
122 | |||
96 | for (const hook of [ 'filter:api.video.upload.accept.result', 'filter:api.live-video.create.accept.result' ]) { | 123 | for (const hook of [ 'filter:api.video.upload.accept.result', 'filter:api.live-video.create.accept.result' ]) { |
97 | registerHook({ | 124 | registerHook({ |
98 | target: hook, | 125 | target: hook, |
diff --git a/server/tests/plugins/action-hooks.ts b/server/tests/plugins/action-hooks.ts index 57ede2701..209db95a4 100644 --- a/server/tests/plugins/action-hooks.ts +++ b/server/tests/plugins/action-hooks.ts | |||
@@ -65,6 +65,39 @@ describe('Test plugin action hooks', function () { | |||
65 | 65 | ||
66 | await checkHook('action:api.video.viewed') | 66 | await checkHook('action:api.video.viewed') |
67 | }) | 67 | }) |
68 | |||
69 | it('Should run action:api.video.deleted', async function () { | ||
70 | await servers[0].videos.remove({ id: videoUUID }) | ||
71 | |||
72 | await checkHook('action:api.video.deleted') | ||
73 | }) | ||
74 | |||
75 | after(async function () { | ||
76 | const { uuid } = await servers[0].videos.quickUpload({ name: 'video' }) | ||
77 | videoUUID = uuid | ||
78 | }) | ||
79 | }) | ||
80 | |||
81 | describe('Video channel hooks', function () { | ||
82 | const channelName = 'my_super_channel' | ||
83 | |||
84 | it('Should run action:api.video-channel.created', async function () { | ||
85 | await servers[0].channels.create({ attributes: { name: channelName } }) | ||
86 | |||
87 | await checkHook('action:api.video-channel.created') | ||
88 | }) | ||
89 | |||
90 | it('Should run action:api.video-channel.updated', async function () { | ||
91 | await servers[0].channels.update({ channelName, attributes: { displayName: 'my display name' } }) | ||
92 | |||
93 | await checkHook('action:api.video-channel.updated') | ||
94 | }) | ||
95 | |||
96 | it('Should run action:api.video-channel.deleted', async function () { | ||
97 | await servers[0].channels.delete({ channelName }) | ||
98 | |||
99 | await checkHook('action:api.video-channel.deleted') | ||
100 | }) | ||
68 | }) | 101 | }) |
69 | 102 | ||
70 | describe('Live hooks', function () { | 103 | describe('Live hooks', function () { |
diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index 5ed24a58e..015459ead 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts | |||
@@ -295,7 +295,7 @@ describe('Test plugin filter hooks', function () { | |||
295 | await servers[0].servers.waitUntilLog('Run hook filter:api.overviews.videos.list.result', 3) | 295 | await servers[0].servers.waitUntilLog('Run hook filter:api.overviews.videos.list.result', 3) |
296 | }) | 296 | }) |
297 | 297 | ||
298 | describe('Should run filter:video.auto-blacklist.result', function () { | 298 | describe('filter:video.auto-blacklist.result', function () { |
299 | 299 | ||
300 | async function checkIsBlacklisted (id: number | string, value: boolean) { | 300 | async function checkIsBlacklisted (id: number | string, value: boolean) { |
301 | const video = await servers[0].videos.getWithToken({ id }) | 301 | const video = await servers[0].videos.getWithToken({ id }) |
@@ -691,6 +691,28 @@ describe('Test plugin filter hooks', function () { | |||
691 | }) | 691 | }) |
692 | }) | 692 | }) |
693 | 693 | ||
694 | describe('Video channel filters', async function () { | ||
695 | |||
696 | it('Should run filter:api.video-channels.list.params', async function () { | ||
697 | const { data } = await servers[0].channels.list({ start: 0, count: 0 }) | ||
698 | |||
699 | // plugin do +1 to the count parameter | ||
700 | expect(data).to.have.lengthOf(1) | ||
701 | }) | ||
702 | |||
703 | it('Should run filter:api.video-channels.list.result', async function () { | ||
704 | const { total } = await servers[0].channels.list({ start: 0, count: 1 }) | ||
705 | |||
706 | // plugin do +1 to the total parameter | ||
707 | expect(total).to.equal(4) | ||
708 | }) | ||
709 | |||
710 | it('Should run filter:api.video-channel.get.result', async function () { | ||
711 | const channel = await servers[0].channels.get({ channelName: 'root_channel' }) | ||
712 | expect(channel.displayName).to.equal('Main root channel <3') | ||
713 | }) | ||
714 | }) | ||
715 | |||
694 | after(async function () { | 716 | after(async function () { |
695 | await cleanupTests(servers) | 717 | await cleanupTests(servers) |
696 | }) | 718 | }) |