@@ -32,6 +32,12 @@ describe('SchemaObjectFactory', () => {
3232 Neighboard = 'neighboard'
3333 }
3434
35+ enum Ranking {
36+ First = 1 ,
37+ Second = 2 ,
38+ Third = 3
39+ }
40+
3541 class CreatePersonDto {
3642 @ApiProperty ( )
3743 name : string ;
@@ -42,21 +48,36 @@ describe('SchemaObjectFactory', () => {
4248 class Person {
4349 @ApiProperty ( { enum : Role , enumName : 'Role' } )
4450 role : Role ;
51+
4552 @ApiProperty ( { enum : Role , enumName : 'Role' , isArray : true } )
4653 roles : Role [ ] ;
54+
55+ @ApiProperty ( { enum : Group , enumName : 'Group' , isArray : true } )
56+ groups : Group [ ] ;
57+
58+ @ApiProperty ( { enum : Ranking , enumName : 'Ranking' , isArray : true } )
59+ rankings : Ranking [ ] ;
4760 }
4861
4962 it ( 'should explore enum' , ( ) => {
5063 const schemas : Record < string , SchemasObject > = { } ;
5164 schemaObjectFactory . exploreModelSchema ( Person , schemas ) ;
5265
53- expect ( Object . keys ( schemas ) ) . toHaveLength ( 2 ) ;
66+ expect ( Object . keys ( schemas ) ) . toHaveLength ( 4 ) ;
5467
5568 expect ( schemas ) . toHaveProperty ( 'Role' ) ;
5669 expect ( schemas . Role ) . toEqual ( {
5770 type : 'string' ,
5871 enum : [ 'admin' , 'user' ]
5972 } ) ;
73+ expect ( schemas . Group ) . toEqual ( {
74+ type : 'string' ,
75+ enum : [ 'user' , 'guest' , 'family' , 'neighboard' ]
76+ } ) ;
77+ expect ( schemas . Ranking ) . toEqual ( {
78+ type : 'number' ,
79+ enum : [ 1 , 2 , 3 ]
80+ } ) ;
6081 expect ( schemas ) . toHaveProperty ( 'Person' ) ;
6182 expect ( schemas . Person ) . toEqual ( {
6283 type : 'object' ,
@@ -69,14 +90,25 @@ describe('SchemaObjectFactory', () => {
6990 items : {
7091 $ref : '#/components/schemas/Role'
7192 }
93+ } ,
94+ groups : {
95+ type : 'array' ,
96+ items : {
97+ $ref : '#/components/schemas/Group'
98+ }
99+ } ,
100+ rankings : {
101+ type : 'array' ,
102+ items : {
103+ $ref : '#/components/schemas/Ranking'
104+ }
72105 }
73106 } ,
74- required : [ 'role' , 'roles' ]
107+ required : [ 'role' , 'roles' , 'groups' , 'rankings' ]
75108 } ) ;
76-
77109 schemaObjectFactory . exploreModelSchema ( CreatePersonDto , schemas ) ;
78110
79- expect ( Object . keys ( schemas ) ) . toHaveLength ( 3 ) ;
111+ expect ( Object . keys ( schemas ) ) . toHaveLength ( 5 ) ;
80112 expect ( schemas ) . toHaveProperty ( 'CreatePersonDto' ) ;
81113 expect ( schemas . CreatePersonDto ) . toEqual ( {
82114 type : 'object' ,
@@ -276,9 +308,9 @@ describe('SchemaObjectFactory', () => {
276308 isArray : false
277309 } ;
278310 const schemas = { } ;
279-
311+
280312 schemaObjectFactory . createEnumSchemaType ( 'field' , metadata , schemas ) ;
281-
313+
282314 expect ( schemas ) . toEqual ( { MyEnum : { enum : [ 1 , 2 , 3 ] , type : 'number' } } ) ;
283315 } ) ;
284316 } ) ;
0 commit comments