Skip to content

Commit

Permalink
Jsaem2 46 connection test (#35)
Browse files Browse the repository at this point in the history
* JSAEM2-46 fixed: update the test for DB connection

* JSAEM2-46 fixed: update the test

* JSAEM 2-46 fixed: use async&await for db test

* JSAEM 2-46 fixed: use connection from initializer
  • Loading branch information
MichaelCTH authored and ikarasz committed Jan 9, 2020
1 parent e5381c4 commit 2333413
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
8 changes: 4 additions & 4 deletions mongoDB.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const mongoose = require('mongoose');

const mongooseInit = () => {
mongoose.connect(`mongodb://${process.env.DB_HOST}/${process.env.DB_DATABASE}`, {
const mongooseInit = () => mongoose
.connect(`mongodb://${process.env.DB_HOST}/${process.env.DB_DATABASE}`, {
user: process.env.DB_USER,
pass: process.env.DB_PASS,
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
});
};


module.exports = mongooseInit;
10 changes: 4 additions & 6 deletions mongoDB.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
const mongoose = require('mongoose');
const mongooseInit = require('./mongoDB');
require('dotenv').config();

describe('mongoDB', () => {
it('Mongo DB Connection', () => {
mongooseInit();
setTimeout(() => {
expect(mongoose.connection.readyState).toEqual(1);
}, 1500);
it('Mongo DB Connection', async () => {
const conn = await mongooseInit();
expect(conn.connection.readyState).toEqual(1);
});
});

0 comments on commit 2333413

Please sign in to comment.