Skip to content

Commit

Permalink
feat: ping google.com
Browse files Browse the repository at this point in the history
  • Loading branch information
dloranc authored and k1eu committed Sep 26, 2024
1 parent 28110c0 commit 58d316a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 19 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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", {}),
);
}
});
});

0 comments on commit 58d316a

Please sign in to comment.