1
0
Fork 0

Add test on AP hooks

This commit is contained in:
Chocobozzz 2023-03-10 15:08:56 +01:00
parent 866b5d3f52
commit 96d00a997b
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
6 changed files with 34 additions and 5 deletions

View File

@ -240,11 +240,11 @@ export class VideoEditComponent implements OnInit, OnDestroy {
this.schedulerInterval = setInterval(() => this.minScheduledDate = new Date(), 1000 * 60) // Update every minute 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.form.patchValue(values)
this.cd.detectChanges() 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.form.valueChanges.subscribe(() => {
this.hooks.runAction('action:video-edit.form.updated', 'video-edit', { type: this.type, formValues: this.form.value }) this.hooks.runAction('action:video-edit.form.updated', 'video-edit', { type: this.type, formValues: this.form.value })

View File

@ -59,7 +59,7 @@ async function sendUpdateActor (accountOrChannel: MChannelDefault | MAccountDefa
logger.info('Creating job to update actor %s.', byActor.url) logger.info('Creating job to update actor %s.', byActor.url)
const url = getUpdateActivityPubUrl(byActor.url, byActor.updatedAt.toISOString()) 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 audience = getAudience(byActor)
const updateActivity = buildUpdateActivity(url, byActor, accountOrChannelObject, audience) const updateActivity = buildUpdateActivity(url, byActor, accountOrChannelObject, audience)

View File

@ -1717,7 +1717,7 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
toActivityPubObject (this: MVideoAP): Promise<VideoObject> { toActivityPubObject (this: MVideoAP): Promise<VideoObject> {
return Hooks.wrapObject( return Hooks.wrapObject(
videoModelToActivityPubObject(this), videoModelToActivityPubObject(this),
'filter:activity-pub.video.jsonld.build.result', 'filter:activity-pub.video.json-ld.build.result',
{ video: this } { video: this }
) )
} }

View 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({ registerHook({
target: 'filter:api.video-threads.list.params', target: 'filter:api.video-threads.list.params',
handler: obj => addToCount(obj) handler: obj => addToCount(obj)

View File

@ -14,6 +14,7 @@ import {
cleanupTests, cleanupTests,
createMultipleServers, createMultipleServers,
doubleFollow, doubleFollow,
makeActivityPubGetRequest,
makeGetRequest, makeGetRequest,
makeRawRequest, makeRawRequest,
PeerTubeServer, 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 () { after(async function () {
await cleanupTests(servers) await cleanupTests(servers)
}) })

View File

@ -119,7 +119,7 @@ export const serverFilterHookObject = {
// Filter the result of video JSON LD builder // 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 // 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 export type ServerFilterHookName = keyof typeof serverFilterHookObject