2023-03-05 17:18:43 +00:00
|
|
|
import { parallel } from "async";
|
|
|
|
import { getRandomUser } from "../user/helper.mjs";
|
2015-07-29 10:46:30 +00:00
|
|
|
|
|
|
|
|
2023-03-05 17:18:43 +00:00
|
|
|
export const createTestUsers = (options, callback) => {
|
2015-07-29 10:46:30 +00:00
|
|
|
var gather = options.gather;
|
|
|
|
|
|
|
|
var instructions = [];
|
|
|
|
for (var i = 0; i < 11; i++) {
|
2015-08-10 23:56:53 +00:00
|
|
|
instructions.push(callback => {
|
2015-08-28 14:17:02 +00:00
|
|
|
getRandomUser((error, user) => {
|
2015-07-29 10:46:30 +00:00
|
|
|
if (error) return callback(error);
|
|
|
|
if (gather.can("addGatherer")) {
|
2015-08-28 14:17:02 +00:00
|
|
|
gather.addGatherer(user);
|
2015-07-29 10:46:30 +00:00
|
|
|
}
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2023-03-05 17:18:43 +00:00
|
|
|
parallel(instructions, (error) => {
|
2015-07-29 10:46:30 +00:00
|
|
|
if (error) {
|
|
|
|
console.log("Error while adding gatherers", error);
|
|
|
|
} else {
|
|
|
|
console.log("Loaded gatherers");
|
2015-08-10 23:56:53 +00:00
|
|
|
gather.gatherers.forEach((gatherer, index, array) => {
|
2015-07-29 10:46:30 +00:00
|
|
|
var candidate = Math.floor(Math.random() * array.length);
|
|
|
|
array[index].leaderVote = array[candidate].id;
|
|
|
|
});
|
|
|
|
console.log("Assigned vote for each gatherer");
|
2015-08-18 09:56:35 +00:00
|
|
|
if (typeof callback === 'function') return callback(gather);
|
2015-07-29 10:46:30 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2023-03-05 17:18:43 +00:00
|
|
|
export default {
|
|
|
|
createTestUsers
|
2015-08-18 09:56:35 +00:00
|
|
|
};
|