diff --git a/app.js b/app.js index e25d7bc..126b933 100644 --- a/app.js +++ b/app.js @@ -315,7 +315,13 @@ MongoClient.connect(config.databaseConnectionString, {}, (err, client) => { // select DB const dbUriObj = mongodbUri.parse(config.databaseConnectionString); - const db = client.db(dbUriObj.database); + let db; + // if in testing, set the testing DB + if(process.env.NODE_ENV === 'test'){ + db = client.db('testingdb'); + }else{ + db = client.db(dbUriObj.database); + } // setup the collections db.users = db.collection('users'); @@ -326,17 +332,20 @@ MongoClient.connect(config.databaseConnectionString, {}, (err, client) => { db.customers = db.collection('customers'); // add db to app for routes + app.dbClient = client; app.db = db; + app.config = config; + app.port = app.get('port'); // run indexing common.runIndexing(app) - .then(common.testData(db, app)) .then(app.listen(app.get('port'))) .then(() => { // lift the app + app.emit('appStarted'); console.log(colors.green('expressCart running on host: http://localhost:' + app.get('port'))); }) - .catch(() => { + .catch((err) => { console.error(colors.red('Error setting up indexes:' + err)); process.exit(2); }); diff --git a/bin/testdata.json b/bin/testdata.json index e1fa7d0..e38574d 100644 --- a/bin/testdata.json +++ b/bin/testdata.json @@ -14,7 +14,7 @@ "productImage": "/uploads/duckworth-jacket/woolfill-jacket_6c39ae23-c0c8-4821-85f4-4b5d64333c62_grande.jpg" }, { - "productPermalink": "5-panel-cap", + "productPermalink": "5-panel-camp-cap", "productTitle": "5 Panel Camp Cap", "productPrice": "48", "productDescription": "

A classic 5 panel hat with our United By Blue logo on the front and an adjustable strap to keep fit and secure. Made with recycled polyester and organic cotton mix.<\/p>