init
This commit is contained in:
18
tests/utils/setupTestDB.js
Normal file
18
tests/utils/setupTestDB.js
Normal file
@@ -0,0 +1,18 @@
|
||||
const mongoose = require('mongoose');
|
||||
const config = require('../../src/config/config');
|
||||
|
||||
const setupTestDB = () => {
|
||||
beforeAll(async () => {
|
||||
await mongoose.connect(config.mongoose.url, config.mongoose.options);
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
await Promise.all(Object.values(mongoose.connection.collections).map(async (collection) => collection.deleteMany()));
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await mongoose.disconnect();
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = setupTestDB;
|
||||
Reference in New Issue
Block a user