diff --git a/src/health/health.controller.spec.ts b/src/health/health.controller.spec.ts new file mode 100644 index 0000000..2e1e171 --- /dev/null +++ b/src/health/health.controller.spec.ts @@ -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); + }); + + it('should be defined', () => { + expect(controller).toBeDefined(); + controller.check(); + expect(mockedCheckServiceCall).toHaveBeenCalledTimes(1); + }); +}); diff --git a/src/health/health.controller.ts b/src/health/health.controller.ts new file mode 100644 index 0000000..6025b35 --- /dev/null +++ b/src/health/health.controller.ts @@ -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([]); + } +}