Fixed test scripts

master
Mark Moffat 2019-06-09 22:02:22 +09:30
parent 3a8c426279
commit 01cd784a0e
2 changed files with 10 additions and 12 deletions

View File

@ -633,6 +633,15 @@ exports.indexOrders = (app, cb) => {
});
};
exports.fixProductDates = (products) => {
let index = 0;
products.forEach((product) => {
products[index].productAddedDate = new Date();
index++;
});
return products;
};
// start indexing products and orders
exports.runIndexing = (app) => {
console.info(colors.yellow('Setting up indexes..'));

View File

@ -3,8 +3,6 @@ const { initDb } = require('./db');
const fs = require('fs');
const path = require('path');
console.log('__dirname', path.join(__dirname, '..', 'bin', 'testdata.json'));
const testData = fs.readFileSync(path.join(__dirname, '..', 'bin', 'testdata.json'), 'utf-8');
const jsonData = JSON.parse(testData);
@ -22,7 +20,7 @@ initDb(config.databaseConnectionString, (err, db) => {
Promise.all([
db.users.insertMany(jsonData.users),
db.customers.insertMany(jsonData.customers),
db.products.insertMany(fixProductDates(jsonData.products)),
db.products.insertMany(common.fixProductDates(jsonData.products)),
db.menu.insertOne(jsonData.menu)
])
.then(() => {
@ -40,12 +38,3 @@ initDb(config.databaseConnectionString, (err, db) => {
});
});
// Adds current date to product added date when smashing into DB
function fixProductDates(products){
let index = 0;
products.forEach((product) => {
products[index].productAddedDate = new Date();
index++;
});
return products;
}