chore: validation reuses endpoints schema
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import joi from 'joi';
|
import joi from 'joi';
|
||||||
import { componentSchema } from '../../utilities/componentSchema';
|
import { componentSchema } from '../../utilities/componentSchema';
|
||||||
|
import { endpointsSchema } from '../../config/schema';
|
||||||
|
|
||||||
const strategyBaseSchema = joi.object().keys({
|
const strategyBaseSchema = joi.object().keys({
|
||||||
refresh: joi.boolean(),
|
refresh: joi.boolean(),
|
||||||
@@ -61,14 +62,7 @@ const collectionSchema = joi.object().keys({
|
|||||||
afterRefresh: joi.array().items(joi.func()),
|
afterRefresh: joi.array().items(joi.func()),
|
||||||
afterForgotPassword: joi.array().items(joi.func()),
|
afterForgotPassword: joi.array().items(joi.func()),
|
||||||
}),
|
}),
|
||||||
endpoints: joi.array().items(joi.object({
|
endpoints: endpointsSchema,
|
||||||
path: joi.string(),
|
|
||||||
method: joi.string().valid('get', 'head', 'post', 'put', 'patch', 'delete', 'connect', 'options'),
|
|
||||||
handler: joi.alternatives().try(
|
|
||||||
joi.array().items(joi.func()),
|
|
||||||
joi.func(),
|
|
||||||
),
|
|
||||||
})),
|
|
||||||
auth: joi.alternatives().try(
|
auth: joi.alternatives().try(
|
||||||
joi.object({
|
joi.object({
|
||||||
tokenExpiration: joi.number(),
|
tokenExpiration: joi.number(),
|
||||||
|
|||||||
@@ -5,6 +5,15 @@ const component = joi.alternatives().try(
|
|||||||
joi.func(),
|
joi.func(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const endpointsSchema = joi.array().items(joi.object({
|
||||||
|
path: joi.string(),
|
||||||
|
method: joi.string().valid('get', 'head', 'post', 'put', 'patch', 'delete', 'connect', 'options'),
|
||||||
|
handler: joi.alternatives().try(
|
||||||
|
joi.array().items(joi.func()),
|
||||||
|
joi.func(),
|
||||||
|
),
|
||||||
|
}));
|
||||||
|
|
||||||
export default joi.object({
|
export default joi.object({
|
||||||
serverURL: joi.string()
|
serverURL: joi.string()
|
||||||
.uri()
|
.uri()
|
||||||
@@ -33,6 +42,7 @@ export default joi.object({
|
|||||||
outputFile: joi.string(),
|
outputFile: joi.string(),
|
||||||
}),
|
}),
|
||||||
collections: joi.array(),
|
collections: joi.array(),
|
||||||
|
endpoints: endpointsSchema,
|
||||||
globals: joi.array(),
|
globals: joi.array(),
|
||||||
admin: joi.object({
|
admin: joi.object({
|
||||||
user: joi.string(),
|
user: joi.string(),
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import joi from 'joi';
|
import joi from 'joi';
|
||||||
import { componentSchema } from '../../utilities/componentSchema';
|
import { componentSchema } from '../../utilities/componentSchema';
|
||||||
|
import { endpointsSchema } from '../../config/schema';
|
||||||
|
|
||||||
const globalSchema = joi.object().keys({
|
const globalSchema = joi.object().keys({
|
||||||
slug: joi.string().required(),
|
slug: joi.string().required(),
|
||||||
@@ -18,14 +19,7 @@ const globalSchema = joi.object().keys({
|
|||||||
beforeRead: joi.array().items(joi.func()),
|
beforeRead: joi.array().items(joi.func()),
|
||||||
afterRead: joi.array().items(joi.func()),
|
afterRead: joi.array().items(joi.func()),
|
||||||
}),
|
}),
|
||||||
endpoints: joi.array().items(joi.object({
|
endpoints: endpointsSchema,
|
||||||
path: joi.string(),
|
|
||||||
method: joi.string().valid('get', 'head', 'post', 'put', 'patch', 'delete', 'connect', 'options'),
|
|
||||||
handler: joi.alternatives().try(
|
|
||||||
joi.array().items(joi.func()),
|
|
||||||
joi.func(),
|
|
||||||
),
|
|
||||||
})),
|
|
||||||
access: joi.object({
|
access: joi.object({
|
||||||
read: joi.func(),
|
read: joi.func(),
|
||||||
readVersions: joi.func(),
|
readVersions: joi.func(),
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ export const collectionSlug = 'endpoints';
|
|||||||
export const globalSlug = 'global-endpoints';
|
export const globalSlug = 'global-endpoints';
|
||||||
|
|
||||||
export const globalEndpoint = 'global';
|
export const globalEndpoint = 'global';
|
||||||
|
export const applicationEndpoint = 'path';
|
||||||
|
|
||||||
export default buildConfig({
|
export default buildConfig({
|
||||||
collections: [
|
collections: [
|
||||||
@@ -68,6 +69,15 @@ export default buildConfig({
|
|||||||
fields: [],
|
fields: [],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
endpoints: [
|
||||||
|
{
|
||||||
|
path: applicationEndpoint,
|
||||||
|
method: 'post',
|
||||||
|
handler: (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',
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { initPayloadTest } from '../helpers/configHelpers';
|
import { initPayloadTest } from '../helpers/configHelpers';
|
||||||
import { RESTClient } from '../helpers/rest';
|
import { RESTClient } from '../helpers/rest';
|
||||||
import { collectionSlug, globalEndpoint, globalSlug } from './config';
|
import { applicationEndpoint, collectionSlug, globalEndpoint, globalSlug } from './config';
|
||||||
|
|
||||||
require('isomorphic-fetch');
|
require('isomorphic-fetch');
|
||||||
|
|
||||||
@@ -45,4 +45,14 @@ describe('Endpoints', () => {
|
|||||||
expect(params).toMatchObject(data);
|
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user