From fe4cd62a1f1c0bcb0d9317f5f979faf68d4f87da Mon Sep 17 00:00:00 2001 From: Jonas Lagoni Date: Tue, 22 Jun 2021 12:32:28 +0200 Subject: [PATCH] test: removed Schema from CommonModel test (#259) --- docs/presets.md | 1 - test/models/CommonModel.spec.ts | 107 ++++++++++++++++---------------- 2 files changed, 53 insertions(+), 55 deletions(-) diff --git a/docs/presets.md b/docs/presets.md index b8fec38772..d2fead0e20 100644 --- a/docs/presets.md +++ b/docs/presets.md @@ -1,4 +1,3 @@ - # Presets The AsyncAPI Model SDK uses **preset** objects to extend the rendered model. diff --git a/test/models/CommonModel.spec.ts b/test/models/CommonModel.spec.ts index 46953b3884..23d2b70603 100644 --- a/test/models/CommonModel.spec.ts +++ b/test/models/CommonModel.spec.ts @@ -1,5 +1,4 @@ -import {CommonModel} from '../../src/models/CommonModel'; -import { Schema } from '../../src/models/Schema'; +import {CommonModel} from '../../src/models/CommonModel'; describe('CommonModel', () => { describe('$id', () => { test('should return a string', () => { @@ -100,24 +99,24 @@ describe('CommonModel', () => { describe('additionalItems', () => { test('should return a Schema object', () => { - const doc: Schema = { additionalItems: { type: 'string' } }; - const d = Schema.toSchema(doc) as Schema; + const doc: any = { additionalItems: { type: 'string' } }; + const d = CommonModel.toCommonModel(doc); expect(typeof d).toEqual('object'); expect(d.additionalItems).not.toBeUndefined(); - expect(d.additionalItems!.constructor.name).toEqual('Schema'); + expect(d.additionalItems!.constructor.name).toEqual('CommonModel'); expect(d.additionalItems).toEqual(doc.additionalItems); }); test('should return undefined when not defined', () => { - const doc: Schema = {}; - const d = Schema.toSchema(doc) as Schema; + const doc: any = {}; + const d = CommonModel.toCommonModel(doc); expect(typeof d).toEqual('object'); expect(d.additionalItems).toEqual(undefined); }); test('should return undefined when undefined', () => { - const doc: Schema = { additionalItems: undefined }; - const d = Schema.toSchema(doc) as Schema; + const doc: any = { additionalItems: undefined }; + const d = CommonModel.toCommonModel(doc); expect(typeof d).toEqual('object'); expect(d.additionalItems).toEqual(undefined); }); @@ -171,7 +170,7 @@ describe('CommonModel', () => { }); describe('mergeCommonModels', () => { test('should handle recursive models', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); doc1.properties = { recursive: doc1 @@ -187,7 +186,7 @@ describe('CommonModel', () => { }); describe('$id', () => { test('should be merged when only right side is defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc2.$id = 'test'; @@ -195,7 +194,7 @@ describe('CommonModel', () => { expect(doc1.$id).toEqual(doc2.$id); }); test('should not be merged when both sides are defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc2.$id = 'test'; @@ -205,7 +204,7 @@ describe('CommonModel', () => { expect(doc1.$id).toEqual('temp'); }); test('should not change if nothing is defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc1 = CommonModel.mergeCommonModels(doc1, doc2, doc); @@ -214,7 +213,7 @@ describe('CommonModel', () => { }); describe('required', () => { test('should contain the same if right side is not defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc1.required = ['test']; @@ -222,7 +221,7 @@ describe('CommonModel', () => { expect(doc1.required).toEqual(['test']); }); test('should be merged when only right side is defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc2.required = ['test']; @@ -230,7 +229,7 @@ describe('CommonModel', () => { expect(doc1.required).toEqual(doc2.required); }); test('should be merged when both sides are defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc1.required = ['test']; @@ -239,7 +238,7 @@ describe('CommonModel', () => { expect(doc1.required).toEqual(['test', 'test2']); }); test('should only contain one if duplicate', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc1.required = ['test']; @@ -248,7 +247,7 @@ describe('CommonModel', () => { expect(doc1.required).toEqual(['test']); }); test('should not change if nothing is defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc1 = CommonModel.mergeCommonModels(doc1, doc2, doc); @@ -257,7 +256,7 @@ describe('CommonModel', () => { }); describe('$ref', () => { test('should be merged when only right side is defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc2.$ref = 'test'; @@ -265,7 +264,7 @@ describe('CommonModel', () => { expect(doc1.$ref).toEqual(doc2.$ref); }); test('should be merged when both sides are defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc2.$id = 'test'; @@ -274,7 +273,7 @@ describe('CommonModel', () => { expect(doc1.$ref).toEqual(doc2.$ref); }); test('should not change if nothing is defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc1 = CommonModel.mergeCommonModels(doc1, doc2, doc); @@ -283,7 +282,7 @@ describe('CommonModel', () => { }); describe('extend', () => { test('should be merged when only right side is defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc2.extend = ['test']; @@ -291,7 +290,7 @@ describe('CommonModel', () => { expect(doc1.extend).toEqual(doc2.extend); }); test('should be merged when both sides are defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc2.$id = 'test'; @@ -300,7 +299,7 @@ describe('CommonModel', () => { expect(doc1.extend).toEqual(doc2.extend); }); test('should not change if nothing is defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc1 = CommonModel.mergeCommonModels(doc1, doc2, doc); @@ -309,7 +308,7 @@ describe('CommonModel', () => { }); describe('type', () => { test('should be merged when only right side is defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc2.type = ['string']; @@ -317,7 +316,7 @@ describe('CommonModel', () => { expect(doc1.type).toEqual(doc2.type); }); test('should be merged when both sides are defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc2.type = ['string']; @@ -326,7 +325,7 @@ describe('CommonModel', () => { expect(doc1.type).toEqual(['number', 'string']); }); test('should not change if nothing is defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc1 = CommonModel.mergeCommonModels(doc1, doc2, doc); @@ -335,7 +334,7 @@ describe('CommonModel', () => { }); describe('enum', () => { test('should be merged when only right side is defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc2.enum = ['string']; @@ -343,7 +342,7 @@ describe('CommonModel', () => { expect(doc1.enum).toEqual(doc2.enum); }); test('Should not contain duplicate values', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc2.enum = ['string']; @@ -352,7 +351,7 @@ describe('CommonModel', () => { expect(doc1.enum).toEqual(['string']); }); test('should be merged when both sides are defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc2.enum = ['string']; @@ -361,7 +360,7 @@ describe('CommonModel', () => { expect(doc1.enum).toEqual(['number', 'string']); }); test('should not change if nothing is defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc1 = CommonModel.mergeCommonModels(doc1, doc2, doc); @@ -370,7 +369,7 @@ describe('CommonModel', () => { }); describe('items', () => { test('should be merged when only right side is defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc2.items = CommonModel.toCommonModel({type: 'string'}); @@ -378,7 +377,7 @@ describe('CommonModel', () => { expect(doc1.items).toEqual(doc2.items); }); test('should be merged when only left side is defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc1.items = CommonModel.toCommonModel({type: 'string'}); @@ -386,14 +385,14 @@ describe('CommonModel', () => { expect(doc1.items).toMatchObject({type: 'string'}); }); test('should handle empty items', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc1 = CommonModel.mergeCommonModels(doc1, doc2, doc); expect(doc1.items).toBeUndefined(); }); test('should be merged when both sides are defined as schemas', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc2.items = CommonModel.toCommonModel({type: 'string'}); @@ -402,7 +401,7 @@ describe('CommonModel', () => { expect(doc1.items).toMatchObject({type: ['number', 'string']}); }); test('should not do anything if right side is an empty array', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc2.items = []; @@ -411,7 +410,7 @@ describe('CommonModel', () => { expect(doc1.items).toMatchObject({type: 'number'}); }); test('Should handle left side is a tuple and right side is not', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc2.items = CommonModel.toCommonModel({type: 'string'}); @@ -420,7 +419,7 @@ describe('CommonModel', () => { expect(doc1.items).toMatchObject([{type: 'number'}]); }); test('Should handle right side is a tuple and left side is not', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc2.items = [CommonModel.toCommonModel({type: 'string'})]; @@ -429,7 +428,7 @@ describe('CommonModel', () => { expect(doc1.items).toMatchObject([{type: 'string'}]); }); test('should be merged when both sides are defined as array of schemas with different lengths', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc2.items = [CommonModel.toCommonModel({type: 'string'}), CommonModel.toCommonModel({type: 'boolean'})]; @@ -438,7 +437,7 @@ describe('CommonModel', () => { expect(doc1.items).toMatchObject([{type: ['number', 'string']}, {type: 'boolean'}]); }); test('should not change if nothing is defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc1 = CommonModel.mergeCommonModels(doc1, doc2, doc); @@ -448,7 +447,7 @@ describe('CommonModel', () => { describe('properties', () => { test('should be merged when only right side is defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc2.properties = {testProp: CommonModel.toCommonModel({type: 'string'})}; @@ -456,7 +455,7 @@ describe('CommonModel', () => { expect(doc1.properties).toEqual(doc2.properties); }); test('should be merged when both sides are defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc2.properties = {testProp: CommonModel.toCommonModel({type: 'string'})}; @@ -465,7 +464,7 @@ describe('CommonModel', () => { expect(doc1.properties).toEqual({testProp: {type: 'string'}, testProp2: {type: 'number'}}); }); test('should be merged together when both sides are defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc2.properties = {testProp: CommonModel.toCommonModel({type: 'string'})}; @@ -474,7 +473,7 @@ describe('CommonModel', () => { expect(doc1.properties).toEqual({testProp: {type: ['number', 'string'], originalSchema: {}}}); }); test('should not change if nothing is defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc1 = CommonModel.mergeCommonModels(doc1, doc2, doc); @@ -483,7 +482,7 @@ describe('CommonModel', () => { }); describe('additionalProperties', () => { test('should be merged when only right side is defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc2.additionalProperties = CommonModel.toCommonModel({type: 'string'}); @@ -491,7 +490,7 @@ describe('CommonModel', () => { expect(doc1.additionalProperties).toEqual(doc2.additionalProperties); }); test('should be merged together when both sides are defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc2.additionalProperties = CommonModel.toCommonModel({type: 'string'}); @@ -500,7 +499,7 @@ describe('CommonModel', () => { expect(doc1.additionalProperties).toEqual({type: ['number', 'string'], originalSchema: {}}); }); test('should not change if nothing is defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc1 = CommonModel.mergeCommonModels(doc1, doc2, doc); @@ -509,7 +508,7 @@ describe('CommonModel', () => { }); describe('additionalItems', () => { test('should be merged when only right side is defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc2.additionalItems = CommonModel.toCommonModel({type: 'string'}); @@ -517,7 +516,7 @@ describe('CommonModel', () => { expect(doc1.additionalItems).toEqual(doc2.additionalItems); }); test('should be merged together when both sides are defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc2.additionalItems = CommonModel.toCommonModel({type: 'string'}); @@ -526,7 +525,7 @@ describe('CommonModel', () => { expect(doc1.additionalItems).toEqual({type: ['number', 'string'], originalSchema: {}}); }); test('should not change if nothing is defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc1 = CommonModel.mergeCommonModels(doc1, doc2, doc); @@ -536,7 +535,7 @@ describe('CommonModel', () => { describe('patternProperties', () => { test('should be merged when only right side is defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc2.patternProperties = {pattern1: CommonModel.toCommonModel({type: 'string'})}; @@ -544,7 +543,7 @@ describe('CommonModel', () => { expect(doc1.patternProperties).toEqual(doc2.patternProperties); }); test('should be merged when both sides are defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc2.patternProperties = {pattern1: CommonModel.toCommonModel({type: 'string'})}; @@ -553,7 +552,7 @@ describe('CommonModel', () => { expect(doc1.patternProperties).toEqual({pattern1: {type: 'string'}, pattern2: {type: 'number'}}); }); test('should be merged together when both sides are defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc2.patternProperties = {pattern1: CommonModel.toCommonModel({type: 'string'})}; @@ -562,7 +561,7 @@ describe('CommonModel', () => { expect(doc1.patternProperties).toEqual({pattern1: {type: ['number', 'string'], originalSchema: {}}}); }); test('should not change if nothing is defined', () => { - const doc: Schema = { }; + const doc: any = { }; let doc1 = CommonModel.toCommonModel(doc); const doc2 = CommonModel.toCommonModel(doc); doc1 = CommonModel.mergeCommonModels(doc1, doc2, doc);