0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-13 10:52:46 +00:00

created a brew generator and chai plugin for easier testing

This commit is contained in:
Scott Tolksdorf
2017-01-27 18:38:09 -05:00
parent 8018442f25
commit a826aaffd9
6 changed files with 124 additions and 111 deletions

View File

@@ -1,52 +0,0 @@
//Populates the DB with a bunch of brews for UI testing
const _ = require('lodash');
const DB = require('../server/db.js');
const BrewData = require('../server/brew.data.js');
//TODO: pull in snippets and randomly add them
const genBrew = () => {
return {
title : 'BrewA',
description : '',
text : '',
authors : _.sampleSize(['userA','userB','userC','userD'], _.random(0, 3)),
systems : _.sampleSize(['5e', '4e', '3.5e', 'Pathfinder'], _.random(0,2)),
views : _.random(0,1000),
published : !!_.random(0,1)
}
}
const randomBrews = _.times(20, genBrew);
const specificBrews = [
{
text : 'Cool test',
authors : ['test']
}
];
return Promise.resolve()
.then(DB.connect)
.then(BrewData.removeAll)
.then(() => {
console.log('Adding random brews...');
return Promise.all(_.map(randomBrews, (brew) => {
return BrewData.create(brew);
}));
})
.then(() => {
console.log('Adding specific brews...');
return Promise.all(_.map(specificBrews, (brew) => {
return BrewData.create(brew);
}));
})
.then(() => {
console.log(`\n Added ${randomBrews.length + specificBrews.length} brews.`);
return DB.close();
})
.catch(console.error);

22
scripts/populate.js Normal file
View File

@@ -0,0 +1,22 @@
//Populates the DB with a bunch of brews for UI testing
const _ = require('lodash');
const DB = require('../server/db.js');
const BrewData = require('../server/brew.data.js');
const BrewGen = require('../test/brew.gen.js');
return Promise.resolve()
.then(DB.connect)
.then(BrewData.removeAll)
.then(() => {
console.log('Adding random brews...');
return return BrewGen.populateDB(BrewGen.random(5));
})
.then(() => {
console.log('Adding specific brews...');
return return BrewGen.populateDB(BrewGen.static());
})
.then(() => {
return DB.close();
})
.catch(console.error);