@@ -126,18 +126,16 @@ describe('transformDefinitions', () => {
126126 // Interface renamed to User
127127 expect ( interfaces . find ( ( i : any ) => i . name === 'User' ) ) . toBeDefined ( )
128128 expect ( interfaces . find ( ( i : any ) => i . name === 'UserDto' ) ) . toBeUndefined ( )
129- // No type alias created when only renaming
130- expect ( configRead . graphs . typings ) . toHaveLength ( 0 )
131129 } )
132130
133- it ( 'creates type alias with custom type when patch provides type override ' , ( ) => {
131+ it ( 'applies name and type when patch provides both ' , ( ) => {
134132 const interfaces : any [ ] = [ ]
135133 provide ( { interfaces, configRead } )
136134 configRead . config . patch = {
137135 definitions : {
138136 SessionDto : {
139137 name : 'Session' ,
140- type : ' { name: string, age: number }' ,
138+ type : [ { name : 'name' , type : ' string' } , { name : ' age' , type : ' number' } ] ,
141139 } ,
142140 } ,
143141 }
@@ -153,11 +151,12 @@ describe('transformDefinitions', () => {
153151 }
154152 transformDefinitions ( definitions as any )
155153
156- // Original interface preserved when type is overridden
157- expect ( interfaces . find ( ( i : any ) => i . name === 'SessionDto' ) ) . toBeDefined ( )
158- expect ( configRead . graphs . typings ) . toHaveLength ( 1 )
159- expect ( configRead . graphs . typings ! [ 0 ] . name ) . toBe ( 'Session' )
160- expect ( configRead . graphs . typings ! [ 0 ] . value ) . toBe ( '{ name: string, age: number }' )
154+ // Interface renamed to Session with patch type as properties
155+ const session = interfaces . find ( ( i : any ) => i . name === 'Session' )
156+ expect ( session ) . toBeDefined ( )
157+ expect ( session ! . properties ) . toHaveLength ( 2 )
158+ expect ( session ! . properties . map ( ( p : any ) => p . name ) ) . toEqual ( [ 'name' , 'age' ] )
159+ expect ( interfaces . find ( ( i : any ) => i . name === 'SessionDto' ) ) . toBeUndefined ( )
161160 } )
162161
163162 it ( 'handles multiple definition patches' , ( ) => {
@@ -182,10 +181,9 @@ describe('transformDefinitions', () => {
182181 }
183182 transformDefinitions ( definitions as any )
184183
185- // Interfaces renamed, no type aliases created
184+ // Interfaces renamed
186185 expect ( interfaces . find ( ( i : any ) => i . name === 'User' ) ) . toBeDefined ( )
187186 expect ( interfaces . find ( ( i : any ) => i . name === 'Order' ) ) . toBeDefined ( )
188- expect ( configRead . graphs . typings ) . toHaveLength ( 0 )
189187 } )
190188
191189 it ( 'renames interface when patch matches transformed name' , ( ) => {
@@ -215,7 +213,6 @@ describe('transformDefinitions', () => {
215213
216214 // Interface renamed to UserAlias (transform: UserDto -> User, patch: User -> UserAlias)
217215 expect ( interfaces . find ( ( i : any ) => i . name === 'UserAlias' ) ) . toBeDefined ( )
218- expect ( configRead . graphs . typings ) . toHaveLength ( 0 )
219216 } )
220217
221218 it ( 'renames interface when patch only renames' , ( ) => {
@@ -275,11 +272,9 @@ describe('transformDefinitions', () => {
275272
276273 // Transform: UserDto -> User
277274 // Patch: User -> UserEntity
278- // Interface should be renamed to UserEntity (no typings created)
279275 expect ( interfaces . find ( ( i : any ) => i . name === 'UserEntity' ) ) . toBeDefined ( )
280276 expect ( interfaces . find ( ( i : any ) => i . name === 'User' ) ) . toBeUndefined ( )
281277 expect ( interfaces . find ( ( i : any ) => i . name === 'UserDto' ) ) . toBeUndefined ( )
282- expect ( configRead . graphs . typings ) . toHaveLength ( 0 )
283278 } )
284279
285280 it ( 'renames interface when transform returns string' , ( ) => {
@@ -301,18 +296,17 @@ describe('transformDefinitions', () => {
301296 // Interface renamed to RenamedType
302297 expect ( interfaces . find ( ( i : any ) => i . name === 'RenamedType' ) ) . toBeDefined ( )
303298 expect ( interfaces . find ( ( i : any ) => i . name === 'OriginalType' ) ) . toBeUndefined ( )
304- expect ( configRead . graphs . typings ) . toHaveLength ( 0 )
305299 } )
306300
307- it ( 'creates type alias with custom type when transform returns object with type' , ( ) => {
301+ it ( 'applies name and type when transform returns object with type' , ( ) => {
308302 const interfaces : any [ ] = [ ]
309303 provide ( { interfaces, configRead } )
310304 configRead . config . transform = {
311305 operation : ( ) => '' ,
312- definition : ( name , type ) => {
306+ definition : ( name ) => {
313307 return {
314308 name : `${ name } Alias` ,
315- type : `Custom ${ type } ` ,
309+ type : [ { name : 'id' , type : 'integer' } ] ,
316310 }
317311 } ,
318312 }
@@ -325,19 +319,19 @@ describe('transformDefinitions', () => {
325319 }
326320 transformDefinitions ( definitions as any )
327321
328- // Original interface preserved when type is overridden
329- expect ( interfaces . find ( ( i : any ) => i . name === 'Test' ) ) . toBeDefined ( )
330- expect ( configRead . graphs . typings ) . toHaveLength ( 1 )
331- expect ( configRead . graphs . typings ! [ 0 ] . name ) . toBe ( 'TestAlias' )
332- expect ( configRead . graphs . typings ! [ 0 ] . value ) . toContain ( 'Custom' )
322+ // Interface renamed to TestAlias with transform type as properties
323+ const testAlias = interfaces . find ( ( i : any ) => i . name === 'TestAlias' )
324+ expect ( testAlias ) . toBeDefined ( )
325+ expect ( testAlias ! . properties ) . toHaveLength ( 1 )
326+ expect ( testAlias ! . properties [ 0 ] ) . toEqual ( { name : 'id' , type : 'integer' , required : undefined , description : undefined } )
333327 } )
334328
335- it ( 'does not create alias when transform returns same name and type' , ( ) => {
329+ it ( 'keeps interface unchanged when transform returns same name and type' , ( ) => {
336330 const interfaces : any [ ] = [ ]
337331 provide ( { interfaces, configRead } )
338332 configRead . config . transform = {
339333 operation : ( ) => '' ,
340- definition : ( name , type ) => ( { name, type } ) , // No-op transform
334+ definition : ( name , properties ) => ( { name, type : properties } ) , // No-op transform
341335 }
342336
343337 const definitions = {
@@ -348,8 +342,8 @@ describe('transformDefinitions', () => {
348342 }
349343 transformDefinitions ( definitions as any )
350344
351- // No typings should be created since nothing changed
352- expect ( configRead . graphs . typings ) . toHaveLength ( 0 )
345+ expect ( interfaces . find ( ( i : any ) => i . name === 'Unchanged' ) ) . toBeDefined ( )
346+ expect ( interfaces . find ( ( i : any ) => i . name === 'Unchanged' ) ! . properties ) . toHaveLength ( 1 )
353347 } )
354348 } )
355349} )
0 commit comments