2015-07-29 10:46:30 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var User = require("../user/user");
|
|
|
|
var client = require("../ensl/client")();
|
|
|
|
var async = require("async");
|
2015-08-28 14:17:02 +00:00
|
|
|
var getRandomUser = require("../user/helper").getRandomUser;
|
2015-07-29 10:46:30 +00:00
|
|
|
|
2015-08-18 09:56:35 +00:00
|
|
|
var 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();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-08-10 23:56:53 +00:00
|
|
|
async.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
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
createTestUsers: createTestUsers
|
2015-08-18 09:56:35 +00:00
|
|
|
};
|