feat: initial test suite framework (#4929)

This commit is contained in:
Jarrod Flesch
2024-02-14 09:46:11 -05:00
committed by GitHub
parent 018755516b
commit 717a6b6d07
50 changed files with 663 additions and 486 deletions

View File

@@ -15,8 +15,8 @@ export default buildConfigWithDefaults({
{
path: '/hello',
method: 'get',
handler: (_, res): void => {
res.json({ message: 'hi' })
handler: () => {
return Response.json({ message: 'hi' })
},
custom: { examples: [{ type: 'response', value: { message: 'hi' } }] },
},
@@ -38,9 +38,9 @@ export default buildConfigWithDefaults({
{
path: '/greet',
method: 'get',
handler: (req, res): void => {
const { name } = req.query
res.json({ message: `Hi ${name}!` })
handler: ({ req }) => {
const sp = new URL(req.url).searchParams
return Response.json({ message: `Hi ${sp.get('name')}!` })
},
custom: { params: [{ in: 'query', name: 'name', type: 'string' }] },
},
@@ -60,8 +60,8 @@ export default buildConfigWithDefaults({
path: '/config',
method: 'get',
root: true,
handler: (req, res): void => {
res.json(req.payload.config)
handler: ({ req }) => {
return Response.json(req.payload.config)
},
custom: { description: 'Get the sanitized payload config' },
},

View File

@@ -29,7 +29,7 @@ describe('Config', () => {
it('allows a custom field in collection endpoints', () => {
const [collection] = payload.config.collections
const [endpoint] = collection.endpoints
const [endpoint] = collection.endpoints || []
expect(endpoint.custom).toEqual({
examples: [{ type: 'response', value: { message: 'hi' } }],
@@ -52,7 +52,7 @@ describe('Config', () => {
it('allows a custom field in global endpoints', () => {
const [global] = payload.config.globals
const [endpoint] = global.endpoints
const [endpoint] = global.endpoints || []
expect(endpoint.custom).toEqual({ params: [{ in: 'query', name: 'name', type: 'string' }] })
})