@@ -4,13 +4,11 @@ import { Project, SourceFile } from 'ts-morph';
4
4
import { testSourceFile } from './helpers' ;
5
5
import { testGenerate } from './test-generate' ;
6
6
7
- let sourceFile : SourceFile ;
8
7
let project : Project ;
9
- let sourceFiles : SourceFile [ ] ;
10
8
11
9
describe ( 'custom decorators namespace both input and output' , ( ) => {
12
10
before ( async ( ) => {
13
- ( { project, sourceFiles } = await testGenerate ( {
11
+ ( { project } = await testGenerate ( {
14
12
schema : `
15
13
model User {
16
14
id Int @id
@@ -153,7 +151,7 @@ describe('custom decorators namespace both input and output', () => {
153
151
154
152
describe ( 'fieldtype disable output' , ( ) => {
155
153
before ( async ( ) => {
156
- ( { project, sourceFiles } = await testGenerate ( {
154
+ ( { project } = await testGenerate ( {
157
155
schema : `
158
156
model User {
159
157
id String @id @default(cuid())
@@ -182,7 +180,7 @@ describe('fieldtype disable output', () => {
182
180
183
181
describe ( 'custom decorators and description' , ( ) => {
184
182
before ( async ( ) => {
185
- ( { project, sourceFiles } = await testGenerate ( {
183
+ ( { project } = await testGenerate ( {
186
184
schema : `
187
185
model User {
188
186
/// user id really
@@ -225,7 +223,7 @@ describe('custom decorators and description', () => {
225
223
226
224
describe ( 'custom decorators default import' , ( ) => {
227
225
before ( async ( ) => {
228
- ( { project, sourceFiles } = await testGenerate ( {
226
+ ( { project } = await testGenerate ( {
229
227
schema : `
230
228
model User {
231
229
id Int @id
@@ -265,7 +263,7 @@ describe('custom decorators default import', () => {
265
263
266
264
describe ( 'default import alternative syntax' , ( ) => {
267
265
before ( async ( ) => {
268
- ( { project, sourceFiles } = await testGenerate ( {
266
+ ( { project } = await testGenerate ( {
269
267
schema : `
270
268
model User {
271
269
id Int @id
@@ -303,7 +301,7 @@ describe('default import alternative syntax', () => {
303
301
304
302
describe ( 'custom decorators field custom type namespace' , ( ) => {
305
303
before ( async ( ) => {
306
- ( { project, sourceFiles } = await testGenerate ( {
304
+ ( { project } = await testGenerate ( {
307
305
schema : `
308
306
model User {
309
307
id Int @id
@@ -368,7 +366,7 @@ describe('custom decorators field custom type namespace', () => {
368
366
369
367
describe ( 'decorate option' , ( ) => {
370
368
before ( async ( ) => {
371
- ( { project, sourceFiles } = await testGenerate ( {
369
+ ( { project } = await testGenerate ( {
372
370
schema : `
373
371
model User {
374
372
id Int @id @default(autoincrement())
@@ -460,7 +458,7 @@ describe('decorate option', () => {
460
458
461
459
describe ( 'model decorate' , ( ) => {
462
460
before ( async ( ) => {
463
- ( { project, sourceFiles } = await testGenerate ( {
461
+ ( { project } = await testGenerate ( {
464
462
schema : `
465
463
/// @NG.Directive('@extends')
466
464
/// @NG.Directive('@key(fields: "id")')
@@ -511,3 +509,57 @@ describe('model decorate', () => {
511
509
expect ( s . propertyDecorators ?. find ( d => d . name === 'Directive' ) ) . toBeFalsy ( ) ;
512
510
} ) ;
513
511
} ) ;
512
+
513
+ describe ( 'model directive' , ( ) => {
514
+ before ( async ( ) => {
515
+ ( { project } = await testGenerate ( {
516
+ schema : `
517
+ /// @Directive({ arguments: ['@extends'] })
518
+ /// @Directive({ arguments: ['@key(fields: "id")'] })
519
+ model User {
520
+ /// @Directive({ arguments: ['@external'] })
521
+ id String @id
522
+ }` ,
523
+ options : [ `outputFilePattern = "{name}.{type}.ts"` ] ,
524
+ } ) ) ;
525
+ } ) ;
526
+
527
+ it ( 'user model id property' , ( ) => {
528
+ const s = testSourceFile ( {
529
+ project,
530
+ file : 'user.model.ts' ,
531
+ property : 'id' ,
532
+ } ) ;
533
+ console . log ( 's.sourceText' , s . sourceText ) ;
534
+ expect ( s . propertyDecorators ?. find ( d => d . name === 'Directive' ) ) . toBeTruthy ( ) ;
535
+ expect (
536
+ s . propertyDecorators ?. find ( d => d . name === 'Directive' ) ?. arguments ?. [ 0 ] ,
537
+ ) . toBe ( "'@external'" ) ;
538
+ } ) ;
539
+
540
+ it ( 'user model class' , ( ) => {
541
+ const s = testSourceFile ( {
542
+ project,
543
+ file : 'user.model.ts' ,
544
+ } ) ;
545
+ expect ( s . namedImports ) . toContainEqual ( {
546
+ name : 'Directive' ,
547
+ specifier : '@nestjs/graphql' ,
548
+ } ) ;
549
+ expect ( s . classFile . getDecorator ( 'Directive' ) ) . toBeTruthy ( ) ;
550
+ } ) ;
551
+
552
+ it ( 'usergroupby should not have ng.directive' , ( ) => {
553
+ const s = testSourceFile ( {
554
+ project,
555
+ file : 'user-group-by.output.ts' ,
556
+ property : 'id' ,
557
+ } ) ;
558
+ expect ( s . propertyDecorators ) . toHaveLength ( 1 ) ;
559
+ expect ( s . propertyDecorators ?. find ( d => d . name === 'Directive' ) ) . toBeFalsy ( ) ;
560
+ expect ( s . namedImports ) . not . toContainEqual ( {
561
+ name : 'Directive' ,
562
+ specifier : '@nestjs/graphql' ,
563
+ } ) ;
564
+ } ) ;
565
+ } ) ;
0 commit comments