2022-06-08 08:01:14 +02:00
|
|
|
import { validateSchema } from '../validate';
|
|
|
|
import { FeatureSchema } from './feature-schema';
|
|
|
|
|
|
|
|
test('featureSchema', () => {
|
|
|
|
const data: FeatureSchema = {
|
|
|
|
name: 'a',
|
|
|
|
variants: [
|
|
|
|
{
|
|
|
|
name: 'a',
|
|
|
|
weight: 1,
|
2023-06-14 14:19:00 +02:00
|
|
|
weightType: 'fix',
|
2022-06-08 08:01:14 +02:00
|
|
|
stickiness: 'a',
|
|
|
|
overrides: [{ contextName: 'a', values: ['a'] }],
|
2023-07-21 08:15:15 +02:00
|
|
|
payload: { type: 'string', value: 'b' },
|
2022-06-08 08:01:14 +02:00
|
|
|
},
|
|
|
|
],
|
2022-06-08 15:31:34 +02:00
|
|
|
environments: [
|
|
|
|
{
|
|
|
|
name: 'a',
|
|
|
|
type: 'b',
|
|
|
|
enabled: true,
|
2023-01-11 09:53:43 +01:00
|
|
|
strategies: [
|
|
|
|
{
|
|
|
|
id: 'a',
|
|
|
|
name: 'a',
|
|
|
|
constraints: [
|
|
|
|
{
|
|
|
|
contextName: 'a',
|
|
|
|
operator: 'IN',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
segments: [1],
|
|
|
|
},
|
|
|
|
],
|
2022-06-08 15:31:34 +02:00
|
|
|
},
|
|
|
|
],
|
2022-06-08 08:01:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
expect(
|
|
|
|
validateSchema('#/components/schemas/featureSchema', data),
|
|
|
|
).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('featureSchema constraints', () => {
|
|
|
|
const data = {
|
|
|
|
name: 'a',
|
2023-01-11 09:53:43 +01:00
|
|
|
environments: [
|
|
|
|
{
|
|
|
|
name: 'a',
|
|
|
|
type: 'b',
|
|
|
|
enabled: true,
|
|
|
|
strategies: [
|
|
|
|
{ name: 'a', constraints: [{ contextName: 'a' }] },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
2022-06-08 08:01:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
expect(
|
|
|
|
validateSchema('#/components/schemas/featureSchema', data),
|
|
|
|
).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
2022-08-08 16:21:57 +02:00
|
|
|
test('featureSchema variants should only have a few required fields', () => {
|
|
|
|
const data = {
|
|
|
|
name: 'a',
|
|
|
|
variants: [
|
|
|
|
{
|
|
|
|
name: 'a',
|
|
|
|
weight: 1,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(
|
|
|
|
validateSchema('#/components/schemas/featureSchema', data),
|
|
|
|
).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('featureSchema variant override values must be an array', () => {
|
2022-06-08 08:01:14 +02:00
|
|
|
const data = {
|
|
|
|
name: 'a',
|
|
|
|
variants: [
|
|
|
|
{
|
|
|
|
name: 'a',
|
|
|
|
weight: 1,
|
2023-07-14 16:48:35 +02:00
|
|
|
weightType: 'fix',
|
2022-06-08 08:01:14 +02:00
|
|
|
stickiness: 'a',
|
|
|
|
overrides: [{ contextName: 'a', values: 'b' }],
|
|
|
|
payload: { type: 'a', value: 'b' },
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
expect(
|
|
|
|
validateSchema('#/components/schemas/featureSchema', data),
|
|
|
|
).toMatchSnapshot();
|
|
|
|
});
|