From a930565c61c373d70fa2cace6e541959064fdb20 Mon Sep 17 00:00:00 2001 From: Xantass Date: Tue, 26 Nov 2024 16:10:55 -0500 Subject: [PATCH] fix: the route 'api/health' only return a status code --- src/modules/health/health.controller.spec.ts | 18 +++++++++--------- src/modules/health/health.controller.ts | 11 +++-------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/modules/health/health.controller.spec.ts b/src/modules/health/health.controller.spec.ts index a3b50c3..7e84f75 100644 --- a/src/modules/health/health.controller.spec.ts +++ b/src/modules/health/health.controller.spec.ts @@ -1,21 +1,21 @@ +import { Test, TestingModule } from '@nestjs/testing'; import { HealthController } from './health.controller'; -import { HttpStatus } from '@nestjs/common'; describe('HealthController', () => { let healthController: HealthController; - beforeEach(() => { - healthController = new HealthController(); + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + controllers: [HealthController], + }).compile(); + + healthController = module.get(HealthController); }); describe('checkHealth', () => { - it('should return status 200 with a healthy message', async () => { + it('should return status 200', async () => { const result = await healthController.checkHealth(); - - expect(result).toEqual({ - status: HttpStatus.OK, - message: 'Server is healthy', - }); + expect(result).toEqual(undefined); }); }); }); diff --git a/src/modules/health/health.controller.ts b/src/modules/health/health.controller.ts index 7f89339..479218b 100644 --- a/src/modules/health/health.controller.ts +++ b/src/modules/health/health.controller.ts @@ -1,5 +1,4 @@ -import { Controller, Get, HttpStatus, UseGuards } from '@nestjs/common'; -import { JwtAuthGuard } from '../../shared/guards/jwt-auth.guard'; +import { Controller, Get } from '@nestjs/common'; /** * Controller for health checks. @@ -17,16 +16,12 @@ export class HealthController { * response indicating whether the server is running correctly. * It requires JWT authentication to access. * - * @returns {Object} - An object containing the HTTP status and a health message. + * @returns {undefined} - Only return status code. * @throws {UnauthorizedException} - Throws if the request is not authenticated. * @async */ - @UseGuards(JwtAuthGuard) @Get() async checkHealth() { - return { - status: HttpStatus.OK, - message: 'Server is healthy', - }; + return; } }