Skip to content

Commit

Permalink
Use correct key for process.env in test
Browse files Browse the repository at this point in the history
  • Loading branch information
bzfvrto committed Jun 16, 2024
1 parent 526fd9b commit 0bccdd3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions __tests__/utils/globalSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ module.exports = async function globalSetup() {
const instance = await MongoMemoryServer.create();
const uri = instance.getUri();
global.__MONGOINSTANCE = instance;
process.env.MONGO_URI = uri.slice(0, uri.lastIndexOf("/"));
process.env.DB_CONNECTION_STRING = uri.slice(0, uri.lastIndexOf("/"));

// The following is to make sure the database is clean before an test starts
console.log("global setup instance uri", instance.getUri());
const conn = await mongoose.connect(`${instance.getUri()}`, { dbName: "npa_test_db" });
console.log("CONNECTION :", conn);
await conn.connection.db.dropDatabase();
await mongoose.disconnect();
};
4 changes: 2 additions & 2 deletions __tests__/utils/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ const mongoose = require("mongoose");

beforeAll(async () => {
// put your client connection code here, example with mongoose:
console.log("before all", process.env["MONGO_URI"]);
console.log("before all", process.env["DB_CONNECTION_STRING"]);
await mongoose.disconnect();
await mongoose.connect(process.env["MONGO_URI"]);
await mongoose.connect(process.env["DB_CONNECTION_STRING"]);
});

afterAll(async () => {
Expand Down

0 comments on commit 0bccdd3

Please sign in to comment.