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 { buildConfigWithDefaults } from '../buildConfigWithDefaults'
|
||||||
import { openAccess } from '../helpers/configHelpers'
|
import { devUser } from '../credentials'
|
||||||
|
|
||||||
const config: Config = {
|
export default buildConfigWithDefaults({
|
||||||
collections: [
|
collections: [
|
||||||
{
|
{
|
||||||
slug: 'pages',
|
slug: 'pages',
|
||||||
access: openAccess,
|
access: {
|
||||||
|
read: () => true,
|
||||||
|
create: () => true,
|
||||||
|
delete: () => true,
|
||||||
|
update: () => true,
|
||||||
|
},
|
||||||
endpoints: [
|
endpoints: [
|
||||||
{
|
{
|
||||||
path: '/hello',
|
path: '/hello',
|
||||||
@@ -64,6 +67,13 @@ const config: Config = {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
custom: { name: 'Customer portal' },
|
custom: { name: 'Customer portal' },
|
||||||
}
|
onInit: async (payload) => {
|
||||||
|
await payload.create({
|
||||||
export default buildConfigWithDefaults(config)
|
collection: 'users',
|
||||||
|
data: {
|
||||||
|
email: devUser.email,
|
||||||
|
password: devUser.password,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|||||||
@@ -1,61 +1,28 @@
|
|||||||
import type { Response } from 'express'
|
import path from 'path'
|
||||||
|
|
||||||
import express from 'express'
|
|
||||||
|
|
||||||
import type { Config } from '../../packages/payload/src/config/types'
|
|
||||||
import type { PayloadRequest } from '../../packages/payload/src/express/types'
|
|
||||||
|
|
||||||
import { buildConfigWithDefaults } from '../buildConfigWithDefaults'
|
import { buildConfigWithDefaults } from '../buildConfigWithDefaults'
|
||||||
import { devUser } from '../credentials'
|
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 default buildConfigWithDefaults({
|
||||||
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 = {
|
|
||||||
collections: [
|
collections: [
|
||||||
{
|
{
|
||||||
slug: collectionSlug,
|
slug: collectionSlug,
|
||||||
access: openAccess,
|
access: {
|
||||||
endpoints: [
|
read: () => true,
|
||||||
{
|
create: () => true,
|
||||||
path: '/say-hello/joe-bloggs',
|
delete: () => true,
|
||||||
method: 'get',
|
update: () => true,
|
||||||
handler: (req: PayloadRequest, res: Response): void => {
|
},
|
||||||
res.json({ message: 'Hey Joey!' })
|
endpoints: [...(collectionEndpoints || [])],
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
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,
|
|
||||||
})
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
name: 'title',
|
name: 'title',
|
||||||
@@ -78,15 +45,7 @@ const MyConfig: Config = {
|
|||||||
globals: [
|
globals: [
|
||||||
{
|
{
|
||||||
slug: globalSlug,
|
slug: globalSlug,
|
||||||
endpoints: [
|
endpoints: [...(globalEndpoints || [])],
|
||||||
{
|
|
||||||
path: `/${globalEndpoint}`,
|
|
||||||
method: 'post',
|
|
||||||
handler: (req: PayloadRequest, res: Response): void => {
|
|
||||||
res.json(req.body)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
fields: [],
|
fields: [],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -101,48 +60,21 @@ const MyConfig: Config = {
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
endpoints: [
|
endpoints: [...(endpoints || [])],
|
||||||
{
|
admin: {
|
||||||
path: `/${applicationEndpoint}`,
|
webpack: (config) => {
|
||||||
method: 'post',
|
return {
|
||||||
handler: (req: PayloadRequest, res: Response): void => {
|
...config,
|
||||||
res.json(req.body)
|
resolve: {
|
||||||
},
|
...config.resolve,
|
||||||
},
|
alias: {
|
||||||
{
|
...config.resolve.alias,
|
||||||
path: `/${applicationEndpoint}`,
|
express: path.resolve(__dirname, './mocks/emptyModule.js'),
|
||||||
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)
|
|
||||||
},
|
},
|
||||||
],
|
}
|
||||||
},
|
},
|
||||||
],
|
},
|
||||||
onInit: async (payload) => {
|
onInit: async (payload) => {
|
||||||
await payload.create({
|
await payload.create({
|
||||||
collection: 'users',
|
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,
|
noEndpointsCollectionSlug,
|
||||||
noEndpointsGlobalSlug,
|
noEndpointsGlobalSlug,
|
||||||
rootEndpoint,
|
rootEndpoint,
|
||||||
} from './config'
|
} from './shared'
|
||||||
|
|
||||||
require('isomorphic-fetch')
|
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 { v4 as uuid } from 'uuid'
|
||||||
|
|
||||||
import type { Payload } from '../../packages/payload/src'
|
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 type { InitOptions } from '../../packages/payload/src/config/types'
|
||||||
|
|
||||||
import payload from '../../packages/payload/src'
|
import payload from '../../packages/payload/src'
|
||||||
@@ -70,10 +69,3 @@ export async function initPayloadTest(options: Options): Promise<InitializedPayl
|
|||||||
|
|
||||||
return { serverURL: `http://localhost:${port}`, payload }
|
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