chore: unable to boot config and endpoints test suites (#3969)
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
import type { Config } from '../../packages/payload/src/config/types'
|
||||
|
||||
import { buildConfigWithDefaults } from '../buildConfigWithDefaults'
|
||||
import { openAccess } from '../helpers/configHelpers'
|
||||
import { devUser } from '../credentials'
|
||||
|
||||
const config: Config = {
|
||||
export default buildConfigWithDefaults({
|
||||
collections: [
|
||||
{
|
||||
slug: 'pages',
|
||||
access: openAccess,
|
||||
access: {
|
||||
read: () => true,
|
||||
create: () => true,
|
||||
delete: () => true,
|
||||
update: () => true,
|
||||
},
|
||||
endpoints: [
|
||||
{
|
||||
path: '/hello',
|
||||
@@ -64,6 +67,13 @@ const config: Config = {
|
||||
},
|
||||
],
|
||||
custom: { name: 'Customer portal' },
|
||||
}
|
||||
|
||||
export default buildConfigWithDefaults(config)
|
||||
onInit: async (payload) => {
|
||||
await payload.create({
|
||||
collection: 'users',
|
||||
data: {
|
||||
email: devUser.email,
|
||||
password: devUser.password,
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,61 +1,28 @@
|
||||
import type { Response } from 'express'
|
||||
|
||||
import express from 'express'
|
||||
|
||||
import type { Config } from '../../packages/payload/src/config/types'
|
||||
import type { PayloadRequest } from '../../packages/payload/src/express/types'
|
||||
import path from 'path'
|
||||
|
||||
import { buildConfigWithDefaults } from '../buildConfigWithDefaults'
|
||||
import { devUser } from '../credentials'
|
||||
import { openAccess } from '../helpers/configHelpers'
|
||||
import { collectionEndpoints } from './endpoints/collections'
|
||||
import { globalEndpoints } from './endpoints/globals'
|
||||
import { endpoints } from './endpoints/root'
|
||||
import {
|
||||
collectionSlug,
|
||||
globalSlug,
|
||||
noEndpointsCollectionSlug,
|
||||
noEndpointsGlobalSlug,
|
||||
} from './shared'
|
||||
|
||||
export const collectionSlug = 'endpoints'
|
||||
export const globalSlug = 'global-endpoints'
|
||||
|
||||
export const globalEndpoint = 'global'
|
||||
export const applicationEndpoint = 'path'
|
||||
export const rootEndpoint = 'root'
|
||||
export const noEndpointsCollectionSlug = 'no-endpoints'
|
||||
export const noEndpointsGlobalSlug = 'global-no-endpoints'
|
||||
|
||||
const MyConfig: Config = {
|
||||
export default buildConfigWithDefaults({
|
||||
collections: [
|
||||
{
|
||||
slug: collectionSlug,
|
||||
access: openAccess,
|
||||
endpoints: [
|
||||
{
|
||||
path: '/say-hello/joe-bloggs',
|
||||
method: 'get',
|
||||
handler: (req: PayloadRequest, res: Response): void => {
|
||||
res.json({ message: 'Hey Joey!' })
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/say-hello/:group/:name',
|
||||
method: 'get',
|
||||
handler: (req: PayloadRequest, res: Response): void => {
|
||||
res.json({ message: `Hello ${req.params.name} @ ${req.params.group}` })
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/say-hello/:name',
|
||||
method: 'get',
|
||||
handler: (req: PayloadRequest, res: Response): void => {
|
||||
res.json({ message: `Hello ${req.params.name}!` })
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/whoami',
|
||||
method: 'post',
|
||||
handler: (req: PayloadRequest, res: Response): void => {
|
||||
res.json({
|
||||
name: req.body.name,
|
||||
age: req.body.age,
|
||||
})
|
||||
},
|
||||
},
|
||||
],
|
||||
access: {
|
||||
read: () => true,
|
||||
create: () => true,
|
||||
delete: () => true,
|
||||
update: () => true,
|
||||
},
|
||||
endpoints: [...(collectionEndpoints || [])],
|
||||
fields: [
|
||||
{
|
||||
name: 'title',
|
||||
@@ -78,15 +45,7 @@ const MyConfig: Config = {
|
||||
globals: [
|
||||
{
|
||||
slug: globalSlug,
|
||||
endpoints: [
|
||||
{
|
||||
path: `/${globalEndpoint}`,
|
||||
method: 'post',
|
||||
handler: (req: PayloadRequest, res: Response): void => {
|
||||
res.json(req.body)
|
||||
},
|
||||
},
|
||||
],
|
||||
endpoints: [...(globalEndpoints || [])],
|
||||
fields: [],
|
||||
},
|
||||
{
|
||||
@@ -101,48 +60,21 @@ const MyConfig: Config = {
|
||||
],
|
||||
},
|
||||
],
|
||||
endpoints: [
|
||||
{
|
||||
path: `/${applicationEndpoint}`,
|
||||
method: 'post',
|
||||
handler: (req: PayloadRequest, res: Response): void => {
|
||||
res.json(req.body)
|
||||
},
|
||||
},
|
||||
{
|
||||
path: `/${applicationEndpoint}`,
|
||||
method: 'get',
|
||||
handler: (req: PayloadRequest, res: Response): void => {
|
||||
res.json({ message: 'Hello, world!' })
|
||||
},
|
||||
},
|
||||
{
|
||||
path: `/${applicationEndpoint}/i18n`,
|
||||
method: 'get',
|
||||
handler: (req: PayloadRequest, res: Response): void => {
|
||||
res.json({ message: req.t('general:backToDashboard') })
|
||||
},
|
||||
},
|
||||
{
|
||||
path: `/${rootEndpoint}`,
|
||||
method: 'get',
|
||||
root: true,
|
||||
handler: (req: PayloadRequest, res: Response): void => {
|
||||
res.json({ message: 'Hello, world!' })
|
||||
},
|
||||
},
|
||||
{
|
||||
path: `/${rootEndpoint}`,
|
||||
method: 'post',
|
||||
root: true,
|
||||
handler: [
|
||||
express.json({ type: 'application/json' }),
|
||||
(req: PayloadRequest, res: Response): void => {
|
||||
res.json(req.body)
|
||||
endpoints: [...(endpoints || [])],
|
||||
admin: {
|
||||
webpack: (config) => {
|
||||
return {
|
||||
...config,
|
||||
resolve: {
|
||||
...config.resolve,
|
||||
alias: {
|
||||
...config.resolve.alias,
|
||||
express: path.resolve(__dirname, './mocks/emptyModule.js'),
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
},
|
||||
],
|
||||
},
|
||||
onInit: async (payload) => {
|
||||
await payload.create({
|
||||
collection: 'users',
|
||||
@@ -152,6 +84,4 @@ const MyConfig: Config = {
|
||||
},
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
export default buildConfigWithDefaults(MyConfig)
|
||||
})
|
||||
|
||||
38
test/endpoints/endpoints/collections.ts
Normal file
38
test/endpoints/endpoints/collections.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import type { Response } from 'express'
|
||||
|
||||
import type { CollectionConfig } from '../../../packages/payload/src/collections/config/types'
|
||||
import type { PayloadRequest } from '../../../packages/payload/src/express/types'
|
||||
|
||||
export const collectionEndpoints: CollectionConfig['endpoints'] = [
|
||||
{
|
||||
path: '/say-hello/joe-bloggs',
|
||||
method: 'get',
|
||||
handler: (req: PayloadRequest, res: Response): void => {
|
||||
res.json({ message: 'Hey Joey!' })
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/say-hello/:group/:name',
|
||||
method: 'get',
|
||||
handler: (req: PayloadRequest, res: Response): void => {
|
||||
res.json({ message: `Hello ${req.params.name} @ ${req.params.group}` })
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/say-hello/:name',
|
||||
method: 'get',
|
||||
handler: (req: PayloadRequest, res: Response): void => {
|
||||
res.json({ message: `Hello ${req.params.name}!` })
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/whoami',
|
||||
method: 'post',
|
||||
handler: (req: PayloadRequest, res: Response): void => {
|
||||
res.json({
|
||||
name: req.body.name,
|
||||
age: req.body.age,
|
||||
})
|
||||
},
|
||||
},
|
||||
]
|
||||
16
test/endpoints/endpoints/globals.ts
Normal file
16
test/endpoints/endpoints/globals.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import type { Response } from 'express'
|
||||
|
||||
import type { PayloadRequest } from '../../../packages/payload/src/express/types'
|
||||
import type { GlobalConfig } from '../../../packages/payload/src/globals/config/types'
|
||||
|
||||
import { globalEndpoint } from '../shared'
|
||||
|
||||
export const globalEndpoints: GlobalConfig['endpoints'] = [
|
||||
{
|
||||
path: `/${globalEndpoint}`,
|
||||
method: 'post',
|
||||
handler: (req: PayloadRequest, res: Response): void => {
|
||||
res.json(req.body)
|
||||
},
|
||||
},
|
||||
]
|
||||
51
test/endpoints/endpoints/root.ts
Normal file
51
test/endpoints/endpoints/root.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import type { Response } from 'express'
|
||||
|
||||
import express from 'express'
|
||||
|
||||
import type { Config } from '../../../packages/payload/src/config/types'
|
||||
import type { PayloadRequest } from '../../../packages/payload/src/express/types'
|
||||
|
||||
import { applicationEndpoint, rootEndpoint } from '../shared'
|
||||
|
||||
export const endpoints: Config['endpoints'] = [
|
||||
{
|
||||
path: `/${applicationEndpoint}`,
|
||||
method: 'post',
|
||||
handler: (req: PayloadRequest, res: Response): void => {
|
||||
res.json(req.body)
|
||||
},
|
||||
},
|
||||
{
|
||||
path: `/${applicationEndpoint}`,
|
||||
method: 'get',
|
||||
handler: (req: PayloadRequest, res: Response): void => {
|
||||
res.json({ message: 'Hello, world!' })
|
||||
},
|
||||
},
|
||||
{
|
||||
path: `/${applicationEndpoint}/i18n`,
|
||||
method: 'get',
|
||||
handler: (req: PayloadRequest, res: Response): void => {
|
||||
res.json({ message: req.t('general:backToDashboard') })
|
||||
},
|
||||
},
|
||||
{
|
||||
path: `/${rootEndpoint}`,
|
||||
method: 'get',
|
||||
root: true,
|
||||
handler: (req: PayloadRequest, res: Response): void => {
|
||||
res.json({ message: 'Hello, world!' })
|
||||
},
|
||||
},
|
||||
{
|
||||
path: `/${rootEndpoint}`,
|
||||
method: 'post',
|
||||
root: true,
|
||||
handler: [
|
||||
express.json({ type: 'application/json' }),
|
||||
(req: PayloadRequest, res: Response): void => {
|
||||
res.json(req.body)
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
noEndpointsCollectionSlug,
|
||||
noEndpointsGlobalSlug,
|
||||
rootEndpoint,
|
||||
} from './config'
|
||||
} from './shared'
|
||||
|
||||
require('isomorphic-fetch')
|
||||
|
||||
|
||||
3
test/endpoints/mocks/emptyModule.js
Normal file
3
test/endpoints/mocks/emptyModule.js
Normal file
@@ -0,0 +1,3 @@
|
||||
export default {
|
||||
json: () => {},
|
||||
}
|
||||
13
test/endpoints/shared.ts
Normal file
13
test/endpoints/shared.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export const collectionSlug = 'endpoints'
|
||||
|
||||
export const globalSlug = 'global-endpoints'
|
||||
|
||||
export const globalEndpoint = 'global'
|
||||
|
||||
export const applicationEndpoint = 'path'
|
||||
|
||||
export const rootEndpoint = 'root'
|
||||
|
||||
export const noEndpointsCollectionSlug = 'no-endpoints'
|
||||
|
||||
export const noEndpointsGlobalSlug = 'global-no-endpoints'
|
||||
@@ -6,7 +6,6 @@ import shelljs from 'shelljs'
|
||||
import { v4 as uuid } from 'uuid'
|
||||
|
||||
import type { Payload } from '../../packages/payload/src'
|
||||
import type { CollectionConfig } from '../../packages/payload/src/collections/config/types'
|
||||
import type { InitOptions } from '../../packages/payload/src/config/types'
|
||||
|
||||
import payload from '../../packages/payload/src'
|
||||
@@ -70,10 +69,3 @@ export async function initPayloadTest(options: Options): Promise<InitializedPayl
|
||||
|
||||
return { serverURL: `http://localhost:${port}`, payload }
|
||||
}
|
||||
|
||||
export const openAccess: CollectionConfig['access'] = {
|
||||
read: () => true,
|
||||
create: () => true,
|
||||
delete: () => true,
|
||||
update: () => true,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user