mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-08 14:14:56 +03:00
Add test cases for min and max item constraint humanization
This commit is contained in:
parent
cb5602748d
commit
8ec1147390
|
@ -2,6 +2,7 @@ import {
|
||||||
detectType,
|
detectType,
|
||||||
getOperationSummary,
|
getOperationSummary,
|
||||||
getStatusCodeType,
|
getStatusCodeType,
|
||||||
|
humanizeConstraints,
|
||||||
isOperationName,
|
isOperationName,
|
||||||
isPrimitiveType,
|
isPrimitiveType,
|
||||||
mergeParams,
|
mergeParams,
|
||||||
|
@ -321,4 +322,35 @@ describe('Utils', () => {
|
||||||
expect(servers[2].url).toEqual('http://127.0.0.3');
|
expect(servers[2].url).toEqual('http://127.0.0.3');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('openapi humanizeConstraints', () => {
|
||||||
|
const itemConstraintSchema = (
|
||||||
|
min: number | undefined = undefined,
|
||||||
|
max: number | undefined = undefined,
|
||||||
|
) => ({ type: 'array', minItems: min, maxItems: max });
|
||||||
|
|
||||||
|
it('should not have a humanized constraint without schema constraints', () => {
|
||||||
|
expect(humanizeConstraints(itemConstraintSchema())).toHaveLength(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a humanized constraint when minItems is set', () => {
|
||||||
|
expect(humanizeConstraints(itemConstraintSchema(2))).toContain('>= 2 items');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a humanized constraint when maxItems is set', () => {
|
||||||
|
expect(humanizeConstraints(itemConstraintSchema(undefined, 8))).toContain('<= 8 items');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a humanized constraint when minItems and maxItems are both set', () => {
|
||||||
|
expect(humanizeConstraints(itemConstraintSchema(2, 8))).toContain('[ 2 .. 8 ] items');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a humanized constraint when minItems and maxItems are the same', () => {
|
||||||
|
expect(humanizeConstraints(itemConstraintSchema(7, 7))).toContain('7 items');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should have a humazined constraint when justMinItems is set, and it is equal to 1', () => {
|
||||||
|
expect(humanizeConstraints(itemConstraintSchema(1))).toContain('non-empty');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user