Skip to content

Commit

Permalink
chore: remove unused functions (#849)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaslagoni authored Sep 12, 2022
1 parent 9429a9d commit df79548
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 78 deletions.
24 changes: 0 additions & 24 deletions src/helpers/TypeHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,5 @@
import { CommonModel } from '../models';
import { ConstrainedAnyModel, ConstrainedBooleanModel, ConstrainedFloatModel, ConstrainedIntegerModel, ConstrainedMetaModel, ConstrainedObjectModel, ConstrainedReferenceModel, ConstrainedStringModel, ConstrainedTupleModel, ConstrainedArrayModel, ConstrainedUnionModel, ConstrainedEnumModel, ConstrainedDictionaryModel } from '../models/ConstrainedMetaModel';

export enum ModelKind {
OBJECT = 'object',
ARRAY = 'array',
ENUM = 'enum',
UNION = 'union',
PRIMITIVE = 'primitive',
}

export class TypeHelpers {
/**
* Returns the type (object | array | union | enum | primitive) of the model
* @param model to check
* @returns {ModelKind}
*/
static extractKind(model: CommonModel): ModelKind {
if (model.type === 'object') {return ModelKind.OBJECT;}
if (model.type === 'array') {return ModelKind.ARRAY;}
if (Array.isArray(model.enum)) {return ModelKind.ENUM;}
if (Array.isArray(model.type)) {return ModelKind.UNION;}
return ModelKind.PRIMITIVE;
}
}

export type TypeContext<T extends ConstrainedMetaModel, Options> = {
propertyKey?: string,
options: Options,
Expand Down
55 changes: 1 addition & 54 deletions test/helpers/TypeHelpers.spec.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,7 @@
import { TypeHelpers, ModelKind, getTypeFromMapping, TypeMapping } from '../../src/helpers';
import { getTypeFromMapping, TypeMapping } from '../../src/helpers';
import { CommonModel, ConstrainedAnyModel, ConstrainedArrayModel, ConstrainedBooleanModel, ConstrainedDictionaryModel, ConstrainedEnumModel, ConstrainedFloatModel, ConstrainedIntegerModel, ConstrainedMetaModel, ConstrainedObjectModel, ConstrainedReferenceModel, ConstrainedStringModel, ConstrainedTupleModel, ConstrainedUnionModel } from '../../src/models';

describe('TypeHelpers', () => {
describe('extractKind', () => {
test('should return object', () => {
const model = new CommonModel();
model.type = 'object';
const kind = TypeHelpers.extractKind(model);

expect(kind).toEqual(ModelKind.OBJECT);
});

test('should return array', () => {
const model = new CommonModel();
model.type = 'array';
const kind = TypeHelpers.extractKind(model);

expect(kind).toEqual(ModelKind.ARRAY);
});

test('should return enum', () => {
const model = new CommonModel();
model.type = 'string';
model.enum = ['someValue1', 'someValue2'];
const kind = TypeHelpers.extractKind(model);

expect(kind).toEqual(ModelKind.ENUM);
});

test('should return union', () => {
const model = new CommonModel();
model.type = ['number', 'string'];
const kind = TypeHelpers.extractKind(model);

expect(kind).toEqual(ModelKind.UNION);
});

test('should return primitive', () => {
const model = new CommonModel();
model.type = 'string';
let kind = TypeHelpers.extractKind(model);
expect(kind).toEqual(ModelKind.PRIMITIVE);

model.type = 'number';
kind = TypeHelpers.extractKind(model);
expect(kind).toEqual(ModelKind.PRIMITIVE);

model.type = 'integer';
kind = TypeHelpers.extractKind(model);
expect(kind).toEqual(ModelKind.PRIMITIVE);

model.type = 'boolean';
kind = TypeHelpers.extractKind(model);
expect(kind).toEqual(ModelKind.PRIMITIVE);
});
});
describe('getTypeFromMapping', () => {
const typeMapping: TypeMapping<any> = {
Object: jest.fn().mockReturnValue('test'),
Expand Down

0 comments on commit df79548

Please sign in to comment.