From d5e32ee9a721fd1e26164b1134ff3342c31138c0 Mon Sep 17 00:00:00 2001 From: Mark Moffat Date: Sat, 9 Nov 2019 15:38:05 +1030 Subject: [PATCH] Fixing user setup in tests --- lib/indexing.js | 10 ---------- test/helper.js | 25 ++++++++++++++++++++++--- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/lib/indexing.js b/lib/indexing.js index 36cf092..6fbaf75 100644 --- a/lib/indexing.js +++ b/lib/indexing.js @@ -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 }; diff --git a/test/helper.js b/test/helper.js index 47e2a29..5460707 100644 --- a/test/helper.js +++ b/test/helper.js @@ -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 };