Skip to content

Commit

Permalink
add tests for enum schema types
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur Kraft committed Mar 9, 2024
1 parent 7230915 commit 11f6ac5
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion test/services/schema-object-factory.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { ApiExtension, ApiProperty } from '../../lib/decorators';
import { SchemasObject } from '../../lib/interfaces/open-api-spec.interface';
import { BaseParameterObject, SchemasObject } from '../../lib/interfaces/open-api-spec.interface';
import { ModelPropertiesAccessor } from '../../lib/services/model-properties-accessor';
import { SchemaObjectFactory } from '../../lib/services/schema-object-factory';
import { SwaggerTypesMapper } from '../../lib/services/swagger-types-mapper';
import { CreateUserDto } from './fixtures/create-user.dto';
import { ParamWithTypeMetadata } from '../../lib/services/parameter-metadata-accessor';

describe('SchemaObjectFactory', () => {
let modelPropertiesAccessor: ModelPropertiesAccessor;
Expand Down Expand Up @@ -328,4 +329,44 @@ describe('SchemaObjectFactory', () => {
expect(schemas).toEqual({ MyEnum: { enum: [1, 2, 3], type: 'number' } });
});
});

describe('createEnumParam', () => {
it('should create an enum schema definition', () => {
const params: ParamWithTypeMetadata & BaseParameterObject = {
required: true,
isArray: false,
enumName: 'MyEnum',
enum: ['a', 'b', 'c']
}
const schemas = {};
schemaObjectFactory.createEnumParam(params, schemas)

expect(schemas['MyEnum']).toEqual({
enum: ['a', 'b', 'c'],
type: 'string'
})
})

it('should create an enum schema definition for an array', () => {
const params: ParamWithTypeMetadata & BaseParameterObject = {
required: true,
isArray: true,
enumName: 'MyEnum',
schema: {
type: 'array',
items: {
type: 'string',
enum: ['a', 'b', 'c']
}
}
}
const schemas = {};
schemaObjectFactory.createEnumParam(params, schemas)

expect(schemas['MyEnum']).toEqual({
enum: ['a', 'b', 'c'],
type: 'string'
})
})
})
});

0 comments on commit 11f6ac5

Please sign in to comment.