Compare commits

...

1 Commits

Author SHA1 Message Date
Jessica Chowdhury
96c0b30d22 chore: adds test collection for autosave with hooks 2025-05-09 15:12:58 +01:00
2 changed files with 38 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
import type { CollectionConfig } from 'payload'
export const Autosave: CollectionConfig = {
slug: 'autosave-with-hooks',
versions: {
drafts: {
autosave: true,
},
},
hooks: {
beforeChange: [
({ data }) => {
data.title = 'reset from beforeChange'
return data
},
],
},
fields: [
{
name: 'title',
type: 'text',
},
{
type: 'text',
name: 'slug',
hooks: {
beforeValidate: [
() => {
return 'reset from beforeValidate'
},
],
},
},
],
}

View File

@@ -8,6 +8,7 @@ import { APIError } from 'payload'
import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js'
import { AfterOperationCollection } from './collections/AfterOperation/index.js'
import { Autosave } from './collections/AutoSave/index.js'
import { BeforeChangeHooks } from './collections/BeforeChange/index.js'
import { BeforeValidateCollection } from './collections/BeforeValidate/index.js'
import ChainingHooks from './collections/ChainingHooks/index.js'
@@ -29,6 +30,7 @@ export const HooksConfig: Promise<SanitizedConfig> = buildConfigWithDefaults({
},
},
collections: [
Autosave,
BeforeChangeHooks,
BeforeValidateCollection,
AfterOperationCollection,