Skip to content

Commit

Permalink
feat: add /health endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Anmol Sharma <anmolsharma0234@gmail.com>
  • Loading branch information
theanmolsharma committed Apr 6, 2024
1 parent 34e9cbe commit 571f0ad
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 61 deletions.
32 changes: 32 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { Config } from '@jest/types';

const config: Config.InitialOptions = {
preset: 'ts-jest',
verbose: true,
moduleFileExtensions: ['js', 'json', 'ts'],
rootDir: '.',
roots: ['<rootDir>/src/'],
testRegex: '.*\\.spec\\.ts$',
transform: {
'^.+\\.(t|j)s$': 'ts-jest',
},
collectCoverageFrom: ['<rootDir>/src/**/*.(t|j)s'],
coveragePathIgnorePatterns: [
'.*.controller.ts',
'.*.module.ts',
'.*.entity.ts',
'.*.dto.ts',
'.*.spec.ts',
'.*.module-definition.ts',
'.*.configuration.ts',
'.*.configuration.model.ts',
'.*./main.ts',
'node_modules',
],
coverageDirectory: './coverage',
testEnvironment: 'node',
moduleNameMapper: {
'@/(.*)': '<rootDir>/src/$1',
},
};
export default config;
20 changes: 1 addition & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json"
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand"
},
"dependencies": {
"@nestjs/common": "^9.0.0",
Expand Down Expand Up @@ -66,23 +65,6 @@
"webpack": "^5.91.0",
"webpack-node-externals": "^3.0.0"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
},
"lint-staged": {
"*.ts": [
"eslint --fix",
Expand Down
7 changes: 3 additions & 4 deletions src/app.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AppController } from '@/app.controller';
import { AppService } from '@/app.service';
import { ServiceStatus } from '@/common/enum';

describe('AppController', () => {
let appController: AppController;
Expand All @@ -14,9 +15,7 @@ describe('AppController', () => {
appController = app.get<AppController>(AppController);
});

describe('root', () => {
it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!');
});
it(`should return "${ServiceStatus.HEALTHY}"`, () => {
expect(appController.getHealth()).toBe(ServiceStatus.HEALTHY);
});
});
6 changes: 3 additions & 3 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { AppService } from '@/app.service';
export class AppController {
constructor(private readonly appService: AppService) {}

@Get()
getHello(): string {
return this.appService.getHello();
@Get('/health')
getHealth(): string {
return this.appService.getHealth();
}
}
5 changes: 3 additions & 2 deletions src/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Injectable } from '@nestjs/common';
import { ServiceStatus } from '@/common/enum';

@Injectable()
export class AppService {
getHello(): string {
return 'Hello World!!';
getHealth(): string {
return ServiceStatus.HEALTHY;
}
}
3 changes: 3 additions & 0 deletions src/common/enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export enum ServiceStatus {
HEALTHY = 'HEALTHY',
}
24 changes: 0 additions & 24 deletions test/app.e2e-spec.ts

This file was deleted.

9 changes: 0 additions & 9 deletions test/jest-e2e.json

This file was deleted.

0 comments on commit 571f0ad

Please sign in to comment.