Skip to content

Commit

Permalink
fix: the route 'api/health' only return a status code
Browse files Browse the repository at this point in the history
  • Loading branch information
Xantass committed Nov 26, 2024
1 parent 68e9b5d commit a930565
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
18 changes: 9 additions & 9 deletions src/modules/health/health.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -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>(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);
});
});
});
11 changes: 3 additions & 8 deletions src/modules/health/health.controller.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
}
}

0 comments on commit a930565

Please sign in to comment.