1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-07-31 13:47:02 +02:00

Feat: add validator tests and fix some errors

This commit is contained in:
Thomas Heartman 2022-07-20 14:54:26 +02:00
parent 45a3909618
commit ed787c015d
4 changed files with 32 additions and 21 deletions

View File

@ -10,9 +10,9 @@ export const playgroundFeatureSchema = {
additionalProperties: false, additionalProperties: false,
required: ['name', 'projectId', 'isEnabled', 'variant', 'variants'], required: ['name', 'projectId', 'isEnabled', 'variant', 'variants'],
properties: { properties: {
name: { type: 'string', examples: ['my-feature'] }, name: { type: 'string', example: 'my-feature' },
projectId: { type: 'string', examples: ['my-project'] }, projectId: { type: 'string', example: 'my-project' },
isEnabled: { type: 'boolean', examples: [true] }, isEnabled: { type: 'boolean', example: true },
variant: { variant: {
type: 'object', type: 'object',
additionalProperties: false, additionalProperties: false,
@ -34,7 +34,7 @@ export const playgroundFeatureSchema = {
}, },
}, },
nullable: true, nullable: true,
examples: ['green'], example: { name: 'green', enabled: true },
}, },
variants: { type: 'array', items: { $ref: variantSchema.$id } }, variants: { type: 'array', items: { $ref: variantSchema.$id } },
}, },

View File

@ -8,13 +8,13 @@ export const playgroundRequestSchema = {
type: 'object', type: 'object',
required: ['environment', 'context'], required: ['environment', 'context'],
properties: { properties: {
environment: { type: 'string', examples: ['development'] }, environment: { type: 'string', example: 'development' },
projects: { projects: {
oneOf: [ oneOf: [
{ {
type: 'array', type: 'array',
items: { type: 'string' }, items: { type: 'string' },
examples: ['my-project', 'my-other-project'], example: ['my-project'],
description: 'A list of projects to check for toggles in.', description: 'A list of projects to check for toggles in.',
}, },
{ {

View File

@ -6,40 +6,38 @@ export const sdkContextSchema = {
type: 'object', type: 'object',
additionalProperties: { additionalProperties: {
type: 'string', type: 'string',
examples: ['top-level custom context value'], example: 'top-level custom context value',
}, },
required: ['appName'], required: ['appName'],
properties: { properties: {
appName: { appName: {
type: 'string', type: 'string',
minLength: 1, minLength: 1,
examples: ['My cool application.'], example: 'My cool application.',
}, },
currentTime: { currentTime: {
type: 'string', type: 'string',
format: 'date-time', format: 'date-time',
examples: ['2022-07-05T12:56:41+02:00'], example: '2022-07-05T12:56:41+02:00',
}, },
environment: { type: 'string', deprecated: true }, environment: { type: 'string', deprecated: true },
properties: { properties: {
type: 'object', type: 'object',
additionalProperties: { type: 'string' }, additionalProperties: { type: 'string' },
examples: [ example: {
{ customContextField: 'this is one!',
customContextField: 'this is one!', otherCustomField: '3',
otherCustomField: 3, },
},
],
}, },
remoteAddress: { remoteAddress: {
type: 'string', type: 'string',
examples: ['192.168.1.1'], example: '192.168.1.1',
}, },
sessionId: { sessionId: {
type: 'string', type: 'string',
examples: ['b65e7b23-fec0-4814-a129-0e9861ef18fc'], example: 'b65e7b23-fec0-4814-a129-0e9861ef18fc',
}, },
userId: { type: 'string', examples: ['username@provider.com'] }, userId: { type: 'string', example: 'username@provider.com' },
}, },
components: {}, components: {},
} as const; } as const;

View File

@ -38,19 +38,32 @@ test('should serve the OpenAPI spec', async () => {
}); });
}); });
// test('the generated OpenAPI should not have any warnings', async () => {
// const { body } = await app.request
// .get('/docs/openapi.json')
// .expect('Content-Type', /json/)
// .expect(200);
// const [_openapi, _error, warning] = await enforcer(body, {
// fullResult: true,
// });
// if (warning !== undefined) console.warn(warning);
// expect(warning).toBeFalsy();
// });
test('the generated OpenAPI spec is valid', async () => { test('the generated OpenAPI spec is valid', async () => {
const { body } = await app.request const { body } = await app.request
.get('/docs/openapi.json') .get('/docs/openapi.json')
.expect('Content-Type', /json/) .expect('Content-Type', /json/)
.expect(200); .expect(200);
const [openapi, error, warning] = await enforcer(body, { const [openapi, error] = await enforcer(body, {
fullResult: true, fullResult: true,
}); });
if (error !== undefined) console.error(error); if (error !== undefined) console.error(error);
if (warning !== undefined) console.warn(warning);
if (openapi !== undefined) console.log('Document is valid');
expect(openapi).toBeTruthy(); expect(openapi).toBeTruthy();
}); });