Fixing user setup in tests
parent
6f2efde1ea
commit
d5e32ee9a7
|
@ -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
|
// start indexing products and orders
|
||||||
const runIndexing = (app) => {
|
const runIndexing = (app) => {
|
||||||
if(process.env.NODE_ENV !== 'test'){
|
if(process.env.NODE_ENV !== 'test'){
|
||||||
|
@ -145,6 +136,5 @@ module.exports = {
|
||||||
indexProducts,
|
indexProducts,
|
||||||
indexCustomers,
|
indexCustomers,
|
||||||
indexOrders,
|
indexOrders,
|
||||||
fixProductDates,
|
|
||||||
runIndexing
|
runIndexing
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,7 @@ const _ = require('lodash');
|
||||||
const session = require('supertest-session');
|
const session = require('supertest-session');
|
||||||
const app = require('../app.js');
|
const app = require('../app.js');
|
||||||
const { getId, newId } = require('../lib/common');
|
const { getId, newId } = require('../lib/common');
|
||||||
const { runIndexing, fixProductDates } = require('../lib/indexing');
|
const { runIndexing } = require('../lib/indexing');
|
||||||
|
|
||||||
// Get test data to compare in tests
|
// Get test data to compare in tests
|
||||||
const rawTestData = fs.readFileSync('./bin/testdata.json', 'utf-8');
|
const rawTestData = fs.readFileSync('./bin/testdata.json', 'utf-8');
|
||||||
|
@ -30,7 +30,7 @@ const setup = (db) => {
|
||||||
])
|
])
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return Promise.all([
|
return Promise.all([
|
||||||
db.users.insertMany(jsonData.users),
|
db.users.insertMany(addApiKey(jsonData.users)),
|
||||||
db.customers.insertMany(jsonData.customers),
|
db.customers.insertMany(jsonData.customers),
|
||||||
db.products.insertMany(fixProductDates(jsonData.products))
|
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 = {
|
module.exports = {
|
||||||
runBefore,
|
runBefore,
|
||||||
setup,
|
setup,
|
||||||
g
|
g,
|
||||||
|
fixProductDates
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue