diff --git a/packages/core/src/libraries/hook/utils.ts b/packages/core/src/libraries/hook/utils.ts index 6e296d771..fe30e3045 100644 --- a/packages/core/src/libraries/hook/utils.ts +++ b/packages/core/src/libraries/hook/utils.ts @@ -1,5 +1,6 @@ import { ApplicationType, + InteractionHookEvent, managementApiHooksRegistration, type HookConfig, type HookEvent, @@ -48,17 +49,13 @@ export const sendWebhookRequest = async ({ }; export const generateHookTestPayload = (hookId: string, event: HookEvent): HookEventPayload => { - const fakeUserId = 'fake-user-id'; + const fakeUserId = 'fake-id'; const now = new Date(); - return { - hookId, - event, - createdAt: now.toISOString(), + const interactionHookContext = { sessionId: 'fake-session-id', - userAgent: 'fake-user-agent', - userId: fakeUserId, userIp: 'fake-user-ip', + userId: fakeUserId, user: { id: fakeUserId, username: 'fake-user', @@ -86,6 +83,26 @@ export const generateHookTestPayload = (hookId: string, event: HookEvent): HookE description: 'Fake application data for testing', }, }; + + const dataHookContext = { + path: '/fake-path/:id', + method: 'POST', + status: 200, + params: { id: fakeUserId }, + data: { result: 'success' }, + }; + + const isInteractionHookEvent = Object.values(InteractionHookEvent).includes(event); + + return { + hookId, + event, + createdAt: now.toISOString(), + sessionId: 'fake-session-id', + userAgent: 'fake-user-agent', + ip: 'fake-user-ip', + ...(isInteractionHookEvent ? interactionHookContext : dataHookContext), + }; }; export const buildManagementApiDataHookRegistrationKey = (