aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-12-08 10:30:33 +0100
committerChocobozzz <chocobozzz@cpy.re>2020-12-08 10:33:23 +0100
commit38267c0c8aa80f974a2c0b4c2bd33c8d8008ac94 (patch)
treedd99242abdd5a02de272be0f06ecfe03edadc575 /server/tests
parent1bfc07e4cca1464c87c317060eb86742344467a6 (diff)
downloadPeerTube-38267c0c8aa80f974a2c0b4c2bd33c8d8008ac94.tar.gz
PeerTube-38267c0c8aa80f974a2c0b4c2bd33c8d8008ac94.tar.zst
PeerTube-38267c0c8aa80f974a2c0b4c2bd33c8d8008ac94.zip
Use dedicated hooks for account/channel videos
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/fixtures/peertube-plugin-test/main.js28
-rw-r--r--server/tests/plugins/filter-hooks.ts30
2 files changed, 54 insertions, 4 deletions
diff --git a/server/tests/fixtures/peertube-plugin-test/main.js b/server/tests/fixtures/peertube-plugin-test/main.js
index 322c0610c..e5a9f8df5 100644
--- a/server/tests/fixtures/peertube-plugin-test/main.js
+++ b/server/tests/fixtures/peertube-plugin-test/main.js
@@ -40,6 +40,26 @@ async function register ({ registerHook, registerSetting, settingsManager, stora
40 }) 40 })
41 41
42 registerHook({ 42 registerHook({
43 target: 'filter:api.accounts.videos.list.params',
44 handler: obj => addToCount(obj)
45 })
46
47 registerHook({
48 target: 'filter:api.accounts.videos.list.result',
49 handler: obj => addToTotal(obj, 2)
50 })
51
52 registerHook({
53 target: 'filter:api.video-channels.videos.list.params',
54 handler: obj => addToCount(obj, 3)
55 })
56
57 registerHook({
58 target: 'filter:api.video-channels.videos.list.result',
59 handler: obj => addToTotal(obj, 3)
60 })
61
62 registerHook({
43 target: 'filter:api.video.get.result', 63 target: 'filter:api.video.get.result',
44 handler: video => { 64 handler: video => {
45 video.name += ' <3' 65 video.name += ' <3'
@@ -167,14 +187,14 @@ module.exports = {
167 187
168// ############################################################################ 188// ############################################################################
169 189
170function addToCount (obj) { 190function addToCount (obj, amount = 1) {
171 return Object.assign({}, obj, { count: obj.count + 1 }) 191 return Object.assign({}, obj, { count: obj.count + amount })
172} 192}
173 193
174function addToTotal (result) { 194function addToTotal (result, amount = 1) {
175 return { 195 return {
176 data: result.data, 196 data: result.data,
177 total: result.total + 1 197 total: result.total + amount
178 } 198 }
179} 199}
180 200
diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts
index 9939b8e6e..3a5c7aa62 100644
--- a/server/tests/plugins/filter-hooks.ts
+++ b/server/tests/plugins/filter-hooks.ts
@@ -8,9 +8,11 @@ import {
8 addVideoCommentThread, 8 addVideoCommentThread,
9 createLive, 9 createLive,
10 doubleFollow, 10 doubleFollow,
11 getAccountVideos,
11 getConfig, 12 getConfig,
12 getPluginTestPath, 13 getPluginTestPath,
13 getVideo, 14 getVideo,
15 getVideoChannelVideos,
14 getVideoCommentThreads, 16 getVideoCommentThreads,
15 getVideosList, 17 getVideosList,
16 getVideosListPagination, 18 getVideosListPagination,
@@ -90,6 +92,34 @@ describe('Test plugin filter hooks', function () {
90 expect(res.body.total).to.equal(11) 92 expect(res.body.total).to.equal(11)
91 }) 93 })
92 94
95 it('Should run filter:api.accounts.videos.list.params', async function () {
96 const res = await getAccountVideos(servers[0].url, servers[0].accessToken, 'root', 0, 2)
97
98 // 1 plugin do +1 to the count parameter
99 expect(res.body.data).to.have.lengthOf(3)
100 })
101
102 it('Should run filter:api.accounts.videos.list.result', async function () {
103 const res = await getAccountVideos(servers[0].url, servers[0].accessToken, 'root', 0, 2)
104
105 // Plugin do +2 to the total result
106 expect(res.body.total).to.equal(12)
107 })
108
109 it('Should run filter:api.video-channels.videos.list.params', async function () {
110 const res = await getVideoChannelVideos(servers[0].url, servers[0].accessToken, 'root_channel', 0, 2)
111
112 // 1 plugin do +3 to the count parameter
113 expect(res.body.data).to.have.lengthOf(5)
114 })
115
116 it('Should run filter:api.video-channels.videos.list.result', async function () {
117 const res = await getAccountVideos(servers[0].url, servers[0].accessToken, 'root_channel', 0, 2)
118
119 // Plugin do +3 to the total result
120 expect(res.body.total).to.equal(13)
121 })
122
93 it('Should run filter:api.video.get.result', async function () { 123 it('Should run filter:api.video.get.result', async function () {
94 const res = await getVideo(servers[0].url, videoUUID) 124 const res = await getVideo(servers[0].url, videoUUID)
95 125