Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix contains property check failing #810

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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