aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-03-24 09:16:48 +0100
committerChocobozzz <me@florianbigard.com>2021-03-24 18:18:41 +0100
commit74a4d53110ebc073dafeb74a7ac815fe00f4706b (patch)
treec09797245d4ea1093b7bc7e61f925aef9e554b02 /server/tests
parenteebd9838f067369031af9770b899f75f30810549 (diff)
downloadPeerTube-74a4d53110ebc073dafeb74a7ac815fe00f4706b.tar.gz
PeerTube-74a4d53110ebc073dafeb74a7ac815fe00f4706b.tar.zst
PeerTube-74a4d53110ebc073dafeb74a7ac815fe00f4706b.zip
Add server hooks for search endpoint
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/fixtures/peertube-plugin-test/main.js24
-rw-r--r--server/tests/plugins/filter-hooks.ts62
2 files changed, 85 insertions, 1 deletions
diff --git a/server/tests/fixtures/peertube-plugin-test/main.js b/server/tests/fixtures/peertube-plugin-test/main.js
index dfcc874d4..ee0bc39f3 100644
--- a/server/tests/fixtures/peertube-plugin-test/main.js
+++ b/server/tests/fixtures/peertube-plugin-test/main.js
@@ -230,6 +230,30 @@ async function register ({ registerHook, registerSetting, settingsManager, stora
230 } 230 }
231 } 231 }
232 }) 232 })
233
234 {
235 const searchHooks = [
236 'filter:api.search.videos.local.list.params',
237 'filter:api.search.videos.local.list.result',
238 'filter:api.search.videos.index.list.params',
239 'filter:api.search.videos.index.list.result',
240 'filter:api.search.video-channels.local.list.params',
241 'filter:api.search.video-channels.local.list.result',
242 'filter:api.search.video-channels.index.list.params',
243 'filter:api.search.video-channels.index.list.result',
244 ]
245
246 for (const h of searchHooks) {
247 registerHook({
248 target: h,
249 handler: (obj) => {
250 peertubeHelpers.logger.debug('Run hook %s.', h)
251
252 return obj
253 }
254 })
255 }
256 }
233} 257}
234 258
235async function unregister () { 259async function unregister () {
diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts
index be47b20ba..6f7fec767 100644
--- a/server/tests/plugins/filter-hooks.ts
+++ b/server/tests/plugins/filter-hooks.ts
@@ -7,6 +7,7 @@ import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-code
7import { 7import {
8 addVideoCommentReply, 8 addVideoCommentReply,
9 addVideoCommentThread, 9 addVideoCommentThread,
10 advancedVideosSearch,
10 createLive, 11 createLive,
11 createVideoPlaylist, 12 createVideoPlaylist,
12 doubleFollow, 13 doubleFollow,
@@ -25,6 +26,7 @@ import {
25 installPlugin, 26 installPlugin,
26 makeRawRequest, 27 makeRawRequest,
27 registerUser, 28 registerUser,
29 searchVideo,
28 setAccessTokensToServers, 30 setAccessTokensToServers,
29 setDefaultVideoChannel, 31 setDefaultVideoChannel,
30 updateCustomSubConfig, 32 updateCustomSubConfig,
@@ -33,7 +35,7 @@ import {
33 uploadVideoAndGetId, 35 uploadVideoAndGetId,
34 waitJobs 36 waitJobs
35} from '../../../shared/extra-utils' 37} from '../../../shared/extra-utils'
36import { cleanupTests, flushAndRunMultipleServers, ServerInfo } from '../../../shared/extra-utils/server/servers' 38import { cleanupTests, flushAndRunMultipleServers, ServerInfo, waitUntilLog } from '../../../shared/extra-utils/server/servers'
37import { getGoodVideoUrl, getMyVideoImports, importVideo } from '../../../shared/extra-utils/videos/video-imports' 39import { getGoodVideoUrl, getMyVideoImports, importVideo } from '../../../shared/extra-utils/videos/video-imports'
38import { 40import {
39 VideoDetails, 41 VideoDetails,
@@ -44,6 +46,7 @@ import {
44 VideoPrivacy 46 VideoPrivacy
45} from '../../../shared/models/videos' 47} from '../../../shared/models/videos'
46import { VideoCommentThreadTree } from '../../../shared/models/videos/video-comment.model' 48import { VideoCommentThreadTree } from '../../../shared/models/videos/video-comment.model'
49import { advancedVideoChannelSearch } from '@shared/extra-utils/search/video-channels'
47 50
48const expect = chai.expect 51const expect = chai.expect
49 52
@@ -468,6 +471,63 @@ describe('Test plugin filter hooks', function () {
468 }) 471 })
469 }) 472 })
470 473
474 describe('Search filters', function () {
475
476 before(async function () {
477 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, {
478 search: {
479 searchIndex: {
480 enabled: true,
481 isDefaultSearch: false,
482 disableLocalSearch: false
483 }
484 }
485 })
486 })
487
488 it('Should run filter:api.search.videos.local.list.{params,result}', async function () {
489 await advancedVideosSearch(servers[0].url, {
490 search: 'Sun Quan'
491 })
492
493 await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.local.list.params', 1)
494 await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.local.list.result', 1)
495 })
496
497 it('Should run filter:api.search.videos.index.list.{params,result}', async function () {
498 await advancedVideosSearch(servers[0].url, {
499 search: 'Sun Quan',
500 searchTarget: 'search-index'
501 })
502
503 await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.local.list.params', 1)
504 await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.local.list.result', 1)
505 await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.index.list.params', 1)
506 await waitUntilLog(servers[0], 'Run hook filter:api.search.videos.index.list.result', 1)
507 })
508
509 it('Should run filter:api.search.video-channels.local.list.{params,result}', async function () {
510 await advancedVideoChannelSearch(servers[0].url, {
511 search: 'Sun Ce'
512 })
513
514 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.local.list.params', 1)
515 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.local.list.result', 1)
516 })
517
518 it('Should run filter:api.search.video-channels.index.list.{params,result}', async function () {
519 await advancedVideoChannelSearch(servers[0].url, {
520 search: 'Sun Ce',
521 searchTarget: 'search-index'
522 })
523
524 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.local.list.params', 1)
525 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.local.list.result', 1)
526 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.index.list.params', 1)
527 await waitUntilLog(servers[0], 'Run hook filter:api.search.video-channels.index.list.result', 1)
528 })
529 })
530
471 after(async function () { 531 after(async function () {
472 await cleanupTests(servers) 532 await cleanupTests(servers)
473 }) 533 })