]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Add test on AP hooks
authorChocobozzz <me@florianbigard.com>
Fri, 10 Mar 2023 14:08:56 +0000 (15:08 +0100)
committerChocobozzz <me@florianbigard.com>
Fri, 10 Mar 2023 14:45:52 +0000 (15:45 +0100)
client/src/app/+videos/+video-edit/shared/video-edit.component.ts
server/lib/activitypub/send/send-update.ts
server/models/video/video.ts
server/tests/fixtures/peertube-plugin-test/main.js
server/tests/plugins/filter-hooks.ts
shared/models/plugins/server/server-hook.model.ts

index e3bd5fe71e743ec447488686fd242b82ef474a9c..2bc0e6bb415ecc49603a6b06679764a17be48d76 100644 (file)
@@ -240,11 +240,11 @@ export class VideoEditComponent implements OnInit, OnDestroy {
       this.schedulerInterval = setInterval(() => this.minScheduledDate = new Date(), 1000 * 60) // Update every minute
     })
 
-    const updateForm = (values: any) => {
+    const updateFormForPlugins = (values: any) => {
       this.form.patchValue(values)
       this.cd.detectChanges()
     }
-    this.hooks.runAction('action:video-edit.init', 'video-edit', { type: this.type, updateForm })
+    this.hooks.runAction('action:video-edit.init', 'video-edit', { type: this.type, updateForm: updateFormForPlugins })
 
     this.form.valueChanges.subscribe(() => {
       this.hooks.runAction('action:video-edit.form.updated', 'video-edit', { type: this.type, formValues: this.form.value })
index 5a66294e6a6104d26b992223c652dff3e36b0586..379e2d9d84b544643233afb33e33826672fc2a93 100644 (file)
@@ -59,7 +59,7 @@ async function sendUpdateActor (accountOrChannel: MChannelDefault | MAccountDefa
   logger.info('Creating job to update actor %s.', byActor.url)
 
   const url = getUpdateActivityPubUrl(byActor.url, byActor.updatedAt.toISOString())
-  const accountOrChannelObject = (accountOrChannel as any).toActivityPubObject() // FIXME: typescript bug?
+  const accountOrChannelObject = await (accountOrChannel as any).toActivityPubObject() // FIXME: typescript bug?
   const audience = getAudience(byActor)
   const updateActivity = buildUpdateActivity(url, byActor, accountOrChannelObject, audience)
 
index 7fe2ec2938795cae5c6d0cbebe5f10e2f2384dce..aa9c62e36e5d1847377bdce41ce8a53e91e44568 100644 (file)
@@ -1717,7 +1717,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
   toActivityPubObject (this: MVideoAP): Promise<VideoObject> {
     return Hooks.wrapObject(
       videoModelToActivityPubObject(this),
-      'filter:activity-pub.video.jsonld.build.result',
+      'filter:activity-pub.video.json-ld.build.result',
       { video: this }
     )
   }
index f01da0226f78ae22bb239523bc7a87dd670467f6..6d06ec17d1a8f3e7d3dc33d926999418d6fcac0a 100644 (file)
@@ -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)
index a7e052d06c5fb6edaa5d8e3cd0f87e5afcf67dde..ab3a6a093be41711ebb80a7ca0d734da691ae1e2 100644 (file)
@@ -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)
   })
index 7881beaa29011f77d4f5e91d2cae0a81f3f677a8..ca83672d02e0edf9f094339fef54d3b4e3b8a7b6 100644 (file)
@@ -119,7 +119,7 @@ export const serverFilterHookObject = {
 
   // Filter the result of video JSON LD builder
   // You may also need to use filter:activity-pub.activity.context.build.result to also update JSON LD context
-  'filter:activity-pub.video.jsonld.build.result': true
+  'filter:activity-pub.video.json-ld.build.result': true
 }
 
 export type ServerFilterHookName = keyof typeof serverFilterHookObject