From 3160d9330576339a9899f16cad8f35f9620f7c5b Mon Sep 17 00:00:00 2001 From: Luis Fernando Planella Gonzalez Date: Fri, 9 Aug 2019 09:06:07 -0300 Subject: [PATCH] Added some tests --- test/all-types.json | 7 +++++++ test/all-types.spec.ts | 11 ++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/test/all-types.json b/test/all-types.json index ec76e9b..cdf3a52 100644 --- a/test/all-types.json +++ b/test/all-types.json @@ -104,6 +104,9 @@ "allOf": [ { "type": "object", + "required": [ + "numberProp" + ], "properties": { "stringProp": { "type": "string", @@ -131,6 +134,10 @@ }, { "type": "object", + "required": [ + "refEnumProp", + "refObjectProp" + ], "properties": { "refEnumProp": { "$ref": "#/components/schemas/RefEnum", diff --git a/test/all-types.spec.ts b/test/all-types.spec.ts index d330126..cb1cfb5 100644 --- a/test/all-types.spec.ts +++ b/test/all-types.spec.ts @@ -131,21 +131,22 @@ describe('Generation tests using all-types.json', () => { expect(decl.properties.length).toBe(18); // Assert the simple types - function assertProperty(name: string, type: string) { + function assertProperty(name: string, type: string, required = false) { const prop = decl.properties.find(p => p.name === name); expect(prop).withContext(`${name} property`).toBeDefined(); if (prop) { - expect(prop.type).toEqual(type); + expect(prop.type).withContext(`${name} type`).toEqual(type); + expect(prop.isOptional).withContext(`${name} required`).toBe(!required); } } assertProperty('stringProp', 'string'); assertProperty('integerProp', 'number'); - assertProperty('numberProp', 'number'); + assertProperty('numberProp', 'number', true); assertProperty('booleanProp', 'boolean'); assertProperty('anyProp', 'any'); - assertProperty('refEnumProp', 'RefEnum'); - assertProperty('refObjectProp', 'RefObject'); + assertProperty('refEnumProp', 'RefEnum', true); + assertProperty('refObjectProp', 'RefObject', true); assertProperty('unionProp', 'Union'); assertProperty('containerProp', 'Container'); assertProperty('arrayOfStringsProp', 'Array');