@@ -3,81 +3,58 @@ import { SchematicTestRunner } from '@angular-devkit/schematics/testing';
33import * as path from 'path' ;
44
55describe ( 'Controller Factory' , ( ) => {
6- const runner : SchematicTestRunner = new SchematicTestRunner (
7- '.' ,
8- path . join ( process . cwd ( ) , 'src/collection.json' ) ,
9- ) ;
6+ const runner : SchematicTestRunner = new SchematicTestRunner ( '.' , path . join ( process . cwd ( ) , 'src/collection.json' ) ) ;
107 it ( 'should manage name only' , ( ) => {
118 const optionsApp : object = {
129 name : 'project' ,
1310 spec : false ,
1411 } ;
15- let app ;
16- app = runner . runSchematicAsync ( 'controller' , optionsApp ) ;
17- app . subscribe ( tree => {
12+ runner . runSchematicAsync ( 'controller' , optionsApp ) . subscribe ( tree => {
1813 const files : string [ ] = tree . files ;
19- expect (
20- files . find ( filename => filename === '/src/app/controllers/project.controller.ts' ) ,
21- ) . toBeDefined ( ) ;
22- expect (
23- files . find ( filename => filename === '/src/app/controllers/project.controller.spec.ts' ) ,
24- ) . not . toBeDefined ( ) ;
14+ expect ( files . find ( filename => filename === '/src/app/controllers/project.controller.ts' ) ) . toBeDefined ( ) ;
15+ expect ( files . find ( filename => filename === '/src/app/controllers/project.controller.spec.ts' ) ) . not . toBeDefined ( ) ;
2516 expect ( tree . readContent ( '/src/app/controllers/project.controller.ts' ) ) . toEqual (
2617 "import { Controller } from '@nestjs/common';\n" +
27- '\n' +
28- "@Controller('projects')\n" +
29- 'export class ProjectController {}\n' ,
18+ '\n' +
19+ "@Controller('projects')\n" +
20+ 'export class ProjectController {}\n' ,
3021 ) ;
31- } )
32-
22+ } ) ;
3323 } ) ;
3424 it ( 'should manage name and path' , ( ) => {
3525 const optionsApp : object = {
3626 name : 'foo' ,
3727 path : 'bar' ,
3828 skipImport : true ,
3929 } ;
40- runner . runSchematicAsync ( 'controller' , optionsApp )
41- . subscribe ( tree => {
42- const files : string [ ] = tree . files ;
43- expect (
44- files . find ( filename => filename === '/bar/src/app/controllers/foo.controller.ts' ) ,
45- ) . toBeDefined ( ) ;
46- expect (
47- files . find ( filename => filename === '/bar/src/app/controllers/foo.controller.spec.ts' ) ,
48- ) . toBeDefined ( ) ;
49- expect ( tree . readContent ( '/bar/src/app/controllers/foo.controller.ts' ) ) . toEqual (
50- "import { Controller } from '@nestjs/common';\n" +
30+ runner . runSchematicAsync ( 'controller' , optionsApp ) . subscribe ( tree => {
31+ const files : string [ ] = tree . files ;
32+ expect ( files . find ( filename => filename === '/bar/src/app/controllers/foo.controller.ts' ) ) . toBeDefined ( ) ;
33+ expect ( files . find ( filename => filename === '/bar/src/app/controllers/foo.controller.spec.ts' ) ) . toBeDefined ( ) ;
34+ expect ( tree . readContent ( '/bar/src/app/controllers/foo.controller.ts' ) ) . toEqual (
35+ "import { Controller } from '@nestjs/common';\n" +
5136 '\n' +
5237 "@Controller('foos')\n" +
5338 'export class FooController {}\n' ,
54- ) ;
55- } ) ;
39+ ) ;
40+ } ) ;
5641 } ) ;
5742 it ( 'should manage name to dasherize' , ( ) => {
5843 const optionsApp : object = {
5944 name : 'fooBar' ,
6045 skipImport : true ,
6146 } ;
62- runner . runSchematicAsync ( 'controller' , optionsApp )
63- . subscribe ( tree => {
64- const files : string [ ] = tree . files ;
65- expect (
66- files . find ( filename => filename === '/src/app/controllers/foo-bar.controller.ts' ) ,
67- ) . toBeDefined ( ) ;
68- expect (
69- files . find (
70- filename => filename === '/src/app/controllers/foo-bar.controller.spec.ts' ,
71- ) ,
72- ) . toBeDefined ( ) ;
73- expect ( tree . readContent ( '/src/app/controllers/foo-bar.controller.ts' ) ) . toEqual (
74- "import { Controller } from '@nestjs/common';\n" +
47+ runner . runSchematicAsync ( 'controller' , optionsApp ) . subscribe ( tree => {
48+ const files : string [ ] = tree . files ;
49+ expect ( files . find ( filename => filename === '/src/app/controllers/foo-bar.controller.ts' ) ) . toBeDefined ( ) ;
50+ expect ( files . find ( filename => filename === '/src/app/controllers/foo-bar.controller.spec.ts' ) ) . toBeDefined ( ) ;
51+ expect ( tree . readContent ( '/src/app/controllers/foo-bar.controller.ts' ) ) . toEqual (
52+ "import { Controller } from '@nestjs/common';\n" +
7553 '\n' +
7654 "@Controller('foo-bars')\n" +
7755 'export class FooBarController {}\n' ,
78- ) ;
79- } )
80-
56+ ) ;
57+ } ) ;
8158 } ) ;
8259 it ( 'should manage declaration in app module' , ( ) => {
8360 const optionsApp : object = {
@@ -86,25 +63,23 @@ describe('Controller Factory', () => {
8663 const optionsModule : object = {
8764 name : 'foo' ,
8865 } ;
89- runner . runSchematicAsync ( 'application' , optionsApp )
90- . subscribe ( tree => {
91- runner . runSchematicAsync ( 'controller' , optionsModule , tree )
92- . subscribe ( tree => {
93- expect ( tree . readContent ( normalize ( '/src/app/app.module.ts' ) ) ) . toEqual (
94- "import { Module } from '@nestjs/common';\n" +
95- "import { AppController } from './app.controller';\n" +
96- "import { AppService } from './app.service';\n" +
97- "import { CoreModule } from './core/core.module';\n" +
98- "import { FooController } from './controllers/foo.controller';\n" +
99- '\n' +
100- '@Module({\n' +
101- ' imports: [CoreModule],\n' +
102- ' controllers: [FooController, AppController],\n' +
103- ' providers: [AppService],\n' +
104- '})\n' +
105- 'export class AppModule {}\n' ,
106- ) ;
107- } )
108- } )
66+ runner . runSchematicAsync ( 'application' , optionsApp ) . subscribe ( tree => {
67+ runner . runSchematicAsync ( 'controller' , optionsModule , tree ) . subscribe ( tree => {
68+ expect ( tree . readContent ( normalize ( '/src/app/app.module.ts' ) ) ) . toEqual (
69+ "import { Module } from '@nestjs/common';\n" +
70+ "import { AppController } from './app.controller';\n" +
71+ "import { AppService } from './app.service';\n" +
72+ "import { CoreModule } from './core/core.module';\n" +
73+ "import { FooController } from './controllers/foo.controller';\n" +
74+ '\n' +
75+ '@Module({\n' +
76+ ' imports: [CoreModule],\n' +
77+ ' controllers: [FooController, AppController],\n' +
78+ ' providers: [AppService],\n' +
79+ '})\n' +
80+ 'export class AppModule {}\n' ,
81+ ) ;
82+ } ) ;
83+ } ) ;
10984 } ) ;
110- } ) ;
85+ } ) ;
0 commit comments