mirror of
https://github.com/logto-io/logto.git
synced 2024-12-30 20:33:54 -05:00
refactor: use db native enum for hook event
This commit is contained in:
parent
34bb0de7a9
commit
6473df99d2
5 changed files with 9 additions and 13 deletions
|
@ -1,5 +1,5 @@
|
|||
import type { Application, Hook, Passcode, Resource, Role, Setting } from '@logto/schemas';
|
||||
import { HookEvent, ApplicationType, PasscodeType } from '@logto/schemas';
|
||||
import { HookEventType, ApplicationType, PasscodeType } from '@logto/schemas';
|
||||
|
||||
export * from './connector';
|
||||
export * from './sign-in-experience';
|
||||
|
@ -38,7 +38,7 @@ export const mockRole: Role = {
|
|||
|
||||
export const mockHook: Readonly<Hook> = Object.freeze({
|
||||
id: 'logto_hook',
|
||||
event: HookEvent.PostSignIn,
|
||||
event: HookEventType.PostSignIn,
|
||||
config: {
|
||||
url: 'https://foo.bar',
|
||||
headers: {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import type { Hook, CreateHook, HookConfig } from '@logto/schemas';
|
||||
import { HookEvent } from '@logto/schemas';
|
||||
import { HookEventType } from '@logto/schemas';
|
||||
|
||||
import { mockHook } from '@/__mocks__';
|
||||
import { createRequester } from '@/utils/test-utils';
|
||||
|
@ -41,7 +41,7 @@ describe('hook routes', () => {
|
|||
});
|
||||
|
||||
it('POST /hooks', async () => {
|
||||
const event = HookEvent.PostChangePassword;
|
||||
const event = HookEventType.PostChangePassword;
|
||||
|
||||
const response = await hookRequest.post('/hooks').send({ event, config: mockHook.config });
|
||||
|
||||
|
@ -56,7 +56,7 @@ describe('hook routes', () => {
|
|||
|
||||
it('POST /hooks should throw with invalid input body', async () => {
|
||||
const id = 'a_good_hook';
|
||||
const event = HookEvent.PostChangePassword;
|
||||
const event = HookEventType.PostChangePassword;
|
||||
|
||||
await expect(hookRequest.post('/hooks')).resolves.toHaveProperty('status', 400);
|
||||
await expect(hookRequest.post('/hooks').send({ id })).resolves.toHaveProperty('status', 400);
|
||||
|
@ -71,7 +71,7 @@ describe('hook routes', () => {
|
|||
});
|
||||
|
||||
it('PATCH /hooks/:id', async () => {
|
||||
const event = HookEvent.PostChangePassword;
|
||||
const event = HookEventType.PostChangePassword;
|
||||
const config: Partial<HookConfig> = { url: 'https://bar.baz' };
|
||||
|
||||
const response = await hookRequest.patch('/hooks/foo').send({ event, config });
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
export enum HookEvent {
|
||||
PostSignIn = 'PostSignIn',
|
||||
PostSignOut = 'PostSignOut',
|
||||
PostChangePassword = 'PostChangePassword',
|
||||
}
|
|
@ -3,4 +3,3 @@ export * from './log';
|
|||
export * from './oidc-config';
|
||||
export * from './user';
|
||||
export * from './logto-config';
|
||||
export * from './hook';
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
create type hook_event_type as enum ('PostSignIn', 'PostSignOut', 'PostChangePassword');
|
||||
|
||||
create table hooks (
|
||||
id varchar(128) not null,
|
||||
event varchar(128) not null,
|
||||
event hook_event_type not null,
|
||||
config jsonb /* @use HookConfig */ not null,
|
||||
created_at timestamptz not null default(now()),
|
||||
primary key (id)
|
||||
|
|
Loading…
Reference in a new issue