mirror of
https://github.com/Unleash/unleash.git
synced 2025-07-26 13:48:33 +02:00
Feat: add validator tests and fix some errors
This commit is contained in:
parent
45a3909618
commit
ed787c015d
@ -10,9 +10,9 @@ export const playgroundFeatureSchema = {
|
||||
additionalProperties: false,
|
||||
required: ['name', 'projectId', 'isEnabled', 'variant', 'variants'],
|
||||
properties: {
|
||||
name: { type: 'string', examples: ['my-feature'] },
|
||||
projectId: { type: 'string', examples: ['my-project'] },
|
||||
isEnabled: { type: 'boolean', examples: [true] },
|
||||
name: { type: 'string', example: 'my-feature' },
|
||||
projectId: { type: 'string', example: 'my-project' },
|
||||
isEnabled: { type: 'boolean', example: true },
|
||||
variant: {
|
||||
type: 'object',
|
||||
additionalProperties: false,
|
||||
@ -34,7 +34,7 @@ export const playgroundFeatureSchema = {
|
||||
},
|
||||
},
|
||||
nullable: true,
|
||||
examples: ['green'],
|
||||
example: { name: 'green', enabled: true },
|
||||
},
|
||||
variants: { type: 'array', items: { $ref: variantSchema.$id } },
|
||||
},
|
||||
|
@ -8,13 +8,13 @@ export const playgroundRequestSchema = {
|
||||
type: 'object',
|
||||
required: ['environment', 'context'],
|
||||
properties: {
|
||||
environment: { type: 'string', examples: ['development'] },
|
||||
environment: { type: 'string', example: 'development' },
|
||||
projects: {
|
||||
oneOf: [
|
||||
{
|
||||
type: 'array',
|
||||
items: { type: 'string' },
|
||||
examples: ['my-project', 'my-other-project'],
|
||||
example: ['my-project'],
|
||||
description: 'A list of projects to check for toggles in.',
|
||||
},
|
||||
{
|
||||
|
@ -6,40 +6,38 @@ export const sdkContextSchema = {
|
||||
type: 'object',
|
||||
additionalProperties: {
|
||||
type: 'string',
|
||||
examples: ['top-level custom context value'],
|
||||
example: 'top-level custom context value',
|
||||
},
|
||||
required: ['appName'],
|
||||
properties: {
|
||||
appName: {
|
||||
type: 'string',
|
||||
minLength: 1,
|
||||
examples: ['My cool application.'],
|
||||
example: 'My cool application.',
|
||||
},
|
||||
currentTime: {
|
||||
type: 'string',
|
||||
format: 'date-time',
|
||||
examples: ['2022-07-05T12:56:41+02:00'],
|
||||
example: '2022-07-05T12:56:41+02:00',
|
||||
},
|
||||
environment: { type: 'string', deprecated: true },
|
||||
properties: {
|
||||
type: 'object',
|
||||
additionalProperties: { type: 'string' },
|
||||
examples: [
|
||||
{
|
||||
customContextField: 'this is one!',
|
||||
otherCustomField: 3,
|
||||
},
|
||||
],
|
||||
example: {
|
||||
customContextField: 'this is one!',
|
||||
otherCustomField: '3',
|
||||
},
|
||||
},
|
||||
remoteAddress: {
|
||||
type: 'string',
|
||||
examples: ['192.168.1.1'],
|
||||
example: '192.168.1.1',
|
||||
},
|
||||
sessionId: {
|
||||
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: {},
|
||||
} as const;
|
||||
|
@ -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 () => {
|
||||
const { body } = await app.request
|
||||
.get('/docs/openapi.json')
|
||||
.expect('Content-Type', /json/)
|
||||
.expect(200);
|
||||
|
||||
const [openapi, error, warning] = await enforcer(body, {
|
||||
const [openapi, error] = await enforcer(body, {
|
||||
fullResult: true,
|
||||
});
|
||||
|
||||
if (error !== undefined) console.error(error);
|
||||
if (warning !== undefined) console.warn(warning);
|
||||
if (openapi !== undefined) console.log('Document is valid');
|
||||
|
||||
expect(openapi).toBeTruthy();
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user