WIP: Testing api doc generation
This commit is contained in:
parent
9279438c20
commit
ad84d1f837
|
|
@ -1,22 +1 @@
|
||||||
import { Test, TestingModule } from '@nestjs/testing';
|
describe('AppController', () => {});
|
||||||
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 +1,34 @@
|
||||||
import { Controller, Get } from '@nestjs/common';
|
import {
|
||||||
|
Body,
|
||||||
|
ClassSerializerInterceptor,
|
||||||
|
Controller,
|
||||||
|
Get,
|
||||||
|
Post,
|
||||||
|
UseInterceptors,
|
||||||
|
} from '@nestjs/common';
|
||||||
import { AppService } from './app.service';
|
import { AppService } from './app.service';
|
||||||
|
import { ApiBody, ApiExtraModels, getSchemaPath } from '@nestjs/swagger';
|
||||||
|
import { TrackingDto } from '@/dtos/tracking.dto';
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
|
@ApiExtraModels(TrackingDto)
|
||||||
|
@UseInterceptors(ClassSerializerInterceptor)
|
||||||
export class AppController {
|
export class AppController {
|
||||||
constructor(private readonly appService: AppService) {}
|
constructor(private readonly appService: AppService) {}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
getHello(): string {
|
debug(): unknown {
|
||||||
return this.appService.getHello();
|
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 { Injectable } from '@nestjs/common';
|
||||||
|
import { ContainerEntity } from '@/entities/container.entity';
|
||||||
|
import { Repository } from 'typeorm';
|
||||||
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AppService {
|
export class AppService {
|
||||||
getHello(): string {
|
constructor(
|
||||||
return 'Hello World!';
|
@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