mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-10 17:53:36 +02:00
Feat: add events-schema plus tests
This commit is contained in:
parent
4154747b10
commit
8c5cefc34a
@ -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,
|
||||
|
31
src/lib/openapi/spec/event-schema.test.ts
Normal file
31
src/lib/openapi/spec/event-schema.test.ts
Normal 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();
|
||||
});
|
@ -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>;
|
||||
|
36
src/lib/openapi/spec/events-schema.test.ts
Normal file
36
src/lib/openapi/spec/events-schema.test.ts
Normal 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();
|
||||
});
|
26
src/lib/openapi/spec/events-schema.ts
Normal file
26
src/lib/openapi/spec/events-schema.ts
Normal 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>;
|
Loading…
Reference in New Issue
Block a user