wip nest course
This commit is contained in:
22
tests_hugo/nest_app/src/app.controller.spec.ts
Normal file
22
tests_hugo/nest_app/src/app.controller.spec.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
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!');
|
||||
});
|
||||
});
|
||||
});
|
||||
12
tests_hugo/nest_app/src/app.controller.ts
Normal file
12
tests_hugo/nest_app/src/app.controller.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
11
tests_hugo/nest_app/src/app.module.ts
Normal file
11
tests_hugo/nest_app/src/app.module.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { CoffeesController } from './coffees/coffees.controller';
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
controllers: [AppController, CoffeesController],
|
||||
providers: [AppService],
|
||||
})
|
||||
export class AppModule {}
|
||||
8
tests_hugo/nest_app/src/app.service.ts
Normal file
8
tests_hugo/nest_app/src/app.service.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
getHello(): string {
|
||||
return 'Hello nest!';
|
||||
}
|
||||
}
|
||||
18
tests_hugo/nest_app/src/coffees/coffees.controller.spec.ts
Normal file
18
tests_hugo/nest_app/src/coffees/coffees.controller.spec.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { CoffeesController } from './coffees.controller';
|
||||
|
||||
describe('CoffeesController', () => {
|
||||
let controller: CoffeesController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [CoffeesController],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<CoffeesController>(CoffeesController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
51
tests_hugo/nest_app/src/coffees/coffees.controller.ts
Normal file
51
tests_hugo/nest_app/src/coffees/coffees.controller.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Param,
|
||||
Post,
|
||||
Body,
|
||||
HttpCode,
|
||||
HttpStatus,
|
||||
Patch,
|
||||
Delete,
|
||||
Query
|
||||
} from '@nestjs/common';
|
||||
|
||||
@Controller('coffees')
|
||||
export class CoffeesController {
|
||||
|
||||
@Get()
|
||||
findAll(@Query() paginationQuery) {
|
||||
const { limit, offset } = paginationQuery;
|
||||
return `this action returns all the coffees.
|
||||
limit: ${limit},
|
||||
offset: ${offset}
|
||||
`;
|
||||
}
|
||||
|
||||
@Get('flavors')
|
||||
findFlavors() {
|
||||
return 'this action returns the coffees flavors';
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string) {
|
||||
return `this action returns #${id} coffees`;
|
||||
}
|
||||
|
||||
@Post()
|
||||
@HttpCode(HttpStatus.GONE)
|
||||
create(@Body() body) {
|
||||
return body;
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() body) {
|
||||
return `this action updates #${id} coffee`;
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return `this action removes #${id} coffee`;
|
||||
}
|
||||
}
|
||||
8
tests_hugo/nest_app/src/main.ts
Normal file
8
tests_hugo/nest_app/src/main.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { AppModule } from './app.module';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
await app.listen(3000);
|
||||
}
|
||||
bootstrap();
|
||||
Reference in New Issue
Block a user