@@ -330,17 +330,18 @@ describe('model with one id int', () => {
330330 } ) ;
331331} ) ;
332332
333- it ( 'duplicated fields in exising file' , async ( ) => {
334- await testGenerate ( {
335- schema : `
336- model User {
337- id Int @id
338- }
339- ` ,
340- createSouceFile : {
341- type : 'input' ,
342- name : 'UserCreateInput' ,
343- text : `
333+ describe ( 'duplicated' , ( ) => {
334+ it ( 'duplicated fields in exising file' , async ( ) => {
335+ await testGenerate ( {
336+ schema : `
337+ model User {
338+ id Int @id
339+ }
340+ ` ,
341+ createSouceFile : {
342+ type : 'input' ,
343+ name : 'UserCreateInput' ,
344+ text : `
344345 import { Int } from '@nestjs/graphql';
345346 @InputType()
346347 export class UserCreateInput {
@@ -349,14 +350,41 @@ it('duplicated fields in exising file', async () => {
349350 })
350351 id?: string;
351352 ` ,
352- } ,
353+ } ,
354+ } ) ;
355+ setSourceFile ( '/user-create.input.ts' ) ;
356+ const classFile = sourceFile . getClass ( ( ) => true ) ! ;
357+ const names = classFile . getProperties ( ) . map ( p => p . getName ( ) ) ;
358+ expect ( names ) . toStrictEqual ( [ 'id' ] ) ;
359+ } ) ;
360+
361+ it ( 'duplicated import decorators' , async ( ) => {
362+ await testGenerate ( {
363+ schema : `
364+ model User {
365+ id Int @id
366+ xl Int
367+ xs Int
368+ }
369+ ` ,
370+ createSouceFile : {
371+ type : 'model' ,
372+ name : 'User' ,
373+ text : `
374+ import { Field, ObjectType } from '@nestjs/graphql';
375+ import { Int, ID } from '@nestjs/graphql';
376+ @ObjectType()
377+ export class User {
378+ @Field(() => ID) id: number;
379+ @Field(() => Int) xl: number;
380+ @Field(() => Int) xs: number;
381+ ` ,
382+ } ,
383+ } ) ;
384+ setSourceFile ( 'user.model.ts' ) ;
385+ expect ( imports . filter ( x => x . name === 'Field' ) ) . toHaveLength ( 1 ) ;
386+ expect ( imports . filter ( x => x . name === 'ObjectType' ) ) . toHaveLength ( 1 ) ;
353387 } ) ;
354- sourceFile = project . getSourceFile ( s =>
355- s . getFilePath ( ) . endsWith ( '/user-create.input.ts' ) ,
356- ) ! ;
357- const classFile = sourceFile . getClass ( ( ) => true ) ! ;
358- const names = classFile . getProperties ( ) . map ( p => p . getName ( ) ) ;
359- expect ( names ) . toStrictEqual ( [ 'id' ] ) ;
360388} ) ;
361389
362390describe ( 'one model with scalar types' , ( ) => {
0 commit comments