-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
45 additions
and
19 deletions.
There are no files selected for viewing
18 changes: 0 additions & 18 deletions
18
examples/common_nestjs_remix/apps/api/src/health/health.controller.spec.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...ples/common_nestjs_remix/apps/api/src/health/indicator/database/drizzleorm.health.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", {}), | ||
); | ||
} | ||
}); | ||
}); |