Files
payloadcms/test/_community/config.ts
2024-02-22 14:20:13 -05:00

52 lines
1.3 KiB
TypeScript

import path from 'path'
import getFileByPath from '../../packages/payload/src/uploads/getFileByPath'
import { buildConfigWithDefaults } from '../buildConfigWithDefaults'
import { devUser } from '../credentials'
import { MediaCollection } from './collections/Media'
import { PostsCollection, postsSlug } from './collections/Posts'
import { MenuGlobal } from './globals/Menu'
export default buildConfigWithDefaults({
// ...extend config here
collections: [
PostsCollection,
MediaCollection,
// ...add more collections here
],
globals: [
MenuGlobal,
// ...add more globals here
],
graphQL: {
schemaOutputFile: './test/_community/schema.graphql',
},
onInit: async (payload) => {
await payload.create({
collection: 'users',
data: {
email: devUser.email,
password: devUser.password,
},
})
await payload.create({
collection: postsSlug,
data: {
text: 'example post',
},
})
// Create image
const imageFilePath = path.resolve(process.cwd(), './test/uploads/image.png')
const imageFile = await getFileByPath(imageFilePath)
const { id: uploadedImage } = await payload.create({
collection: 'media',
data: {},
file: imageFile,
})
},
})