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