-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathheathcheck.test.ts
More file actions
38 lines (28 loc) · 1.07 KB
/
heathcheck.test.ts
File metadata and controls
38 lines (28 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
import { DBHealthcheck } from "../healthcheck";
import { createTables, DBContext, deleteTables, setupDynamoDBContainer } from "./db";
// Database tests can take longer, especially with setup and teardown
jest.setTimeout(30000);
describe('DBHealthcheck', () => {
let db: DBContext;
beforeAll(async () => {
db = await setupDynamoDBContainer();
});
beforeEach(async () => {
await createTables(db);
});
afterEach(async () => {
await deleteTables(db);
});
it('passes when the database is available', async () => {
const dbHealthCheck = new DBHealthcheck(db.docClient, db.config);
await dbHealthCheck.check();
});
it('fails when the database is unavailable', async () => {
const realFunction = db.docClient.send;
db.docClient.send = jest.fn().mockImplementation(() => { throw new Error('Failed to send')});
const dbHealthCheck = new DBHealthcheck(db.docClient, db.config);
await expect(dbHealthCheck.check()).rejects.toThrow();
db.docClient.send = realFunction;
});
});