Files
payload/test/hooks/config.ts
Alessio Gravili f6adbae0c7 feat: collection, global and field props for hooks, fix request context initialization, add context to global hooks (#3780)
* feat: pass collection, global and field props to collection, global and field hooks - where applicable

* fix: initial request context not set for all operations

* chore: add tests which check the collection prop for collection hooks

* feat: add context to props of global hooks

* chore: add global tests for global and field props

* chore: int tests: use JSON instead of object hashes
2023-10-21 11:40:57 +02:00

48 lines
1.5 KiB
TypeScript

import type { SanitizedConfig } from '../../packages/payload/src/config/types'
import { buildConfigWithDefaults } from '../buildConfigWithDefaults'
import AfterOperation from './collections/AfterOperation'
import ChainingHooks from './collections/ChainingHooks'
import ContextHooks from './collections/ContextHooks'
import { DataHooks } from './collections/Data'
import Hooks, { hooksSlug } from './collections/Hook'
import NestedAfterReadHooks from './collections/NestedAfterReadHooks'
import Relations from './collections/Relations'
import TransformHooks from './collections/Transform'
import Users, { seedHooksUsers } from './collections/Users'
import { DataHooksGlobal } from './globals/Data'
export const HooksConfig: Promise<SanitizedConfig> = buildConfigWithDefaults({
collections: [
AfterOperation,
ContextHooks,
TransformHooks,
Hooks,
NestedAfterReadHooks,
ChainingHooks,
Relations,
Users,
DataHooks,
],
globals: [DataHooksGlobal],
onInit: async (payload) => {
await seedHooksUsers(payload)
await payload.create({
collection: hooksSlug,
data: {
check: 'update',
fieldBeforeValidate: false,
collectionBeforeValidate: false,
fieldBeforeChange: false,
collectionBeforeChange: false,
fieldAfterChange: false,
collectionAfterChange: false,
collectionBeforeRead: false,
fieldAfterRead: false,
collectionAfterRead: false,
},
})
},
})
export default HooksConfig