Skip to content

Commit 11f6ac5

Browse files
author
Artur Kraft
committedMar 9, 2024
add tests for enum schema types
1 parent 7230915 commit 11f6ac5

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed
 

‎test/services/schema-object-factory.spec.ts

+42-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { ApiExtension, ApiProperty } from '../../lib/decorators';
2-
import { SchemasObject } from '../../lib/interfaces/open-api-spec.interface';
2+
import { BaseParameterObject, SchemasObject } from '../../lib/interfaces/open-api-spec.interface';
33
import { ModelPropertiesAccessor } from '../../lib/services/model-properties-accessor';
44
import { SchemaObjectFactory } from '../../lib/services/schema-object-factory';
55
import { SwaggerTypesMapper } from '../../lib/services/swagger-types-mapper';
66
import { CreateUserDto } from './fixtures/create-user.dto';
7+
import { ParamWithTypeMetadata } from '../../lib/services/parameter-metadata-accessor';
78

89
describe('SchemaObjectFactory', () => {
910
let modelPropertiesAccessor: ModelPropertiesAccessor;
@@ -328,4 +329,44 @@ describe('SchemaObjectFactory', () => {
328329
expect(schemas).toEqual({ MyEnum: { enum: [1, 2, 3], type: 'number' } });
329330
});
330331
});
332+
333+
describe('createEnumParam', () => {
334+
it('should create an enum schema definition', () => {
335+
const params: ParamWithTypeMetadata & BaseParameterObject = {
336+
required: true,
337+
isArray: false,
338+
enumName: 'MyEnum',
339+
enum: ['a', 'b', 'c']
340+
}
341+
const schemas = {};
342+
schemaObjectFactory.createEnumParam(params, schemas)
343+
344+
expect(schemas['MyEnum']).toEqual({
345+
enum: ['a', 'b', 'c'],
346+
type: 'string'
347+
})
348+
})
349+
350+
it('should create an enum schema definition for an array', () => {
351+
const params: ParamWithTypeMetadata & BaseParameterObject = {
352+
required: true,
353+
isArray: true,
354+
enumName: 'MyEnum',
355+
schema: {
356+
type: 'array',
357+
items: {
358+
type: 'string',
359+
enum: ['a', 'b', 'c']
360+
}
361+
}
362+
}
363+
const schemas = {};
364+
schemaObjectFactory.createEnumParam(params, schemas)
365+
366+
expect(schemas['MyEnum']).toEqual({
367+
enum: ['a', 'b', 'c'],
368+
type: 'string'
369+
})
370+
})
371+
})
331372
});

0 commit comments

Comments
 (0)
Please sign in to comment.