1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-05 17:53:12 +02:00

Feat: add events-schema plus tests

This commit is contained in:
Thomas Heartman 2022-06-27 11:57:09 +02:00
parent 4154747b10
commit 8c5cefc34a
5 changed files with 106 additions and 0 deletions

View File

@ -82,6 +82,8 @@ import { emailSchema } from './spec/email-schema';
import { strategySchema } from './spec/strategy-schema';
import { strategiesSchema } from './spec/strategies-schema';
import { upsertStrategySchema } from './spec/upsert-strategy-schema';
import { eventSchema } from './spec/event-schema';
import { eventsSchema } from './spec/events-schema';
import { clientApplicationSchema } from './spec/client-application-schema';
// All schemas in `openapi/spec` should be listed here.
@ -107,6 +109,8 @@ export const schemas = {
emailSchema,
environmentSchema,
environmentsSchema,
eventSchema,
eventsSchema,
exportParametersSchema,
featureEnvironmentSchema,
featureEnvironmentMetricsSchema,

View File

@ -0,0 +1,31 @@
import { validateSchema } from '../validate';
import { EventSchema } from './event-schema';
test('eventSchema', () => {
const data: EventSchema = {
id: 899,
type: 'feature-created',
createdBy: 'user@company.com',
createdAt: '2022-05-31T13:32:20.560Z',
data: {
name: 'new-feature',
description: 'Toggle description',
type: 'release',
project: 'my-project',
stale: false,
variants: [],
createdAt: '2022-05-31T13:32:20.547Z',
lastSeenAt: null,
impressionData: true,
},
preData: null,
tags: [],
featureName: 'new-feature',
project: 'my-project',
environment: null,
};
expect(
validateSchema('#/components/schemas/eventSchema', data),
).toBeUndefined();
});

View File

@ -1,4 +1,5 @@
import { FromSchema } from 'json-schema-to-ts';
import { tagSchema } from './tag-schema';
export const eventSchema = {
$id: '#/components/schemas/eventSchema',
@ -20,6 +21,9 @@ export const eventSchema = {
createdBy: {
type: 'string',
},
environment: {
type: 'string',
},
project: {
type: 'string',
},
@ -35,6 +39,11 @@ export const eventSchema = {
},
},
},
components: {
schemas: {
tagSchema,
},
},
} as const;
export type EventSchema = FromSchema<typeof eventSchema>;

View File

@ -0,0 +1,36 @@
import { validateSchema } from '../validate';
import { EventsSchema } from './events-schema';
test('eventsSchema', () => {
const data: EventsSchema = {
version: 1,
events: [
{
id: 899,
type: 'feature-created',
createdBy: 'user@company.com',
createdAt: '2022-05-31T13:32:20.560Z',
data: {
name: 'new-feature',
description: 'Toggle description',
type: 'release',
project: 'my-project',
stale: false,
variants: [],
createdAt: '2022-05-31T13:32:20.547Z',
lastSeenAt: null,
impressionData: true,
},
preData: null,
tags: [],
featureName: 'new-feature',
project: 'my-project',
environment: null,
},
],
};
expect(
validateSchema('#/components/schemas/eventsSchema', data),
).toBeUndefined();
});

View File

@ -0,0 +1,26 @@
import { FromSchema } from 'json-schema-to-ts';
import { eventSchema } from './event-schema';
export const eventsSchema = {
$id: '#/components/schemas/eventsSchema',
type: 'object',
additionalProperties: false,
required: ['version', 'events'],
properties: {
version: {
type: 'integer',
minimum: 1,
},
events: {
type: 'array',
items: { $ref: '#/components/schemas/eventSchema' },
},
},
components: {
schemas: {
eventSchema,
},
},
} as const;
export type EventsSchema = FromSchema<typeof eventsSchema>;