From dc48ef1aaa9f66ea898f895561b123057ba1c8b4 Mon Sep 17 00:00:00 2001 From: Juan Miguel Besada Date: Mon, 15 Feb 2021 21:10:14 +0100 Subject: [PATCH] chore(): Add tests --- test/plugin/controller-class-visitor.spec.ts | 14 +++ .../fixtures/enhanced-comments.controller.ts | 109 ++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 test/plugin/fixtures/enhanced-comments.controller.ts diff --git a/test/plugin/controller-class-visitor.spec.ts b/test/plugin/controller-class-visitor.spec.ts index 0e75b804c..a376f6c0a 100644 --- a/test/plugin/controller-class-visitor.spec.ts +++ b/test/plugin/controller-class-visitor.spec.ts @@ -4,6 +4,10 @@ import { appControllerText, appControllerTextTranspiled } from './fixtures/app.controller'; +import { + enhancedCommentsControllerText, + enhancedCommentsControllerTextTranspiled +} from './fixtures/enhanced-comments.controller'; const compilerOptions: ts.CompilerOptions = { module: ts.ModuleKind.CommonJS, @@ -40,4 +44,14 @@ describe('Controller methods', () => { expect(result.outputText).toEqual(appControllerTextTranspiled); }); + + it('Should generate summary and description if no controllerKeyOfComments', () => { + const result = transpileModule( + 'enhanced-comments.controller.ts', + enhancedCommentsControllerText, + compilerOptions, + { controllerKeyOfComment: null } + ); + expect(result.outputText).toEqual(enhancedCommentsControllerTextTranspiled); + }) }); diff --git a/test/plugin/fixtures/enhanced-comments.controller.ts b/test/plugin/fixtures/enhanced-comments.controller.ts new file mode 100644 index 000000000..b775b9c09 --- /dev/null +++ b/test/plugin/fixtures/enhanced-comments.controller.ts @@ -0,0 +1,109 @@ +export const enhancedCommentsControllerText = `import { Controller, Post, HttpStatus } from '@nestjs/common'; +import { ApiOperation } from '@nestjs/swagger'; + +class Cat {} + +@Controller('cats') +export class EnhancedCommentsController { + onApplicationBootstrap() {} + + /** + * create a Cat + * + * @remarks + * Create a super nice cat + * + * @returns {Promise} + * @memberof AppController + */ + @Post() + async create(): Promise {} + + /** + * find a Cat + * + * @remarks + * Find the best cat in the world + */ + @ApiOperation({}) + @Get() + async findOne(): Promise {} + + /** + * find all Cats im comment + * + * @remarks + * Find all cats while you write comments + * + * @returns {Promise} + * @memberof AppController + */ + @ApiOperation({ + summary: 'find all Cats', + description: 'Find all cats while you write decorators' + }) + @Get() + @HttpCode(HttpStatus.NO_CONTENT) + async findAll(): Promise {} +}`; + +export const enhancedCommentsControllerTextTranspiled = `"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.EnhancedCommentsController = void 0; +const openapi = require("@nestjs/swagger"); +const common_1 = require("@nestjs/common"); +const swagger_1 = require("@nestjs/swagger"); +class Cat { +} +let EnhancedCommentsController = class EnhancedCommentsController { + onApplicationBootstrap() { } + /** + * create a Cat + * + * @remarks + * Create a super nice cat + * + * @returns {Promise} + * @memberof AppController + */ + async create() { } + /** + * find a Cat + * + * @remarks + * Find the best cat in the world + */ + async findOne() { } + /** + * find all Cats im comment + * + * @remarks + * Find all cats while you write comments + * + * @returns {Promise} + * @memberof AppController + */ + async findAll() { } +}; +__decorate([ + openapi.ApiOperation({ summary: "create a Cat", description: "Create a super nice cat" }), + common_1.Post(), + openapi.ApiResponse({ status: 201, type: Cat }) +], EnhancedCommentsController.prototype, "create", null); +__decorate([ + swagger_1.ApiOperation({ summary: "find a Cat", description: "Find the best cat in the world" }), + Get(), + openapi.ApiResponse({ status: 200, type: Cat }) +], EnhancedCommentsController.prototype, "findOne", null); +__decorate([ + swagger_1.ApiOperation({ summary: 'find all Cats', + description: 'Find all cats while you write decorators' }), + Get(), + HttpCode(common_1.HttpStatus.NO_CONTENT), + openapi.ApiResponse({ status: common_1.HttpStatus.NO_CONTENT, type: [Cat] }) +], EnhancedCommentsController.prototype, "findAll", null); +EnhancedCommentsController = __decorate([ + common_1.Controller('cats') +], EnhancedCommentsController); +exports.EnhancedCommentsController = EnhancedCommentsController; +`;