mirror of
https://github.com/stolksdorf/homebrewery.git
synced 2025-12-23 13:11:30 +00:00
Adding a new script from populating the DB with a bunch of random brews
This commit is contained in:
51
scripts/genbrews.js
Normal file
51
scripts/genbrews.js
Normal file
@@ -0,0 +1,51 @@
|
||||
//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.`);
|
||||
})
|
||||
.catch(console.error);
|
||||
Reference in New Issue
Block a user