mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-11 00:08:30 +01:00
49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
|
import fc, { Arbitrary } from 'fast-check';
|
||
|
import { urlFriendlyString } from '../../../test/arbitraries.test';
|
||
|
import { validateSchema } from '../validate';
|
||
|
import {
|
||
|
playgroundFeatureSchema,
|
||
|
PlaygroundFeatureSchema,
|
||
|
} from './playground-feature-schema';
|
||
|
|
||
|
export const generate = (): Arbitrary<PlaygroundFeatureSchema> =>
|
||
|
fc.boolean().chain((isEnabled) =>
|
||
|
fc.record({
|
||
|
isEnabled: fc.constant(isEnabled),
|
||
|
projectId: urlFriendlyString(),
|
||
|
name: urlFriendlyString(),
|
||
|
variant: fc.record(
|
||
|
{
|
||
|
name: urlFriendlyString(),
|
||
|
enabled: fc.constant(isEnabled),
|
||
|
payload: fc.oneof(
|
||
|
fc.record({
|
||
|
type: fc.constant('json' as 'json'),
|
||
|
value: fc.json(),
|
||
|
}),
|
||
|
fc.record({
|
||
|
type: fc.constant('csv' as 'csv'),
|
||
|
value: fc
|
||
|
.array(fc.lorem())
|
||
|
.map((words) => words.join(',')),
|
||
|
}),
|
||
|
fc.record({
|
||
|
type: fc.constant('string' as 'string'),
|
||
|
value: fc.string(),
|
||
|
}),
|
||
|
),
|
||
|
},
|
||
|
{ requiredKeys: ['name', 'enabled'] },
|
||
|
),
|
||
|
}),
|
||
|
);
|
||
|
|
||
|
test('playgroundFeatureSchema', () =>
|
||
|
fc.assert(
|
||
|
fc.property(
|
||
|
generate(),
|
||
|
(data: PlaygroundFeatureSchema) =>
|
||
|
validateSchema(playgroundFeatureSchema.$id, data) === undefined,
|
||
|
),
|
||
|
));
|