0
Fork 0
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:
Gao Sun 2022-11-12 16:06:12 +08:00
parent 34bb0de7a9
commit 6473df99d2
No known key found for this signature in database
GPG key ID: 13EBE123E4773688
5 changed files with 9 additions and 13 deletions

View file

@ -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: {

View file

@ -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 });

View file

@ -1,5 +0,0 @@
export enum HookEvent {
PostSignIn = 'PostSignIn',
PostSignOut = 'PostSignOut',
PostChangePassword = 'PostChangePassword',
}

View file

@ -3,4 +3,3 @@ export * from './log';
export * from './oidc-config';
export * from './user';
export * from './logto-config';
export * from './hook';

View file

@ -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)