diff --git a/server.js b/server.js index 015334e..4121a26 100644 --- a/server.js +++ b/server.js @@ -14,13 +14,7 @@ const config = require('nconf') .file('defaults', { file: 'config/default.json' }); //DB -require('mongoose') - .connect(process.env.MONGODB_URI || process.env.MONGOLAB_URI || 'mongodb://localhost/naturalcrit') - .connection.on('error', () => { - console.error('Error : Could not connect to a Mongo Database.'); - console.error(' If you are running locally, make sure mongodb.exe is running.'); - }); - +require('./server/db.js').connect(); //Middleware const mw = require('./server/middleware.js'); diff --git a/server/db.js b/server/db.js new file mode 100644 index 0000000..a703e33 --- /dev/null +++ b/server/db.js @@ -0,0 +1,18 @@ + +module.exports = { + connect : ()=>{ + return new Promise((resolve, reject)=>{ + require('mongoose') + .connect(process.env.MONGODB_URI || process.env.MONGOLAB_URI || 'mongodb://localhost/homebrewery', + (err) => { + if(err){ + console.log('Error : Could not connect to a Mongo Database.'); + console.log(' If you are running locally, make sure mongodb.exe is running.'); + return reject(); + } + return resolve(); + } + ); + }); + } +} \ No newline at end of file diff --git a/test/brew.datatest.js b/test/brew.datatest.js index 00d4e0c..8fbdd00 100644 --- a/test/brew.datatest.js +++ b/test/brew.datatest.js @@ -12,11 +12,16 @@ describe('BrewDB', () => { return BrewDB.create({ text : "Brew Text" }).then((brew) => { + console.log('running?'); should.exist(brew); brew.should.have.property('editId').that.is.a('string'); brew.should.have.property('shareId').that.is.a('string'); brew.should.have.property('text').that.is.a('string'); - }); + done(); + }) + .catch(()=>{ + console.log('yo'); + }) }); }); \ No newline at end of file