reorganized code

main
Inga 🏳‍🌈 2 years ago
parent 5eba301199
commit 12faf64595
  1. 22
      src/app.controller.spec.ts
  2. 12
      src/app.controller.ts
  3. 8
      src/app.module.ts
  4. 22
      src/hello-world/controller.spec.ts
  5. 12
      src/hello-world/controller.ts
  6. 2
      src/hello-world/service.ts
  7. 4
      test/app.e2e-spec.ts

@ -1,22 +0,0 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AppController } from './app.controller';
import { AppService } from './app.service';
describe('AppController', () => {
let appController: AppController;
beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService],
}).compile();
appController = app.get<AppController>(AppController);
});
describe('root', () => {
it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!');
});
});
});

@ -1,12 +0,0 @@
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@Get()
getHello(): string {
return this.appService.getHello();
}
}

@ -1,10 +1,10 @@
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { HelloWorldController } from './hello-world/controller';
import { HelloWorldService } from './hello-world/service';
@Module({
imports: [],
controllers: [AppController],
providers: [AppService],
controllers: [HelloWorldController],
providers: [HelloWorldService],
})
export class AppModule {}

@ -0,0 +1,22 @@
import { Test, TestingModule } from '@nestjs/testing';
import { HelloWorldController } from './controller';
import { HelloWorldService } from './service';
describe('HelloWorldController', () => {
let helloWorldController: HelloWorldController;
beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [HelloWorldController],
providers: [HelloWorldService],
}).compile();
helloWorldController = app.get<HelloWorldController>(HelloWorldController);
});
describe('root', () => {
it('should return "Hello World!"', () => {
expect(helloWorldController.getHello()).toBe('Hello World!');
});
});
});

@ -0,0 +1,12 @@
import { Controller, Get } from '@nestjs/common';
import { HelloWorldService } from './service';
@Controller('hello-world')
export class HelloWorldController {
constructor(private readonly helloWorldService: HelloWorldService) {}
@Get()
getHello(): string {
return this.helloWorldService.getHello();
}
}

@ -1,7 +1,7 @@
import { Injectable } from '@nestjs/common';
@Injectable()
export class AppService {
export class HelloWorldService {
getHello(): string {
return 'Hello World!';
}

@ -15,9 +15,9 @@ describe('AppController (e2e)', () => {
await app.init();
});
it('/ (GET)', () => {
it('/hello-world (GET)', () => {
return request(app.getHttpServer())
.get('/')
.get('/hello-world')
.expect(200)
.expect('Hello World!');
});

Loading…
Cancel
Save