WIP: Testing api doc generation
This commit is contained in:
parent
9279438c20
commit
ad84d1f837
|
|
@ -1,22 +1 @@
|
|||
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!');
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('AppController', () => {});
|
||||
|
|
|
|||
|
|
@ -1,12 +1,34 @@
|
|||
import { Controller, Get } from '@nestjs/common';
|
||||
import {
|
||||
Body,
|
||||
ClassSerializerInterceptor,
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
UseInterceptors,
|
||||
} from '@nestjs/common';
|
||||
import { AppService } from './app.service';
|
||||
import { ApiBody, ApiExtraModels, getSchemaPath } from '@nestjs/swagger';
|
||||
import { TrackingDto } from '@/dtos/tracking.dto';
|
||||
|
||||
@Controller()
|
||||
@ApiExtraModels(TrackingDto)
|
||||
@UseInterceptors(ClassSerializerInterceptor)
|
||||
export class AppController {
|
||||
constructor(private readonly appService: AppService) {}
|
||||
|
||||
@Get()
|
||||
getHello(): string {
|
||||
return this.appService.getHello();
|
||||
debug(): unknown {
|
||||
return this.appService.debug();
|
||||
}
|
||||
|
||||
@Post()
|
||||
@ApiBody({
|
||||
schema: {
|
||||
$ref: getSchemaPath(TrackingDto),
|
||||
},
|
||||
})
|
||||
test(@Body() body: TrackingDto): string {
|
||||
console.log(body);
|
||||
return 'ok';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,19 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { ContainerEntity } from '@/entities/container.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
getHello(): string {
|
||||
return 'Hello World!';
|
||||
constructor(
|
||||
@InjectRepository(ContainerEntity)
|
||||
private readonly containerRepository: Repository<ContainerEntity>,
|
||||
) {}
|
||||
async debug(): Promise<unknown> {
|
||||
return this.containerRepository.find({
|
||||
take: 5,
|
||||
});
|
||||
|
||||
// return 'Hello World!';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue