Skip to content

Commit 107462c

Browse files
hard coded db uri
1 parent 1518576 commit 107462c

5 files changed

Lines changed: 25 additions & 5 deletions

File tree

globalConfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"mongoUri":"mongodb://127.0.0.1:50944/jest?","mongoDBName":"jest"}

jest-mongodb-config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
mongodbMemoryServerOptions: {
3+
instance: {
4+
dbName: "jest",
5+
},
6+
binary: {
7+
version: "4.0.3",
8+
skipMD5: true,
9+
},
10+
autoStart: false,
11+
},
12+
};

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ module.exports = {
33
testRegex: [".spec.js$", ".test.js$"],
44
coverageDirectory: "./coverage",
55
testEnvironment: "node",
6+
preset: "@shelf/jest-mongodb",
67
};

src/db/__test__/config/setup.js

Whitespace-only changes.

src/db/__test__/db.test.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ require("dotenv").config();
66
describe("INSERT", () => {
77
test("Should confirm mongodb works by adding a record", async () => {
88
console.log("Attempting to connect to database...");
9-
await connect(process.env.AUTH_API_MONGODB_URI);
9+
await connect(
10+
"mongodb+srv://microapi:secret123@cluster0.japiw.mongodb.net/microapi?retryWrites=true&w=majority"
11+
);
1012
const id = mongoose.Types.ObjectId();
1113
const mockData = new IndexModel({
1214
_id: id,
@@ -28,14 +30,18 @@ describe("INSERT", () => {
2830
test("Should return error for existing connections", async () => {
2931
console.log("Attempting to connect to database...");
3032
mongoose.connection.readyState = 1;
31-
expect(await connect(process.env.AUTH_API_MONGODB_URI)).toEqual(
32-
Error("Connection already Established")
33-
);
33+
expect(
34+
await connect(
35+
"mongodb+srv://microapi:secret123@cluster0.japiw.mongodb.net/microapi?retryWrites=true&w=majority"
36+
)
37+
).toEqual(Error("Connection already Established"));
3438
});
3539

3640
test("Should return error for non-existing connections on disconnec", async () => {
3741
console.log("Attempting to connect to database...");
38-
await connect(process.env.AUTH_API_MONGODB_URI);
42+
await connect(
43+
"mongodb+srv://microapi:secret123@cluster0.japiw.mongodb.net/microapi?retryWrites=true&w=majority"
44+
);
3945
mongoose.connection.readyState = 0;
4046
expect(await disconnect()).toEqual(Error("No open connection(s)"));
4147
});

0 commit comments

Comments
 (0)