From 2855fca34f6ac53cf2029f393bad46891b1918dc Mon Sep 17 00:00:00 2001 From: nanov Date: Sat, 12 Oct 2019 17:38:37 +0300 Subject: [PATCH] write tests for 'multipleOf' constrain --- src/utils/__tests__/openapi.test.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/utils/__tests__/openapi.test.ts b/src/utils/__tests__/openapi.test.ts index 244ab63c..fbc56ea2 100644 --- a/src/utils/__tests__/openapi.test.ts +++ b/src/utils/__tests__/openapi.test.ts @@ -333,7 +333,8 @@ describe('Utils', () => { const itemConstraintSchema = ( min: number | undefined = undefined, max: number | undefined = undefined, - ) => ({ type: 'array', minItems: min, maxItems: max }); + multipleOf: number | undefined = undefined, + ) => ({ type: 'array', minItems: min, maxItems: max, multipleOf }); it('should not have a humanized constraint without schema constraints', () => { expect(humanizeConstraints(itemConstraintSchema())).toHaveLength(0); @@ -358,6 +359,18 @@ describe('Utils', () => { it('should have a humazined constraint when justMinItems is set, and it is equal to 1', () => { expect(humanizeConstraints(itemConstraintSchema(1))).toContain('non-empty'); }); + + it('should have a humazined constraint when multipleOf is set, and it is in format of /^0\\.0*1$/', () => { + expect(humanizeConstraints(itemConstraintSchema(undefined, undefined, 0.01))).toContain( + 'decimals <= 2 digits', + ); + }); + + it('should have a humazined constraint when multipleOf is set, and it is in format other than /^0\\.0*1$/', () => { + expect(humanizeConstraints(itemConstraintSchema(undefined, undefined, 0.5))).toContain( + 'multiple of 0.5', + ); + }); }); describe('OpenAPI pluralizeType', () => { @@ -387,7 +400,9 @@ describe('Utils', () => { expect(pluralizeType('objects (Pet)')).toEqual('objects (Pet)'); expect(pluralizeType('strings ')).toEqual('strings '); expect(pluralizeType('objects or strings')).toEqual('objects or strings'); - expect(pluralizeType('objects (Pet) or numbers ')).toEqual('objects (Pet) or numbers '); + expect(pluralizeType('objects (Pet) or numbers ')).toEqual( + 'objects (Pet) or numbers ', + ); }); });