diff --git a/apps/apps-backend/jest-e2e.json b/apps/apps-backend/jest-e2e.json new file mode 100644 index 00000000000..8a02f0e8a41 --- /dev/null +++ b/apps/apps-backend/jest-e2e.json @@ -0,0 +1,13 @@ +{ + "moduleFileExtensions": ["js", "json", "ts"], + "rootDir": "./", + "testRegex": ".e2e-spec.ts$", + "transform": { + "^.+\\.(t|j)s$": "ts-jest" + }, + "testEnvironment": "node", + "moduleNameMapper": { + "^src/(.*)$": "/dist/$1", + "^@iota/core/(.*)$": "/dist/core/src/$1" + } +} diff --git a/apps/apps-backend/package.json b/apps/apps-backend/package.json index eb94045a4f5..149cc6fd9fc 100644 --- a/apps/apps-backend/package.json +++ b/apps/apps-backend/package.json @@ -6,8 +6,9 @@ "format": "prettier --write \"src/**/*.ts\"", "dev": "nest start --watch", "debug": "nest start --debug --watch", - "preview": "pnpm run build && node dist/main", - "lint": "eslint --max-warnings=0 \"{src,apps,libs,test}/**/*.ts\"" + "preview": "pnpm run build && node dist/apps-backend/src/main", + "lint": "eslint --max-warnings=0 \"{src,apps,libs,test}/**/*.ts\"", + "test:e2e": "jest --config ./jest-e2e.json" }, "dependencies": { "@iota/core": "workspace:*", diff --git a/apps/apps-backend/src/app.module.ts b/apps/apps-backend/src/app.module.ts index 0dc2844e50e..b7fd88272e7 100644 --- a/apps/apps-backend/src/app.module.ts +++ b/apps/apps-backend/src/app.module.ts @@ -11,6 +11,7 @@ import { FeaturesModule } from './features/features.module'; import { MonitorNetworkModule } from './monitor-network/monitor-network.module'; import { PricesModule } from './prices/prices.module'; import { RestrictedModule } from './restricted/restricted.module'; +import { HealthModule } from './health/health.module'; @Module({ imports: [ @@ -30,6 +31,7 @@ import { RestrictedModule } from './restricted/restricted.module'; ttl: 3600, max: 100, }), + HealthModule, ], }) export class AppModule {} diff --git a/apps/apps-backend/src/health/health.controller.ts b/apps/apps-backend/src/health/health.controller.ts new file mode 100644 index 00000000000..c86fdd5fc40 --- /dev/null +++ b/apps/apps-backend/src/health/health.controller.ts @@ -0,0 +1,12 @@ +// Copyright (c) 2024 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +import { Controller, Get } from '@nestjs/common'; + +@Controller('health') +export class HealthController { + @Get() + check() { + return { status: 'ok' }; + } +} diff --git a/apps/apps-backend/src/health/health.module.ts b/apps/apps-backend/src/health/health.module.ts new file mode 100644 index 00000000000..e6394484ac5 --- /dev/null +++ b/apps/apps-backend/src/health/health.module.ts @@ -0,0 +1,10 @@ +// Copyright (c) 2024 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +import { Module } from '@nestjs/common'; +import { HealthController } from './health.controller'; + +@Module({ + controllers: [HealthController], +}) +export class HealthModule {} diff --git a/apps/apps-backend/test/health.e2e-spec.ts b/apps/apps-backend/test/health.e2e-spec.ts new file mode 100644 index 00000000000..cde735e7a57 --- /dev/null +++ b/apps/apps-backend/test/health.e2e-spec.ts @@ -0,0 +1,28 @@ +// Copyright (c) 2024 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +import { Test, TestingModule } from '@nestjs/testing'; +import { INestApplication } from '@nestjs/common'; +import * as request from 'supertest'; +import { AppModule } from '../src/app.module'; + +describe('Health Check (e2e)', () => { + let app: INestApplication; + + beforeAll(async () => { + const moduleFixture: TestingModule = await Test.createTestingModule({ + imports: [AppModule], + }).compile(); + + app = moduleFixture.createNestApplication(); + await app.init(); + }); + + afterAll(async () => { + await app.close(); + }); + + it('/health (GET)', () => { + return request(app.getHttpServer()).get('/health').expect(200).expect({ status: 'ok' }); + }); +});