chore: validation reuses endpoints schema

This commit is contained in:
Dan Ribbens
2022-08-17 13:06:58 -04:00
parent 040833ead8
commit 771bbaedbc
5 changed files with 35 additions and 17 deletions

View File

@@ -8,6 +8,7 @@ export const collectionSlug = 'endpoints';
export const globalSlug = 'global-endpoints';
export const globalEndpoint = 'global';
export const applicationEndpoint = 'path';
export default buildConfig({
collections: [
@@ -68,6 +69,15 @@ export default buildConfig({
fields: [],
},
],
endpoints: [
{
path: applicationEndpoint,
method: 'post',
handler: (req: PayloadRequest, res: Response): void => {
res.json(req.body);
},
},
],
onInit: async (payload) => {
await payload.create({
collection: 'users',

View File

@@ -1,6 +1,6 @@
import { initPayloadTest } from '../helpers/configHelpers';
import { RESTClient } from '../helpers/rest';
import { collectionSlug, globalEndpoint, globalSlug } from './config';
import { applicationEndpoint, collectionSlug, globalEndpoint, globalSlug } from './config';
require('isomorphic-fetch');
@@ -45,4 +45,14 @@ describe('Endpoints', () => {
expect(params).toMatchObject(data);
});
});
describe('Application', () => {
it('should call custom endpoint', async () => {
const params = { app: 'response' };
const { status, data } = await client.endpoint(`/${applicationEndpoint}`, 'post', params);
expect(status).toBe(200);
expect(params).toMatchObject(data);
});
});
});