mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-11 00:08:30 +01:00
64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
import { validateSchema } from '../validate';
|
|
import { ClientMetricsSchema } from './client-metrics-schema';
|
|
|
|
test('clientMetricsSchema full', () => {
|
|
const data: ClientMetricsSchema = {
|
|
appName: 'a',
|
|
instanceId: 'some-id',
|
|
environment: 'some-env',
|
|
bucket: {
|
|
start: Date.now(),
|
|
stop: Date.now(),
|
|
toggles: {
|
|
someToggle: {
|
|
yes: 52,
|
|
no: 2,
|
|
variants: { someVariant: 52, newVariant: 33 },
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
expect(
|
|
validateSchema('#/components/schemas/clientMetricsSchema', data),
|
|
).toBeUndefined();
|
|
});
|
|
|
|
test('clientMetricsSchema should ignore additional properties without failing when required fields are there', () => {
|
|
expect(
|
|
validateSchema('#/components/schemas/clientMetricsSchema', {
|
|
appName: 'a',
|
|
someParam: 'some-value',
|
|
bucket: {
|
|
start: Date.now(),
|
|
stop: Date.now(),
|
|
toggles: {
|
|
someToggle: {
|
|
yes: 52,
|
|
variants: {},
|
|
someOtherParam: 'some-other-value',
|
|
},
|
|
},
|
|
},
|
|
}),
|
|
).toBeUndefined();
|
|
});
|
|
|
|
test('clientMetricsSchema should fail when required field is missing', () => {
|
|
expect(
|
|
validateSchema('#/components/schemas/clientMetricsSchema', {
|
|
appName: 'a',
|
|
bucket: {
|
|
start: Date.now(),
|
|
toggles: {
|
|
someToggle: {
|
|
yes: 52,
|
|
variants: {},
|
|
someOtherParam: 'some-other-value',
|
|
},
|
|
},
|
|
},
|
|
}),
|
|
).toMatchSnapshot();
|
|
});
|