chore: hoists tests out of payload package

This commit is contained in:
James
2023-09-01 14:45:41 -04:00
parent 893ca87225
commit 0f3b364e46
215 changed files with 254 additions and 257 deletions

69
test/config/config.ts Normal file
View File

@@ -0,0 +1,69 @@
import type { Config } from '../../packages/payload/src/config/types'
import { buildConfigWithDefaults } from '../buildConfigWithDefaults'
import { openAccess } from '../helpers/configHelpers'
const config: Config = {
collections: [
{
slug: 'pages',
access: openAccess,
endpoints: [
{
path: '/hello',
method: 'get',
handler: (_, res): void => {
res.json({ message: 'hi' })
},
custom: { examples: [{ type: 'response', value: { message: 'hi' } }] },
},
],
fields: [
{
name: 'title',
type: 'text',
custom: { description: 'The title of this page' },
},
],
custom: { externalLink: 'https://foo.bar' },
},
],
globals: [
{
slug: 'my-global',
endpoints: [
{
path: '/greet',
method: 'get',
handler: (req, res): void => {
const { name } = req.query
res.json({ message: `Hi ${name}!` })
},
custom: { params: [{ in: 'query', name: 'name', type: 'string' }] },
},
],
fields: [
{
name: 'title',
type: 'text',
custom: { description: 'The title of my global' },
},
],
custom: { foo: 'bar' },
},
],
endpoints: [
{
path: '/config',
method: 'get',
root: true,
handler: (req, res): void => {
res.json(req.payload.config)
},
custom: { description: 'Get the sanitized payload config' },
},
],
custom: { name: 'Customer portal' },
}
export default buildConfigWithDefaults(config)

67
test/config/int.spec.ts Normal file
View File

@@ -0,0 +1,67 @@
import payload from '../../packages/payload/src'
import { initPayloadTest } from '../helpers/configHelpers'
require('isomorphic-fetch')
describe('Config', () => {
beforeAll(async () => {
await initPayloadTest({ __dirname, init: { local: true } })
})
describe('payload config', () => {
it('allows a custom field at the config root', () => {
const { config } = payload
expect(config.custom).toEqual({ name: 'Customer portal' })
})
it('allows a custom field in the root endpoints', () => {
const [endpoint] = payload.config.endpoints
expect(endpoint.custom).toEqual({ description: 'Get the sanitized payload config' })
})
})
describe('collection config', () => {
it('allows a custom field in collections', () => {
const [collection] = payload.config.collections
expect(collection.custom).toEqual({ externalLink: 'https://foo.bar' })
})
it('allows a custom field in collection endpoints', () => {
const [collection] = payload.config.collections
const [endpoint] = collection.endpoints
expect(endpoint.custom).toEqual({
examples: [{ type: 'response', value: { message: 'hi' } }],
})
})
it('allows a custom field in collection fields', () => {
const [collection] = payload.config.collections
const [field] = collection.fields
expect(field.custom).toEqual({ description: 'The title of this page' })
})
})
describe('global config', () => {
it('allows a custom field in globals', () => {
const [global] = payload.config.globals
expect(global.custom).toEqual({ foo: 'bar' })
})
it('allows a custom field in global endpoints', () => {
const [global] = payload.config.globals
const [endpoint] = global.endpoints
expect(endpoint.custom).toEqual({ params: [{ in: 'query', name: 'name', type: 'string' }] })
})
it('allows a custom field in global fields', () => {
const [global] = payload.config.globals
const [field] = global.fields
expect(field.custom).toEqual({ description: 'The title of my global' })
})
})
})