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';
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', () => {});

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

View File

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