mirror of
https://github.com/Unleash/unleash.git
synced 2025-05-12 01:17:04 +02:00
Wip: refactor tests for updated schema name
This commit is contained in:
parent
48e9bd4ead
commit
f39faeaead
@ -1,6 +1,6 @@
|
||||
import { FromSchema } from 'json-schema-to-ts';
|
||||
|
||||
export const exportParameters = {
|
||||
const exportParameters = {
|
||||
format: {
|
||||
type: 'string',
|
||||
enum: ['json', 'yaml'],
|
||||
|
@ -1,39 +1,76 @@
|
||||
import { SchemaObject } from 'ajv';
|
||||
import fc from 'fast-check';
|
||||
import { createRequestParameters } from './request-parameters';
|
||||
import fc, { Arbitrary } from 'fast-check';
|
||||
import {
|
||||
createRequestParameters,
|
||||
ParameterDescription,
|
||||
ParameterDetails,
|
||||
Parameters,
|
||||
} from './request-parameters';
|
||||
|
||||
const paramDesc = <T, U>(
|
||||
typeName: U,
|
||||
gen: Arbitrary<T>,
|
||||
): Arbitrary<ParameterDescription<U, T>> =>
|
||||
fc.record(
|
||||
{
|
||||
type: fc.constant(typeName),
|
||||
default: gen,
|
||||
enum: fc.array(gen, { minLength: 1 }),
|
||||
},
|
||||
{ requiredKeys: ['type'] },
|
||||
);
|
||||
|
||||
const parameterDescription = (): Arbitrary<ParameterDescription<any, any>> =>
|
||||
fc.oneof(
|
||||
paramDesc('boolean', fc.boolean()),
|
||||
paramDesc('string', fc.string()),
|
||||
paramDesc('number', fc.integer()),
|
||||
);
|
||||
|
||||
const paramDetails = (): Arbitrary<ParameterDetails> =>
|
||||
fc
|
||||
.tuple(fc.string(), parameterDescription())
|
||||
.map(([description, deets]) => ({
|
||||
description,
|
||||
...deets,
|
||||
}));
|
||||
|
||||
const parameterDetails = (): Arbitrary<Parameters> =>
|
||||
fc.dictionary(fc.string({ minLength: 1 }), paramDetails());
|
||||
|
||||
describe('request parameter utils', () => {
|
||||
it('turns an object of names and descriptions into a an expected parameter list', () => {
|
||||
fc.assert(
|
||||
fc.property(
|
||||
fc.dictionary(fc.string({ minLength: 1 }), fc.string()),
|
||||
(parameters) => {
|
||||
const result = createRequestParameters(parameters);
|
||||
fc.property(parameterDetails(), fc.context(), (parameters, ctx) => {
|
||||
const result = createRequestParameters(parameters);
|
||||
|
||||
return result.every((paramsObject) => {
|
||||
return (
|
||||
paramsObject.description ===
|
||||
parameters[paramsObject.name]
|
||||
);
|
||||
});
|
||||
},
|
||||
),
|
||||
ctx.log(JSON.stringify(parameters));
|
||||
// ctx.log(JSON.stringify(result));
|
||||
return false;
|
||||
// return result.every((paramsObject) => {
|
||||
// return false;
|
||||
// });
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('says every parameter is of type string and goes in the query', () => {
|
||||
fc.assert(
|
||||
fc.property(
|
||||
fc.dictionary(fc.string({ minLength: 1 }), fc.string()),
|
||||
// it('assigns parameter descriptions correctly', () => {
|
||||
// fc.assert(fc.property());
|
||||
// });
|
||||
|
||||
(parameters) => {
|
||||
return createRequestParameters(parameters).every(
|
||||
(paramsObject) =>
|
||||
(paramsObject.schema as SchemaObject).type ===
|
||||
'string' && paramsObject.in === 'query',
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
});
|
||||
// it('says every parameter is of type string and goes in the query', () => {
|
||||
// fc.assert(
|
||||
// fc.property(
|
||||
// fc.dictionary(fc.string({ minLength: 1 }), fc.string()),
|
||||
|
||||
// (parameters) => {
|
||||
// return createRequestParameters(parameters).every(
|
||||
// (paramsObject) =>
|
||||
// (paramsObject.schema as SchemaObject).type ===
|
||||
// 'string' && paramsObject.in === 'query',
|
||||
// );
|
||||
// },
|
||||
// ),
|
||||
// );
|
||||
// });
|
||||
});
|
||||
|
@ -1,25 +1,29 @@
|
||||
import { OpenAPIV3 } from 'openapi-types';
|
||||
|
||||
// type ParameterDetails = {
|
||||
// description: string;
|
||||
// } & (
|
||||
// | { type: 'boolean'; default?: boolean; enum?: boolean[] }
|
||||
// | { type: 'string'; default?: string; enum?: string[] }
|
||||
// | { type: 'number'; default?: number; enum?: number[] }
|
||||
// );
|
||||
export type ParameterDescription<TypeName, T> = {
|
||||
type: TypeName;
|
||||
default?: T;
|
||||
enum?: T[];
|
||||
};
|
||||
|
||||
// { [parameterName: string]: Parameter };
|
||||
// type Parameters = Record<ParameterName, ParameterDetails>;
|
||||
export type ParameterDetails = {
|
||||
description: string;
|
||||
} & (
|
||||
| ParameterDescription<'boolean', boolean>
|
||||
| ParameterDescription<'string', string>
|
||||
| ParameterDescription<'number', number>
|
||||
);
|
||||
|
||||
export type Parameters = Record<ParameterName, ParameterDetails>;
|
||||
|
||||
type ParameterName = string;
|
||||
type Description = string;
|
||||
|
||||
export const createRequestParameters = (
|
||||
params: Record<ParameterName, Description>,
|
||||
params: Parameters,
|
||||
): OpenAPIV3.ParameterObject[] =>
|
||||
Object.entries(params).map(([name, description]) => ({
|
||||
Object.entries(params).map(([name, deets]) => ({
|
||||
name,
|
||||
description,
|
||||
description: deets.description,
|
||||
schema: { type: 'string' },
|
||||
in: 'query',
|
||||
}));
|
||||
|
@ -79,7 +79,7 @@ class StateController extends Controller {
|
||||
responses: {
|
||||
200: createResponseSchema('stateSchema'),
|
||||
},
|
||||
parameters: createRequestParameters(exportParametersSchema),
|
||||
// parameters: createRequestParameters(exportParametersSchema),
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user