Skip to content

Commit

Permalink
health controller
Browse files Browse the repository at this point in the history
  • Loading branch information
RohitKandimalla committed Apr 16, 2024
1 parent 3e06b66 commit 457104e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/health/health.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Test, TestingModule } from '@nestjs/testing';
import { HealthController } from './health.controller';
import { HealthCheckService, TerminusModule } from '@nestjs/terminus';

describe('HealthController', () => {
let controller: HealthController;
const mockedCheckServiceCall = jest.fn().mockResolvedValue(() => {
return { status: 'ok', info: {}, error: {}, details: {} };
});

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [HealthController],
providers: [
{
provide: HealthCheckService,
useValue: {
check: mockedCheckServiceCall,
},
},
],
imports: [TerminusModule],
}).compile();

controller = module.get<HealthController>(HealthController);
});

it('should be defined', () => {
expect(controller).toBeDefined();
controller.check();
expect(mockedCheckServiceCall).toHaveBeenCalledTimes(1);
});
});
13 changes: 13 additions & 0 deletions src/health/health.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Controller, Get } from '@nestjs/common';
import { HealthCheck, HealthCheckService } from '@nestjs/terminus';

@Controller('health')
export class HealthController {
constructor(private health: HealthCheckService) {}

@Get()
@HealthCheck()
check() {
return this.health.check([]);
}
}

0 comments on commit 457104e

Please sign in to comment.