From 58e735dd77a4ea8fc9e8da3b54fd338bf9e3558b Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 10 Mar 2023 15:08:56 +0100 Subject: Add test on AP hooks --- server/tests/fixtures/peertube-plugin-test/main.js | 12 ++++++++++++ server/tests/plugins/filter-hooks.ts | 17 +++++++++++++++++ 2 files changed, 29 insertions(+) (limited to 'server/tests') diff --git a/server/tests/fixtures/peertube-plugin-test/main.js b/server/tests/fixtures/peertube-plugin-test/main.js index f01da0226..6d06ec17d 100644 --- a/server/tests/fixtures/peertube-plugin-test/main.js +++ b/server/tests/fixtures/peertube-plugin-test/main.js @@ -207,6 +207,18 @@ async function register ({ registerHook, registerSetting, settingsManager, stora // --------------------------------------------------------------------------- + registerHook({ + target: 'filter:activity-pub.activity.context.build.result', + handler: context => context.concat([ 'https://example.com/new-context' ]) + }) + + registerHook({ + target: 'filter:activity-pub.video.json-ld.build.result', + handler: (jsonld, { video }) => ({ ...jsonld, videoName: video.name }) + }) + + // --------------------------------------------------------------------------- + registerHook({ target: 'filter:api.video-threads.list.params', handler: obj => addToCount(obj) diff --git a/server/tests/plugins/filter-hooks.ts b/server/tests/plugins/filter-hooks.ts index a7e052d06..ab3a6a093 100644 --- a/server/tests/plugins/filter-hooks.ts +++ b/server/tests/plugins/filter-hooks.ts @@ -14,6 +14,7 @@ import { cleanupTests, createMultipleServers, doubleFollow, + makeActivityPubGetRequest, makeGetRequest, makeRawRequest, PeerTubeServer, @@ -846,6 +847,22 @@ describe('Test plugin filter hooks', function () { }) }) + describe('Activity Pub', function () { + + it('Should run filter:activity-pub.activity.context.build.result', async function () { + const { body } = await makeActivityPubGetRequest(servers[0].url, '/w/' + videoUUID) + expect(body.type).to.equal('Video') + + expect(body['@context'].some(c => c === 'https://example.com/new-context')).to.be.true + }) + + it('Should run filter:activity-pub.video.json-ld.build.result', async function () { + const { body } = await makeActivityPubGetRequest(servers[0].url, '/w/' + videoUUID) + expect(body.name).to.equal('default video 0') + expect(body.videoName).to.equal('default video 0') + }) + }) + after(async function () { await cleanupTests(servers) }) -- cgit v1.2.3