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:
parent
88f568f3c5
commit
330c6bd6eb
1 changed files with 24 additions and 7 deletions
|
@ -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 = (
|
||||
|
|
Loading…
Add table
Reference in a new issue