Fixing user setup in tests

master
Mark Moffat 2019-11-09 15:38:05 +10:30
parent 6f2efde1ea
commit d5e32ee9a7
2 changed files with 22 additions and 13 deletions

View File

@ -115,15 +115,6 @@ const indexOrders = (app, cb) => {
});
};
const fixProductDates = (products) => {
let index = 0;
products.forEach(() => {
products[index].productAddedDate = new Date();
index++;
});
return products;
};
// start indexing products and orders
const runIndexing = (app) => {
if(process.env.NODE_ENV !== 'test'){
@ -145,6 +136,5 @@ module.exports = {
indexProducts,
indexCustomers,
indexOrders,
fixProductDates,
runIndexing
};

View File

@ -3,7 +3,7 @@ const _ = require('lodash');
const session = require('supertest-session');
const app = require('../app.js');
const { getId, newId } = require('../lib/common');
const { runIndexing, fixProductDates } = require('../lib/indexing');
const { runIndexing } = require('../lib/indexing');
// Get test data to compare in tests
const rawTestData = fs.readFileSync('./bin/testdata.json', 'utf-8');
@ -30,7 +30,7 @@ const setup = (db) => {
])
.then(() => {
return Promise.all([
db.users.insertMany(jsonData.users),
db.users.insertMany(addApiKey(jsonData.users)),
db.customers.insertMany(jsonData.customers),
db.products.insertMany(fixProductDates(jsonData.products))
]);
@ -91,8 +91,27 @@ const runBefore = async () => {
});
};
const fixProductDates = (products) => {
let index = 0;
products.forEach(() => {
products[index].productAddedDate = new Date();
index++;
});
return products;
};
const addApiKey = (users) => {
let index = 0;
users.forEach(() => {
users[index].apiKey = newId();
index++;
});
return users;
};
module.exports = {
runBefore,
setup,
g
g,
fixProductDates
};