WIP: Testing api doc generation

This commit is contained in:
Thom Werring 2024-03-24 14:30:39 +01:00
parent 9279438c20
commit ad84d1f837
3 changed files with 39 additions and 27 deletions

View File

@ -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!');
});
});
});

View File

@ -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';
} }
} }

View File

@ -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!';
} }
} }