2019-06-15 14:46:08 +10:00
|
|
|
const { getConfig } = require('./common');
|
|
|
|
const { initDb } = require('./db');
|
|
|
|
const { fixProductDates } = require('./indexing');
|
2019-06-08 17:50:01 +10:00
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
|
|
|
|
const testData = fs.readFileSync(path.join(__dirname, '..', 'bin', 'testdata.json'), 'utf-8');
|
|
|
|
const jsonData = JSON.parse(testData);
|
|
|
|
|
|
|
|
// get config
|
2019-07-12 18:06:34 +10:00
|
|
|
const config = getConfig();
|
2019-06-08 17:50:01 +10:00
|
|
|
|
|
|
|
initDb(config.databaseConnectionString, (err, db) => {
|
|
|
|
Promise.all([
|
2019-10-29 18:26:30 +10:00
|
|
|
db.users.deleteMany({}, {}),
|
|
|
|
db.customers.deleteMany({}, {}),
|
|
|
|
db.products.deleteMany({}, {}),
|
|
|
|
db.menu.deleteMany({}, {})
|
2019-06-08 17:50:01 +10:00
|
|
|
])
|
|
|
|
.then(() => {
|
|
|
|
Promise.all([
|
|
|
|
db.users.insertMany(jsonData.users),
|
|
|
|
db.customers.insertMany(jsonData.customers),
|
2019-06-15 14:46:08 +10:00
|
|
|
db.products.insertMany(fixProductDates(jsonData.products)),
|
2019-06-08 17:50:01 +10:00
|
|
|
db.menu.insertOne(jsonData.menu)
|
|
|
|
])
|
|
|
|
.then(() => {
|
|
|
|
console.log('Test data complete');
|
|
|
|
process.exit();
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
console.log('Error inserting test data', err);
|
2019-06-11 15:32:44 +10:00
|
|
|
process.exit(2);
|
2019-06-08 17:50:01 +10:00
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
console.log('Error removing existing test data', err);
|
2019-06-11 15:32:44 +10:00
|
|
|
process.exit(2);
|
2019-06-08 17:50:01 +10:00
|
|
|
});
|
|
|
|
});
|