diff --git a/examples/common_nestjs_remix/apps/api/src/health/health.controller.spec.ts b/examples/common_nestjs_remix/apps/api/src/health/health.controller.spec.ts deleted file mode 100644 index 4dd30bc..0000000 --- a/examples/common_nestjs_remix/apps/api/src/health/health.controller.spec.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Test, TestingModule } from "@nestjs/testing"; -import { HealthController } from "./health.controller"; - -describe("HealthController", () => { - let controller: HealthController; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - controllers: [HealthController], - }).compile(); - - controller = module.get(HealthController); - }); - - it("should be defined", () => { - expect(controller).toBeDefined(); - }); -}); diff --git a/examples/common_nestjs_remix/apps/api/src/health/health.controller.ts b/examples/common_nestjs_remix/apps/api/src/health/health.controller.ts index 63b1ee5..f282092 100644 --- a/examples/common_nestjs_remix/apps/api/src/health/health.controller.ts +++ b/examples/common_nestjs_remix/apps/api/src/health/health.controller.ts @@ -20,7 +20,7 @@ export class HealthController { @HealthCheck() check() { return this.health.check([ - () => this.http.pingCheck("nestjs-docs", "https://docs.nestjs.com"), + () => this.http.pingCheck("google", "https://google.com"), () => this.db.pingCheck("guidebook"), ]); } diff --git a/examples/common_nestjs_remix/apps/api/src/health/indicator/database/drizzleorm.health.spec.ts b/examples/common_nestjs_remix/apps/api/src/health/indicator/database/drizzleorm.health.spec.ts new file mode 100644 index 0000000..a0e9ac6 --- /dev/null +++ b/examples/common_nestjs_remix/apps/api/src/health/indicator/database/drizzleorm.health.spec.ts @@ -0,0 +1,44 @@ +import { DatabasePg } from "src/common"; +import { TestContext, createUnitTest } from "test/create-unit-test"; +import { DrizzleOrmHealthIndicator } from "./drizzleorm.health"; +import { HealthCheckError } from "@nestjs/terminus"; + +describe("DrizzleOrmHealthIndicator", () => { + let testContext: TestContext; + let drizzleOrmHealthIndicator: DrizzleOrmHealthIndicator; + let db: DatabasePg; + + beforeAll(async () => { + testContext = await createUnitTest(); + db = testContext.db; + drizzleOrmHealthIndicator = new DrizzleOrmHealthIndicator(db); + }, 30000); + + afterAll(async () => { + await testContext.teardown(); + }); + + it("should ping the database", async () => { + const result = await drizzleOrmHealthIndicator.pingCheck("test-database"); + + expect(result).toStrictEqual({ + "test-database": { + status: "up", + }, + }); + }); + + it("should return status when failure", async () => { + db.execute = jest.fn().mockImplementation(() => { + throw new Error(); + }); + + try { + await drizzleOrmHealthIndicator.pingCheck("test-database"); + } catch (error) { + expect(error).toStrictEqual( + new HealthCheckError("Database check failed", {}), + ); + } + }); +});