-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.setup.js
More file actions
40 lines (31 loc) · 1.07 KB
/
jest.setup.js
File metadata and controls
40 lines (31 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
39
40
jest.mock("aws-sdk");
jest.mock("./src/auth");
jest.mock("./src/db-url");
const { MongoClient } = require("mongodb");
const { GenericContainer } = require("testcontainers");
const { getDbUrl } = require("./src/db-url");
let mongoContainer;
let mongoClient;
let mongoCollection;
beforeAll(async () => {
jest.setTimeout(120000);
const database = "test";
mongoContainer = await new GenericContainer("mongo", "4.2.10")
.withEnv("MONGO_INITDB_DATABASE", database)
.withExposedPorts(27017)
.start();
const mongoHost = mongoContainer.getContainerIpAddress();
const mongoPort = mongoContainer.getMappedPort(27017);
const mongoUrl = `mongodb://${mongoHost}:${mongoPort}`;
getDbUrl.mockReturnValue({ url: mongoUrl, database });
mongoClient = new MongoClient(mongoUrl, { useUnifiedTopology: true });
await mongoClient.connect();
const mongoDatabase = mongoClient.db(database);
mongoCollection = mongoDatabase.collection("recipes");
});
afterAll(async () => {
await mongoContainer.stop();
});
beforeEach(async () => {
await mongoCollection.deleteMany({});
});