0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-27 21:39:16 -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 { import {
ApplicationType, ApplicationType,
InteractionHookEvent,
managementApiHooksRegistration, managementApiHooksRegistration,
type HookConfig, type HookConfig,
type HookEvent, type HookEvent,
@ -48,17 +49,13 @@ export const sendWebhookRequest = async ({
}; };
export const generateHookTestPayload = (hookId: string, event: HookEvent): HookEventPayload => { export const generateHookTestPayload = (hookId: string, event: HookEvent): HookEventPayload => {
const fakeUserId = 'fake-user-id'; const fakeUserId = 'fake-id';
const now = new Date(); const now = new Date();
return { const interactionHookContext = {
hookId,
event,
createdAt: now.toISOString(),
sessionId: 'fake-session-id', sessionId: 'fake-session-id',
userAgent: 'fake-user-agent',
userId: fakeUserId,
userIp: 'fake-user-ip', userIp: 'fake-user-ip',
userId: fakeUserId,
user: { user: {
id: fakeUserId, id: fakeUserId,
username: 'fake-user', username: 'fake-user',
@ -86,6 +83,26 @@ export const generateHookTestPayload = (hookId: string, event: HookEvent): HookE
description: 'Fake application data for testing', 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 = ( export const buildManagementApiDataHookRegistrationKey = (