]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Add overviews filter hook tests
authorChocobozzz <me@florianbigard.com>
Wed, 21 Jul 2021 14:13:20 +0000 (16:13 +0200)
committerChocobozzz <me@florianbigard.com>
Wed, 21 Jul 2021 14:13:20 +0000 (16:13 +0200)
server/controllers/api/overviews.ts
server/tests/fixtures/peertube-plugin-test/main.js
server/tests/plugins/filter-hooks.ts

index 727ed66d7a15c60acb3ab9165d5b8cb8b411bb24..2dfac15ef3019497ebf6f5c706db478efbe309fc 100644 (file)
@@ -109,7 +109,7 @@ async function getVideos (
   res: express.Response,
   where: { videoChannelId?: number, tagsOneOf?: string[], categoryOneOf?: number[] }
 ) {
-  let query = Object.assign({
+  const query = await Hooks.wrapObject({
     start: 0,
     count: 12,
     sort: '-createdAt',
@@ -117,10 +117,10 @@ async function getVideos (
     nsfw: buildNSFWFilter(res),
     user: res.locals.oauth ? res.locals.oauth.token.User : undefined,
     withFiles: false,
-    countVideos: false
-  }, where)
+    countVideos: false,
 
-  query = await Hooks.wrapObject(query, 'filter:api.overviews.videos.list.params')
+    ...where
+  }, 'filter:api.overviews.videos.list.params')
 
   const { data } = await Hooks.wrapPromiseFun(
     VideoModel.listForApi,
index f8e6f0b98129406ce82742b57abd0fc684afb2ff..db405ff31e16b01c6380c17935c7fd5510aaf7f7 100644 (file)
@@ -234,7 +234,7 @@ async function register ({ registerHook, registerSetting, settingsManager, stora
   })
 
   {
-    const searchHooks = [
+    const filterHooks = [
       'filter:api.search.videos.local.list.params',
       'filter:api.search.videos.local.list.result',
       'filter:api.search.videos.index.list.params',
@@ -246,10 +246,13 @@ async function register ({ registerHook, registerSetting, settingsManager, stora
       'filter:api.search.video-playlists.local.list.params',
       'filter:api.search.video-playlists.local.list.result',
       'filter:api.search.video-playlists.index.list.params',
-      'filter:api.search.video-playlists.index.list.result'
+      'filter:api.search.video-playlists.index.list.result',
+
+      'filter:api.overviews.videos.list.params',
+      'filter:api.overviews.videos.list.result'
     ]
 
-    for (const h of searchHooks) {
+    for (const h of filterHooks) {
       registerHook({
         target: h,
         handler: (obj) => {
index c00ac8f91701a9d7cfd20a1efe21fa00fba870dc..02915f08cb2f8199f383cdb778b618544f014c68 100644 (file)
@@ -255,6 +255,14 @@ describe('Test plugin filter hooks', function () {
     expect(thread.comment.text.endsWith(' <3')).to.be.true
   })
 
+  it('Should run filter:api.overviews.videos.list.{params,result}', async function () {
+    await servers[0].overviews.getVideos({ page: 1 })
+
+    // 3 because we get 3 samples per page
+    await servers[0].servers.waitUntilLog('Run hook filter:api.overviews.videos.list.params', 3)
+    await servers[0].servers.waitUntilLog('Run hook filter:api.overviews.videos.list.result', 3)
+  })
+
   describe('Should run filter:video.auto-blacklist.result', function () {
 
     async function checkIsBlacklisted (id: number | string, value: boolean) {