0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-20 21:32:31 -05:00

feat(core): update test hook payload (#5883)

update test hook payload to be dynamic based on InteractionHook or DataHook event
This commit is contained in:
simeng-li 2024-05-17 17:40:44 +08:00 committed by GitHub
parent 88f568f3c5
commit 330c6bd6eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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<string>(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 = (