Skip to content

Commit

Permalink
chore: fix contains property check failing (#810)
Browse files Browse the repository at this point in the history
* fixed impl and test

* moved test
  • Loading branch information
jonaslagoni authored Jul 11, 2022
1 parent f4b7371 commit df88e8b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/models/ConstrainedMetaModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ export class ConstrainedObjectModel extends ConstrainedMetaModel {
*/
containsPropertyType<T>(propertyType: { new(...args: any[]): T }) : boolean {
const foundPropertiesWithType = Object.values(this.properties).filter((property) => {
return property instanceof propertyType;
return property.property instanceof propertyType;
});
return foundPropertiesWithType.length === 0;
return foundPropertiesWithType.length !== 0;
}
}
15 changes: 14 additions & 1 deletion test/models/ConstrainedMetaModel.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { constrainMetaModel } from '../../src/helpers';
import { AnyModel, ArrayModel, BooleanModel, ConstrainedArrayModel, ConstrainedDictionaryModel, ConstrainedEnumModel, ConstrainedObjectModel, ConstrainedReferenceModel, ConstrainedTupleModel, ConstrainedUnionModel, DictionaryModel, EnumModel, EnumValueModel, FloatModel, IntegerModel, ObjectModel, ObjectPropertyModel, ReferenceModel, StringModel, TupleModel, TupleValueModel, UnionModel } from '../../src/models';
import { AnyModel, ArrayModel, BooleanModel, ConstrainedArrayModel, ConstrainedBooleanModel, ConstrainedDictionaryModel, ConstrainedEnumModel, ConstrainedObjectModel, ConstrainedObjectPropertyModel, ConstrainedReferenceModel, ConstrainedStringModel, ConstrainedTupleModel, ConstrainedUnionModel, DictionaryModel, EnumModel, EnumValueModel, FloatModel, IntegerModel, ObjectModel, ObjectPropertyModel, ReferenceModel, StringModel, TupleModel, TupleValueModel, UnionModel } from '../../src/models';
import { mockedConstraints, mockedTypeMapping } from '../TestUtils/TestConstrainer';


describe('ConstrainedMetaModel', () => {
describe('ReferenceModel', () => {
test('should return no dependencies', () => {
Expand Down Expand Up @@ -120,6 +121,18 @@ describe('ConstrainedMetaModel', () => {
expect(dependencies).toHaveLength(1);
expect(dependencies[0]).toEqual(model.properties['reference'].property);
});

describe('containsPropertyType', () => {
test('should find present property type and those who are not', () => {
const stringModel = new ConstrainedStringModel('', undefined, '');
const stringObjectPropertyModel = new ConstrainedObjectPropertyModel('string', '', false, stringModel);
const rawModel = new ConstrainedObjectModel('test', undefined, '', {
string: stringObjectPropertyModel
});
expect(rawModel.containsPropertyType(ConstrainedStringModel)).toEqual(true);
expect(rawModel.containsPropertyType(ConstrainedBooleanModel)).toEqual(false);
});
});
});
describe('EnumModel', () => {
test('should return no dependencies', () => {
Expand Down

0 comments on commit df88e8b

Please sign in to comment.